Skip to content

Instantly share code, notes, and snippets.

@yireo
Created June 28, 2013 10:13
Show Gist options
  • Save yireo/5883745 to your computer and use it in GitHub Desktop.
Save yireo/5883745 to your computer and use it in GitHub Desktop.
PHP-script to remap old SimpleLists category-IDs (Joomla! 1.5) to new SimpleLists category-IDs (Joomla! 2.5 or higher). Make sure to run the script "yr_simplelists_spupgrade_categories.php" first and make sure that all SimpleLists categories are working as they should. For instance, open up a SimpleLists category and save it, to see if that work…
<?php
// Define variables
define('DOCUMENT_ROOT', dirname(__FILE__).'/');
define('_JEXEC', 1);
define('JPATH_BASE', DOCUMENT_ROOT);
define('DS', DIRECTORY_SEPARATOR );
if(!isset($_SERVER['REMOTE_ADDR'])) $_SERVER['REMOTE_ADDR'] = null;
if(!isset($_SERVER['HTTP_HOST'])) $_SERVER['HTTP_HOST'] = null;
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
jimport('joomla.environment.request');
jimport('joomla.database.database');
// Start the application
$app = JFactory::getApplication('administrator');
$app->initialise();
$db = JFactory::getDbo();
// Select the SimpleLists categories
$query = "SELECT * FROM #__categories WHERE `extension`='com_simplelists'";
$db->setQuery($query);
$categories = $db->loadObjectList();
// Loop through the categories and create a mapper
$categoryMap = array();
foreach($categories as $category) {
$categoryMap[$category->note] = $category->id;
}
// Select the SimpleLists categories-items mapping
$query = "SELECT * FROM #__simplelists_categories";
$db->setQuery($query);
$categoryItems = $db->loadObjectList();
foreach($categoryItems as $categoryItem) {
$category_id = $categoryItem->category_id;
if(isset($categoryMap[$category_id])) {
$new_category_id = $categoryMap[$category_id];
$query = "UPDATE #__simplelists_categories SET `category_id`=".$new_category_id
." WHERE `id`=".$categoryItem->id." AND `category_id`=".$category_id;
$db->setQuery($query);
$db->query();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment