/** * 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(); } }
/** * 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(); } }
/** * 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'); } }
/** * 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[1;37m-------------------------------------------------------------------------------------------------\n"; print "[1;37m| [0;34m\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'); } }