Exemplo n.º 1
0
 function __construct(redMigratorStep $step = null)
 {
     // Set the current step
     $this->_step = $step;
     jimport('legacy.component.helper');
     jimport('cms.version.version');
     JLoader::import('helpers.redmigrator', JPATH_COMPONENT_ADMINISTRATOR);
     $this->params = redMigratorHelper::getParams();
     // Getting the J! version
     $version = new JVersion();
     $this->_version = $version->RELEASE;
     // Creating dabatase instance for this installation
     $this->_db = JFactory::getDBO();
     // Getting the driver
     JLoader::register('redMigratorDriver', JPATH_COMPONENT_ADMINISTRATOR . '/includes/redmigrator.driver.class.php');
     if ($this->_step instanceof redMigratorStep) {
         $this->_step->table = $this->getSourceTable();
         // Initialize the driver
         $this->_driver = redMigratorDriver::getInstance($step);
     }
     // Getting the total
     if (!empty($step->source)) {
         $this->_total = redMigratorHelper::getTotal($step);
     }
     // Set timelimit to 0
     if (!@ini_get('safe_mode')) {
         if (!empty($this->params->timelimit)) {
             set_time_limit(0);
         }
     }
     // Make sure we can see all errors.
     if (!empty($this->params->error_reporting)) {
         error_reporting(E_ALL);
         @ini_set('display_errors', 1);
     }
     // MySQL grants check
     $query = "SHOW GRANTS FOR CURRENT_USER";
     $this->_db->setQuery($query);
     $list = $this->_db->loadRowList();
     $grant = isset($list[1][0]) ? $list[1][0] : $list[0][0];
     $grant = empty($list[1][0]) ? $list[0][0] : $list[1][0];
     if (strpos($grant, 'DROP') == true || strpos($grant, 'ALL') == true) {
         $this->canDrop = true;
     }
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
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');
     }
 }
Exemplo n.º 4
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');
     }
 }
Exemplo n.º 5
0
 /**
  * Getting the total 
  *
  * @return  int	The total number
  *
  * @since   3.0.0
  */
 public static function getTotal(redMigratorStep $step = null)
 {
     JLoader::register('redMigratorDriver', JPATH_COMPONENT_ADMINISTRATOR . '/includes/redmigrator.driver.class.php');
     $driver = redMigratorDriver::getInstance($step);
     return $driver->getTotal();
 }
Exemplo n.º 6
0
 function __construct(redMigratorStep $step = null)
 {
     parent::__construct($step);
 }