/**
  *
  * @param   stdClass   $options  Parameters to be passed to the database driver.
  *
  * @return  redMigrator  A redMigrator object.
  *
  * @since  3.0.0
  */
 static function getInstance(redMigratorStep $step = null)
 {
     // Loading the JFile class
     jimport('joomla.filesystem.file');
     // Getting the params and Joomla version web and cli
     $params = redMigratorHelper::getParams();
     // Derive the class name from the driver.
     $class_name = 'redMigratorDriver' . ucfirst(strtolower($params->method));
     $class_file = JPATH_COMPONENT_ADMINISTRATOR . '/includes/driver/' . $params->method . '.php';
     // Require the driver file
     if (JFile::exists($class_file)) {
         JLoader::register($class_name, $class_file);
     }
     // If the class still doesn't exist we have nothing left to do but throw an exception.  We did our best.
     if (!class_exists($class_name)) {
         throw new RuntimeException(sprintf('Unable to load redMigrator Driver: %s', $params->method));
     }
     // Create our new redMigratorDriver connector based on the options given.
     try {
         $instance = new $class_name($step);
     } catch (RuntimeException $e) {
         throw new RuntimeException(sprintf('Unable to load redMigrator object: %s', $e->getMessage()));
     }
     return $instance;
 }
Example #2
0
 /**
  * Display the view.
  *
  * @param	string	$tpl	The subtemplate to display.
  *
  * @return	void
  */
 function display($tpl = null)
 {
     // Get params
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     $params = redMigratorHelper::getParams();
     //
     // Joomla bug: JInstaller not save the defaults params reading config.xml
     //
     $db = JFactory::getDBO();
     if (!$params->method) {
         $default_params = '{"method":"rest","rest_hostname":"http:\\/\\/www.example.org\\/","rest_username":"","rest_password":"","rest_key":"","path":"","driver":"mysql","hostname":"localhost","username":"","password":"","database":"","prefix":"jos_","skip_checks":"0","skip_files":"1","skip_templates":"1","skip_extensions":"1","skip_core_users":"0","skip_core_categories":"0","skip_core_sections":"0","skip_core_contents":"0","skip_core_contents_frontpage":"0","skip_core_menus":"0","skip_core_menus_types":"0","skip_core_modules":"0","skip_core_modules_menu":"0","skip_core_banners":"0","skip_core_banners_clients":"0","skip_core_banners_tracks":"0","skip_core_contacts":"0","skip_core_newsfeeds":"0","skip_core_weblinks":"0","positions":"0","debug":"0"}';
         $query = "UPDATE #__extensions SET `params` = '{$default_params}' WHERE `element` = 'com_redmigrator'";
         $db->setQuery($query);
         $db->query();
         // Get params.. again
         $params = redMigratorHelper::getParams();
     }
     // Load mooTools
     JHtml::_('behavior.framework', true);
     $xmlfile = JPATH_COMPONENT_ADMINISTRATOR . '/redmigrator.xml';
     $xml = JFactory::getXML($xmlfile);
     $this->params = $params;
     $this->version = $xml->version[0];
     parent::display($tpl);
 }
Example #3
0
 /**
  * Initial checks in redMigrator
  *
  * @return	none
  * @since	1.2.0
  */
 public function step($name = false, $json = true, $extensions = false)
 {
     // Check if extensions exists if not get it from URI request
     $extensions = (bool) ($extensions != false) ? $extensions : JRequest::getCmd('extensions', '');
     // Getting the redMigratorStep instance
     $step = redMigratorStep::getInstance(null, $extensions);
     // Check if name exists
     $name = !empty($name) ? $name : $step->name;
     // Get the next step
     $step->getStep($name);
     if (!redMigratorHelper::isCli()) {
         echo $step->getParameters();
     } else {
         return $step->getParameters();
     }
 }
Example #4
0
 /**
  * Migrate
  *
  * @return	none
  * @since	3.0.3
  */
 function migrate($table = false, $json = true, $extensions = false)
 {
     $table = (bool) ($table != false) ? $table : JRequest::getCmd('table', '');
     $extensions = (bool) ($extensions != false) ? $extensions : JRequest::getCmd('extensions', '');
     // Init the redMigrator instance
     $step = redMigratorStep::getInstance($table, $extensions);
     $redmigrator = redMigrator::getInstance($step);
     // Get the database structure
     if ($step->first == true && $extensions == 'tables') {
         $structure = $redmigrator->getTableStructure();
     }
     // Run the upgrade
     if ($step->total > 0) {
         try {
             $redmigrator->upgrade();
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
     }
     // Javascript flags
     if ($step->cid == $step->stop + 1 && $step->total != 0) {
         $step->next = true;
     }
     if ($step->name == $step->laststep) {
         $step->end = true;
     }
     $empty = false;
     if ($step->cid == 0 && $step->total == 0 && $step->start == 0 && $step->stop == 0) {
         $empty = true;
     }
     if ($step->stop == 0) {
         $step->stop = -1;
     }
     // Update #__redMigrator_steps table if id = last_id
     if ($step->total <= $step->cid || $step->stop == -1 && $empty == false) {
         $step->next = true;
         $step->status = 2;
         $step->_updateStep();
     }
     if (!redMigratorHelper::isCli()) {
         echo $step->getParameters();
     } else {
         return $step->getParameters();
     }
 }
Example #5
0
 function __construct(redMigratorStep $step = null)
 {
     parent::__construct($step);
     $class = !empty($step->class) ? $step->class : 'redMigrator';
     $name = !empty($step->name) ? $step->name : '';
     $xmlpath = !empty($step->xmlpath) ? $step->xmlpath : '';
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     redMigratorHelper::requireClass($name, $xmlpath, $class);
     // @@ Fix bug using PHP < 5.2.3 version
     $this->_conditions = call_user_func($class . '::getConditionsHook');
     $db_config = array();
     $db_config['driver'] = $this->params->old_dbtype;
     $db_config['host'] = $this->params->old_hostname;
     $db_config['user'] = $this->params->old_username;
     $db_config['password'] = $this->params->old_password;
     $db_config['database'] = $this->params->old_db;
     $db_config['prefix'] = $this->params->old_dbprefix;
     $this->_db_old = JDatabase::getInstance($db_config);
 }
Example #6
0
 /**
  * Cleanup
  *
  * @return	none
  * @since	1.2.0
  */
 function cleanup()
 {
     // Loading the helper
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     // Importing helper tags
     jimport('cms.helper.tags');
     // Getting the component parameter with global settings
     $params = redMigratorHelper::getParams();
     // If REST is enable, cleanup the source #__redMigrator_steps table
     if ($params->method == 'rest') {
         $driver = redMigratorDriver::getInstance();
         $code = $driver->requestRest('cleanup');
     }
     // Set all cid, status and cache to 0
     $query = $this->_db->getQuery(true);
     $query->update('#__redmigrator_steps')->set('cid = 0, status = 0, cache = 0');
     $this->_db->setQuery($query)->execute();
     // Convert the params to array
     $core_skips = (array) $params;
     // Skiping the steps setted by user
     foreach ($core_skips as $k => $v) {
         $core = substr($k, 0, 9);
         $name = substr($k, 10, 18);
         if ($core == "skip_core") {
             if ($v == 1) {
                 $query->clear();
                 // Set all status to 0 and clear state
                 $query->update('#__redmigrator_steps')->set('status = 2')->where("name = '{$name}'");
                 try {
                     $this->_db->setQuery($query)->execute();
                 } catch (RuntimeException $e) {
                     throw new RuntimeException($e->getMessage());
                 }
                 $query->clear();
                 if ($name == 'users') {
                     $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'arogroup\'');
                     try {
                         $this->_db->setQuery($query)->execute();
                     } catch (RuntimeException $e) {
                         throw new RuntimeException($e->getMessage());
                     }
                     $query->clear();
                     $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'usergroupmap\'');
                     try {
                         $this->_db->setQuery($query)->execute();
                     } catch (RuntimeException $e) {
                         throw new RuntimeException($e->getMessage());
                     }
                 }
                 if ($name == 'categories') {
                     $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'sections\'');
                     try {
                         $this->_db->setQuery($query)->execute();
                     } catch (RuntimeException $e) {
                         throw new RuntimeException($e->getMessage());
                     }
                 }
             }
         }
         if ($k == 'skip_extensions') {
             if ($v == 1) {
                 $query->clear();
                 $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'extensions\'');
                 try {
                     $this->_db->setQuery($query)->execute();
                 } catch (RuntimeException $e) {
                     throw new RuntimeException($e->getMessage());
                 }
             }
         }
     }
     // Truncate the selected tables
     $tables = array();
     $tables[] = '#__redmigrator_categories';
     $tables[] = '#__redmigrator_menus';
     $tables[] = '#__redmigrator_modules';
     $tables[] = '#__redmigrator_default_categories';
     //$tables[] = '#__menu_types';
     //$tables[] = '#__content';
     for ($i = 0; $i < count($tables); $i++) {
         $query->clear();
         $query->delete()->from("{$tables[$i]}");
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
     }
     // Cleanup the menu table
     if ($params->skip_core_menus != 1) {
         // Insert needed value
         $query->clear();
         $query->insert('#__redmigrator_menus')->columns('`old`, `new`')->values("0, 0");
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Clear the default database
         $query->clear();
         $query->delete()->from('#__redmigrator_default_menus')->where('id > 100');
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Getting the menus
         $query->clear();
         // 3.0 Changes
         if (version_compare(PHP_VERSION, '3.0', '>=')) {
             $query->select("`menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `component_id`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `home`, `language`, `client_id`");
         } else {
             $query->select("`menutype`, `title`, `alias`, `note`, `path`, `link`, `type`, `published`, `parent_id`, `component_id`, `ordering`, `checked_out`, `checked_out_time`, `browserNav`, `access`, `img`, `template_style_id`, `params`, `home`, `language`, `client_id`");
         }
         $query->from("#__menu");
         $query->where("id > 100");
         $query->where("alias != 'home'");
         $query->order('id ASC');
         $this->_db->setQuery($query);
         try {
             $menus = $this->_db->loadObjectList();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         foreach ($menus as $menu) {
             // Convert the array into an object.
             $menu = (object) $menu;
             try {
                 $this->_db->insertObject('#__redmigrator_default_menus', $menu);
             } catch (RuntimeException $e) {
                 throw new RuntimeException($e->getMessage());
             }
         }
         // Cleanup the entire menu
         $query->clear();
         $query->delete()->from('#__menu')->where('id > 1');
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
     }
     // Delete uncategorised categories
     if ($params->skip_core_categories != 1) {
         // Insert uncategorized id
         $query->clear();
         $query->insert('#__redmigrator_categories')->columns('`old`, `new`')->values("0, 2");
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Getting the menus
         $query->clear();
         $query->select("`id`, `parent_id`, `path`, `extension`, `title`, `alias`, `note`, `description`, `published`,  `params`, `created_user_id`");
         $query->from("#__categories");
         $query->where("id > 1");
         $query->order('id ASC');
         $this->_db->setQuery($query);
         try {
             $categories = $this->_db->loadObjectList();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         foreach ($categories as $category) {
             $id = $category->id;
             unset($category->id);
             $this->_db->insertObject('#__redmigrator_default_categories', $category);
             // Getting the categories table
             $table = JTable::getInstance('Category', 'JTable');
             // Load it before delete. Joomla bug?
             $table->load($id);
             // Delete
             $table->delete($id);
         }
     }
     // Change the id of the admin user
     if ($params->skip_core_users != 1) {
         // Getting the data
         $query->clear();
         $query->select("username");
         $query->from("#__users");
         $query->where("name = 'Super User'");
         $query->order('id ASC');
         $query->limit(1);
         $this->_db->setQuery($query);
         try {
             $superuser = $this->_db->loadResult();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Updating the super user id to 10
         $query->clear();
         $query->update("#__users");
         $query->set("`id` = 10");
         $query->where("username = '******'");
         // Execute the query
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Updating the user_usergroup_map
         $query->clear();
         $query->update("#__user_usergroup_map");
         $query->set("`user_id` = 10");
         $query->where("`group_id` = 8");
         // Execute the query
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
     }
     // Checking if modules were added.
     if ($params->skip_core_modules != 1) {
         $query->clear();
         $query->select('id');
         $query->from("`#__modules`");
         $query->order('id DESC');
         $query->limit(1);
         $this->_db->setQuery($query);
         try {
             $modules_id = $this->_db->loadResult();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         if ($modules_id > 86) {
             $query->clear();
             $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'modules\'');
             try {
                 $this->_db->setQuery($query)->execute();
             } catch (RuntimeException $e) {
                 throw new RuntimeException($e->getMessage());
             }
             $query->clear();
             $query->update('#__redmigrator_steps')->set('status = 2')->where('name = \'modules_menu\'');
             try {
                 $this->_db->setQuery($query)->execute();
             } catch (RuntimeException $e) {
                 throw new RuntimeException($e->getMessage());
             }
         }
         // Cleanup the modules for 'site' unused modules
         $query->clear();
         $query->delete()->from('#__modules')->where('client_id = 0');
         try {
             $this->_db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
     }
     // Done checks
     if (!redMigratorHelper::isCli()) {
         $this->returnError(100, 'DONE');
     }
 }
Example #7
0
 /**
  * Get the next step
  *
  * @return   step object
  */
 public function getStep($name = false, $json = true)
 {
     // Check if step is loaded
     if (empty($name)) {
         return false;
     }
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     $params = redMigratorHelper::getParams();
     $limit = $params->chunk_limit;
     // Getting the total
     if (isset($this->source)) {
         $this->total = redMigratorHelper::getTotal($this);
     }
     // We must to fragment the steps
     if ($this->total > $limit) {
         if ($this->cache == 0 && $this->status == 0) {
             if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
                 $this->cache = round(($this->total - 1) / $limit, 0, PHP_ROUND_HALF_DOWN);
             } else {
                 $this->cache = round(($this->total - 1) / $limit);
             }
             $this->start = 0;
             $this->stop = $limit - 1;
             $this->first = true;
             $this->debug = "{{{1}}}";
         } else {
             if ($this->cache == 1 && $this->status == 1) {
                 $this->start = $this->cid;
                 $this->cache = 0;
                 $this->stop = $this->total - 1;
                 $this->debug = "{{{2}}}";
                 $this->first = false;
             } else {
                 if ($this->cache > 0) {
                     $this->start = $this->cid;
                     $this->stop = $this->start - 1 + $limit;
                     $this->cache = $this->cache - 1;
                     $this->debug = "{{{3}}}";
                     $this->first = false;
                     if ($this->stop > $this->total) {
                         $this->stop = $this->total - 1;
                         $this->next = true;
                     } else {
                         $this->middle = true;
                     }
                 }
             }
         }
         // Status == 1
         $this->status = 1;
     } else {
         if ($this->total == 0) {
             $this->stop = -1;
             $this->next = 1;
             $this->first = true;
             if ($this->name == $this->laststep) {
                 $this->end = true;
             }
             $this->cache = 0;
             $this->status = 2;
             $this->debug = "{{{4}}}";
         } else {
             //$this->next = true;
             $this->start = 0;
             $this->first = 1;
             $this->cache = 0;
             $this->stop = $this->total - 1;
             $this->debug = "{{{5}}}";
         }
     }
     // Mark if is the end of the step
     if ($this->name == $this->laststep && $this->cache == 1) {
         $this->end = true;
     }
     // updating the status flag
     $this->_updateStep();
     return $this->getParameters();
 }
Example #8
0
 /**
  * Initial checks in redMigrator
  *
  * @return	none
  * @since	1.2.0
  */
 function checks()
 {
     // Loading the helper
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     // Getting the component parameter with global settings
     $params = redMigratorHelper::getParams();
     // Checking tables
     $tables = $this->_db->getTableList();
     // Check if the tables exists if not populate install.sql
     $tablesComp = array();
     $tablesComp[] = 'categories';
     $tablesComp[] = 'default_categories';
     $tablesComp[] = 'default_menus';
     $tablesComp[] = 'errors';
     $tablesComp[] = 'extensions';
     $tablesComp[] = 'extensions_tables';
     $tablesComp[] = 'files_images';
     $tablesComp[] = 'files_media';
     $tablesComp[] = 'files_templates';
     $tablesComp[] = 'menus';
     $tablesComp[] = 'modules';
     $tablesComp[] = 'steps';
     foreach ($tablesComp as $table) {
         if (!in_array($this->_db->getPrefix() . 'redmigrator_' . $table, $tables)) {
             if (redMigratorHelper::isCli()) {
                 print "\n-------------------------------------------------------------------------------------------------\n";
                 print "|  \tInstalling redMigrator tables\n";
             }
             redMigratorHelper::populateDatabase($this->_db, JPATH_COMPONENT_ADMINISTRATOR . '/sql/install.sql');
             break;
         }
     }
     // Define the message array
     $message = array();
     $message['status'] = "ERROR";
     // Getting the data
     $query = $this->_db->getQuery(true);
     $query->select('COUNT(id)');
     $query->from("`#__redmigrator_steps`");
     $this->_db->setQuery($query);
     $nine = $this->_db->loadResult();
     if ($nine < 10) {
         throw new Exception('COM_REDMIGRATOR_ERROR_TABLE_STEPS_NOT_VALID');
     }
     // Check safe_mode_gid
     if (@ini_get('safe_mode_gid') && @ini_get('safe_mode')) {
         throw new Exception('COM_REDMIGRATOR_ERROR_DISABLE_SAFE_GID');
     }
     // Check for bad configurations
     if ($params->method == "rest") {
         if (!isset($params->rest_hostname) || !isset($params->rest_username) || !isset($params->rest_password) || !isset($params->rest_key)) {
             throw new Exception('COM_REDMIGRATOR_ERROR_REST_CONFIG');
         }
         if ($params->rest_hostname == 'http://www.example.org/' || $params->rest_hostname == '' || $params->rest_username == '' || $params->rest_password == '' || $params->rest_key == '') {
             throw new Exception('COM_REDMIGRATOR_ERROR_REST_CONFIG');
         }
         // Checking the RESTful connection
         $driver = redMigratorDriver::getInstance();
         $code = $driver->requestRest('check');
         switch ($code) {
             case 401:
                 throw new Exception('COM_REDMIGRATOR_ERROR_REST_501');
             case 402:
                 throw new Exception('COM_REDMIGRATOR_ERROR_REST_502');
             case 403:
                 throw new Exception('COM_REDMIGRATOR_ERROR_REST_503');
             case 405:
                 throw new Exception('COM_REDMIGRATOR_ERROR_REST_505');
             case 406:
                 throw new Exception('COM_REDMIGRATOR_ERROR_REST_506');
         }
     }
     // Check for bad configurations
     if ($params->method == "database") {
         if ($params->old_hostname == '' || $params->old_username == '' || $params->old_db == '' || $params->old_dbprefix == '') {
             throw new Exception('COM_REDMIGRATOR_ERROR_DATABASE_CONFIG');
         }
     }
     // Convert the params to array
     $core_skips = (array) $params;
     $flag = false;
     // Check is all skips is set
     foreach ($core_skips as $k => $v) {
         $core = substr($k, 0, 9);
         $name = substr($k, 10, 18);
         if ($core == "skip_core") {
             if ($v == 0) {
                 $flag = true;
             }
         }
     }
     if ($flag === false) {
         throw new Exception('COM_REDMIGRATOR_ERROR_SKIPS_ALL');
     }
     // Checking tables
     if ($params->skip_core_contents != 1) {
         $query->clear();
         $query->select('COUNT(id)');
         $query->from("`#__content`");
         $this->_db->setQuery($query);
         $content_count = $this->_db->loadResult();
         if ($content_count > 0) {
             throw new Exception('COM_REDMIGRATOR_ERROR_DATABASE_CONTENT');
         }
     }
     // Checking tables
     if ($params->skip_core_users != 1) {
         $query->clear();
         $query->select('COUNT(id)');
         $query->from("`#__users`");
         $this->_db->setQuery($query);
         $users_count = $this->_db->loadResult();
         if ($users_count > 1) {
             throw new Exception('COM_REDMIGRATOR_ERROR_DATABASE_USERS');
         }
     }
     // Done checks
     if (!redMigratorHelper::isCli()) {
         $this->returnError(100, 'DONE');
     }
 }
Example #9
0
 /**
  *
  * @param   stdClass   $options  Parameters to be passed to the database driver.
  *
  * @return  redMigrator  A redMigrator object.
  *
  * @since  3.0.0
  */
 static function getInstance(redMigratorStep $step = null)
 {
     $class = '';
     if ($step == null) {
         return false;
     }
     // Correct the 3rd party extensions class name
     if (isset($step->element)) {
         $step->class = empty($step->class) ? 'redMigratorExtensions' : $step->class;
     }
     // Getting the class name
     if (isset($step->class)) {
         $class = $step->class;
     }
     // Require the correct file
     redMigratorHelper::requireClass($step->name, $step->xmlpath, $step->class);
     // If the class still doesn't exist we have nothing left to do but throw an exception.  We did our best.
     if (!class_exists($class)) {
         $class = 'redMigrator';
     }
     // Create our new redMigrator connector based on the options given.
     try {
         $instance = new $class($step);
     } catch (RuntimeException $e) {
         throw new RuntimeException(sprintf('Unable to load redMigrator object: %s', $e->getMessage()));
     }
     return $instance;
 }