/** * * @param stdClass $options Parameters to be passed to the database driver. * * @return jUpgradePro A jUpgradePro object. * * @since 3.0.0 */ static function getInstance(JUpgradeproStep $step = null) { // Loading the JFile class jimport('joomla.filesystem.file'); // Getting the params and Joomla version web and cli $params = JUpgradeproHelper::getParams(); // Derive the class name from the driver. $class_name = 'JUpgradeproDriver' . ucfirst(strtolower($params->method)); $class_file = JPATH_LIBRARIES . '/matware/jupgrade/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 JUpgradepro Driver: %s', $params->method)); } // Create our new jUpgradeDriver connector based on the options given. try { $instance = new $class_name($step); } catch (RuntimeException $e) { throw new RuntimeException(sprintf('Unable to load jUpgradePro object: %s', $e->getMessage())); } return $instance; }
function __construct(JUpgradeproStep $step = null) { // Set the current step $this->_step = $step; jimport('legacy.component.helper'); jimport('cms.version.version'); JLoader::import('helpers.jupgradepro', JPATH_COMPONENT_ADMINISTRATOR); // Get the component parameters $this->params = JUpgradeproHelper::getParams(); // Create the dabatase instance for this installation $this->_db = JFactory::getDBO(); // Get the driver JLoader::register('JUpgradeproDriver', JPATH_LIBRARIES . '/matware/jupgrade/driver.php'); if ($this->_step instanceof JUpgradeproStep) { $this->_step->table = $this->getSourceTable(); } // Initialize the driver $this->_driver = JUpgradeproDriver::getInstance($step); // Get the total if (!empty($step->source)) { $this->_total = JUpgradeproHelper::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 = empty($list[1][0]) ? $list[0][0] : $list[1][0]; if (strpos($grant, 'DROP') == true || strpos($grant, 'ALL') == true) { $this->canDrop = true; } }
/** * Setting the conditions hook * * @return void * @since 3.0.0 * @throws Exception */ public static function getConditionsHook() { // Get the component parameters JLoader::import('helpers.jupgradepro', JPATH_COMPONENT_ADMINISTRATOR); $params = JUpgradeproHelper::getParams(); $conditions = array(); $conditions['select'] = '*'; if ($params->keep_ids == 1) { $where_or = array(); $where_or[] = "extension REGEXP '^[\\-\\+]?[[:digit:]]*\\.?[[:digit:]]*\$'"; $where_or[] = "extension IN ('com_banners', 'com_contact', 'com_content', 'com_newsfeeds', 'com_sections', 'com_weblinks' )"; $conditions['where_or'] = $where_or; $conditions['order'] = "id DESC, extension DESC"; } else { $where = array(); $where[] = "path != 'uncategorised'"; $where[] = "(extension REGEXP '^[\\-\\+]?[[:digit:]]*\\.?[[:digit:]]*\$' OR extension IN ('com_banners', 'com_contact', 'com_content', 'com_newsfeeds', 'com_sections', 'com_weblinks' ))"; $conditions['where'] = $where; $conditions['order'] = "parent_id DESC"; } return $conditions; }
/** * 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.jupgradepro', JPATH_COMPONENT_ADMINISTRATOR); $params = JUpgradeproHelper::getParams(); $limit = $this->chunk = $params->chunk_limit; // Getting the total if (isset($this->source)) { $this->total = JUpgradeproHelper::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->start = 0; $this->first = 1; $this->cache = 0; $this->status = 1; $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(); }
/** * Get the raw data for this part of the upgrade. * * @return array Returns a reference to the source data array. * @since 1.1.0 * @throws Exception */ protected function _processExtensions() { jimport('joomla.filesystem.folder'); // Getting the component parameter with global settings $params = JUpgradeproHelper::getParams(); $types = array('/^(.+)_(.+)_(.+)$/', '/^(.+)_(.+)$/'); function replaceClassName($matches) { if ($matches[1] == 'com') { $option = 'jUpgradeComponent' . ucfirst($matches[2]); } else { if ($matches[1] == 'mod') { $option = 'jUpgradeModule' . ucfirst($matches[2]); } else { if ($matches[1] == 'plg') { $option = 'jUpgradePlugin' . ucfirst($matches[2]) . ucfirst($matches[3]); } else { if ($matches[1] == 'tpl') { $option = 'jUpgradeTemplate' . ucfirst($matches[2]); } } } } return $option; } // Getting the plugins list $query = $this->_db->getQuery(true); $query->select('*'); $query->from('#__extensions'); $query->where("type = 'plugin'"); $query->where("folder = 'jupgradepro'"); $query->where("enabled = 1"); $query->where("state = 0"); // Setting the query and getting the result $this->_db->setQuery($query); $plugins = $this->_db->loadObjectList(); // Get the tables list and prefix from the old site if ($params->method == "database") { $old_tables = $this->_driver->_db_old->getTableList(); $old_prefix = $params->old_dbprefix; } else { if ($params->method == "rest") { $old_tables = json_decode($this->_driver->requestRest('tableslist')); $old_prefix = substr($old_tables[10], 0, strpos($old_tables[10], '_') + 1); } } // Get the old site version $old_version = JUpgradeproHelper::getVersion('old'); // Do some custom post processing on the list. foreach ($plugins as $plugin) { // Looking for xml files $files = (array) JFolder::files(JPATH_PLUGINS . "/jupgradepro/{$plugin->element}/extensions", '\\.xml$', true, true); foreach ($files as $xmlfile) { if (!empty($xmlfile)) { $element = JFile::stripExt(basename($xmlfile)); if (array_key_exists($element, $this->extensions)) { $extension = $this->extensions[$element]; // Read xml definition file $xml = simplexml_load_file($xmlfile); // Getting the php file if (!empty($xml->installer->file[0])) { $phpfile = JPATH_ROOT . '/' . trim($xml->installer->file[0]); } if (empty($phpfile)) { $default_phpfile = JPATH_PLUGINS . "/jupgradepro/{$plugin->element}/extensions/{$element}.php"; $phpfile = file_exists($default_phpfile) ? $default_phpfile : null; } // Getting the class if (!empty($xml->installer->class[0])) { $class = trim($xml->installer->class[0]); } if (empty($class)) { $class = preg_replace_callback($types, 'replaceClassName', $element); } // Saving the extensions and migrating the tables if (!empty($phpfile) || !empty($xmlfile)) { // Adding +1 to count $this->count = $this->count + 1; // Reset the $query object $query->clear(); $xmlpath = "{$plugin->element}/extensions/{$element}.xml"; // Checking if other migration exists $query = $this->_db->getQuery(true); $query->select('e.*'); $query->from('#__jupgradepro_extensions AS e'); $query->where('e.name = \'' . $element . '\''); $query->limit(1); $this->_db->setQuery($query); $exists = $this->_db->loadResult(); if (empty($exists)) { // Inserting the step to #__jupgradepro_extensions table $query->insert('#__jupgradepro_extensions')->columns('`version`, `name`, `title`, `class`, `xmlpath`')->values("'{$old_version}', '{$element}', '{$xml->name}', '{$class}', '{$xmlpath}'"); $this->_db->setQuery($query); $this->_db->execute(); } // Inserting the collection if exists if (isset($xml->name) && isset($xml->collection)) { $query->insert('#__update_sites')->columns('name, type, location, enabled')->values("'{$xml->name}', 'collection', '{$xml->collection}, 1"); $this->_db->setQuery($query); $this->_db->execute(); } // Converting the params if (version_compare($old_version, '1.5', '=')) { $extension->params = $this->convertParams($extension->params); } // Unset id unset($extension->extension_id); // Saving the extension to #__extensions table if (!$this->_db->insertObject('#__extensions', $extension)) { throw new Exception($this->_db->getErrorMsg()); } // Getting the extension id $extension->extension_id = $this->_db->insertid(); // Adding tables to migrate if (!empty($xml->tables[0])) { // Check if tables must to be replaced $main_replace = (string) $xml->tables->attributes()->replace; $count = count($xml->tables[0]->table); for ($i = 0; $i < $count; $i++) { // $table = new StdClass(); $table->name = $table->source = $table->destination = (string) $xml->tables->table[$i]; $table->eid = $extension->extension_id; $table->element = $element; $table->version = $old_version; $table->class = $class; $table->replace = (string) $xml->tables->table[$i]->attributes()->replace; $table->replace = !empty($table->replace) ? $table->replace : $main_replace; $table_name = $old_prefix . $table->name; if (in_array($table_name, $old_tables)) { if (!$this->_db->insertObject('#__jupgradepro_extensions_tables', $table)) { throw new Exception($this->_db->getErrorMsg()); } } } } // Add other extensions from the package if (!empty($xml->package[0])) { foreach ($xml->package[0]->extension as $xml_ext) { if (isset($this->extensions[(string) $xml_ext->name])) { $extension = $this->extensions[(string) $xml_ext->name]; $state->extensions[] = (string) $xml_ext->name; $extension->params = $this->convertParams($extension->params); if (!$this->_db->insertObject('#__extensions', $extension)) { throw new Exception($this->_db->getErrorMsg()); } unset($this->extensions[(string) $xml_ext->name]); } } } } //end if } // end if } // end if unset($class); unset($phpfile); unset($xmlfile); } // end foreach } // end foreach return $this->count; }