Skip to content

Instantly share code, notes, and snippets.

@yireo
Created June 28, 2013 10:04
Show Gist options
  • Save yireo/5883712 to your computer and use it in GitHub Desktop.
Save yireo/5883712 to your computer and use it in GitHub Desktop.
PHP-script to migrate SimpleLists categories from Joomla! 1.5 to Joomla! 2.5 or 3.0 by using the SPUpgrade component. Note that SPUpgrade component needs to be installed when running this script. The original category-ID is not re-used in Joomla!, but saved in the category-field "note". This is used in another script "yr_simplelists_spupgrade_re…
<?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();
// Check for SPUpgrade
define('JPATH_COMPONENT', JPATH_ADMINISTRATOR.'/components/com_spupgrade');
if(!is_file(JPATH_COMPONENT.'/models/com.php')) {
die('SPUpgrade not found');
}
// Include SPUpgrade-stuff
include_once JPATH_COMPONENT.'/libraries/general.php';
include_once JPATH_COMPONENT.'/libraries/simplexml.php';
include_once JPATH_COMPONENT.'/models/com.php';
include_once JPATH_COMPONENT.'/models/extension.php';
JLoader::register('SPUpgradeHelper', JPATH_COMPONENT.'/helpers/spupgrade.php');
jimport('spcyend.utilities.factory');
jimport('spcyend.database.source');
// Load the source database (Joomla! 1.5)
$params = JComponentHelper::getParams('com_spupgrade');
$factory = new CYENDFactory();
$source = new CYENDSource('com_spupgrade');
$source_db = $source->source_db;
// Select the old SimpleLists categories
$query = "SELECT * FROM #__categories WHERE `section`='com_simplelists'";
$source_db->setQuery($query);
$categories = $source_db->loadObjectList();
// Check for a current ROOT-category
$query = "SELECT * FROM #__categories WHERE `level`=0 AND `extension`='SYSTEM' AND `parent_id`=0";
$db->setQuery($query);
if($db->loadObject() == false) {
die('No root-category found');
}
// Loop through the categories and create valid new categories from them
foreach($categories as $category) {
$query = "SELECT `#__categories` WHERE `extension`='com_simplelists' AND `note`=".$category->id;
jimport('joomla.registry.registry');
$params = @new JRegistry();
$params->loadString($category->params);
$params->set('intro_image', $category->image);
$params->set('intro_position', $category->image_position);
require_once JPATH_ADMINISTRATOR.'/components/com_categories/tables/category.php';
$table = JTable::getInstance('category');
$table->load($category_id);
$table->parent_id = $category->parent_id;
$table->title = $category->title;
$table->path = $category->alias;
$table->note = $category->id;
$table->extension = 'com_simplelists';
$table->published = $category->published;
$table->level = 1;
$table->tags = null;
$table->params = $params->toString();
if (!$table->check()) {
echo "table-check failed: ".$table->getError()."\n";
break;
}
if (!$table->store()) {
echo "table-store failed: ".$table->getError()."\n";
break;
}
$query = "UPDATE `#__categories` SET `level`=1 WHERE `id`=".$table->id;
$db->setQuery($query);
$db->query();
}
// What is not migrated: Ordering, access
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment