Last active
December 3, 2016 15:42
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>"; | |
} | |
} | |
} | |
?> | |
Updated file with full db check here: https://github.com/robwent/joomla-json-db-check
@robwent thanks 👍 This saved my day!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.