Skip to content

Instantly share code, notes, and snippets.

@robwent
Last active December 3, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robwent/2b945d860cdecf8f877fcf5955b00c94 to your computer and use it in GitHub Desktop.
Save robwent/2b945d860cdecf8f877fcf5955b00c94 to your computer and use it in GitHub Desktop.
Updates params and rules with invalid default json entries. This will not fix errors from extensions which add invalid parameters.
<?php
//Initiate Joomla so we can use it's functions
/**
* Constant that is checked in included files to prevent direct access.
* define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower
*/
define('_JEXEC', 1);
define( 'DS', DIRECTORY_SEPARATOR );
if (file_exists(__DIR__ . '/defines.php'))
{
include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES'))
{
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
}
require_once JPATH_BASE . '/includes/framework.php';
// Instantiate the application.
$app = JFactory::getApplication('site');
$db = JFactory::getDbo();
$config = JFactory::getConfig();
$query = $db->getQuery(true);
$query->select('TABLE_NAME,COLUMN_NAME');
$query->from('INFORMATION_SCHEMA.COLUMNS');
$query->where('COLUMN_NAME = \'params\' OR COLUMN_NAME = \'rules\'');
$query->andWhere('TABLE_SCHEMA = \'' . $config->get('db') . '\'');
$db->setQuery($query);
$results = $db->loadObjectList();
if ($results) {
foreach ($results as $result) {
echo "Checking table: {$result->TABLE_NAME}, column {$result->COLUMN_NAME}<br>";
$query = $db->getQuery(true);
$query->update($result->TABLE_NAME);
$query->set($result->COLUMN_NAME . ' = "{}"');
$query->where($result->COLUMN_NAME . ' = "" OR ' . $result->COLUMN_NAME . ' = \'{\"\"}\' OR ' . $result->COLUMN_NAME . ' = \'{\\\\\"\\\\\"}\' ');
$db->setQuery($query);
// echo ($query->__toString());
$results = $db->execute();
$changes = $db->getAffectedRows();
if($changes != 0) {
echo $changes . " rows modified.<br>";
}
}
}
?>
@robwent
Copy link
Author

robwent commented Oct 26, 2016

Take a backup of your database.
Upload the file to the root of your site and view it in a browser at http://yoursite.com/joomla-json-db-check.php
Check the site to see if the errors have gone.

@robwent
Copy link
Author

robwent commented Oct 26, 2016

Updated file with full db check here: https://github.com/robwent/joomla-json-db-check

@manojLondhe
Copy link

@robwent thanks 👍 This saved my day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment