コード例 #1
0
ファイル: driver.php プロジェクト: klas/matware-libraries
 /**
  *
  * @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;
 }
コード例 #2
0
ファイル: menus.php プロジェクト: klas/matware-libraries
 /**
  * Method to be called before migrate any data
  *
  * @return	array
  * @since	3.2.0
  * @throws	Exception
  */
 public function beforeHook()
 {
     // Insert needed value
     $query = $this->_db->getQuery(true);
     $query->insert('#__jupgradepro_menus')->columns('`old`, `new`')->values("0, 0");
     try {
         $this->_db->setQuery($query)->execute();
     } catch (RuntimeException $e) {
         throw new RuntimeException($e->getMessage());
     }
     if ($this->params->keep_ids == 1) {
         // Clear the default database
         $query->clear();
         $query->delete()->from('#__jupgradepro_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(JUpgradeproHelper::getVersion('new'), '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('#__jupgradepro_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());
         }
     }
 }
コード例 #3
0
ファイル: contacts.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	3.0.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         $row = (array) $row;
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row['imagepos']);
         }
     }
     return $rows;
 }
コード例 #4
0
ファイル: weblinks.php プロジェクト: klas/matware-libraries
 /**
  * Get the raw data for this part of the upgrade.
  *
  * @return	array	Returns a reference to the source data array.
  * @since		3.2.0
  * @throws	Exception
  */
 public function &dataHook($rows)
 {
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         $row = (array) $row;
         // Remove unused fields.
         if (version_compare(JUpgradeproHelper::getVersion('new'), '2.5', '=')) {
             unset($row['version']);
             unset($row['images']);
         }
     }
     return $rows;
 }
コード例 #5
0
ファイル: contents.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.5.3
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     $params = $this->getParams();
     $table = $this->getDestinationTable();
     // Get category mapping
     $query = "SELECT * FROM #__jupgradepro_categories WHERE section REGEXP '^[\\-\\+]?[[:digit:]]*\\.?[[:digit:]]*\$' AND old > 0";
     $this->_db->setQuery($query);
     $catidmap = $this->_db->loadObjectList('old');
     // Find uncategorised category id
     $query = "SELECT id FROM #__categories WHERE extension='com_content' AND path='uncategorised' LIMIT 1";
     $this->_db->setQuery($query);
     $defaultId = $this->_db->loadResult();
     // Initialize values
     $aliases = array();
     $total = count($rows);
     // Insert content data
     foreach ($rows as $row) {
         $row = (array) $row;
         // Check if title and alias isn't blank
         $row['title'] = !empty($row['title']) ? $row['title'] : "###BLANK###";
         $row['alias'] = !empty($row['alias']) ? $row['alias'] : "###BLANK###";
         // Add tags if Joomla! is greater than 3.1
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.1', '>=')) {
             $row['metadata'] = $row['metadata'] . "\ntags=";
         }
         // JTable:store() run an update if id exists into the object so we create them first
         $object = new stdClass();
         $object->id = $row['id'];
         // Inserting the content
         if (!$this->_db->insertObject($table, $object)) {
             throw new Exception($this->_db->getErrorMsg());
         }
         // Getting the asset table
         $content = JTable::getInstance('Content', 'JTable', array('dbo' => $this->_db));
         // Bind data to save content
         if (!$content->bind($row)) {
             throw new Exception($content->getError());
         }
         // Check the content
         if (!$content->check()) {
             throw new Exception($content->getError());
         }
         // Insert the content
         if (!$content->store()) {
             throw new Exception($content->getError());
         }
         // Updating the steps table
         $this->_step->_nextID($total);
     }
     return false;
 }
コード例 #6
0
ファイル: weblinks.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	3.0.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Getting the component parameter with global settings
     $params = $this->getParams();
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         // Convert the array into an object.
         $row = (array) $row;
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row['approved']);
             unset($row['archived']);
             unset($row['date']);
             unset($row['sid']);
         }
     }
     return $rows;
 }
コード例 #7
0
ファイル: newsfeeds.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	3.0.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Getting the component parameter with global settings
     $params = $this->getParams();
     // Getting the categories id's
     $categories = $this->getMapList('categories', 'com_newsfeeds');
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         $row = (array) $row;
         $row['access'] = 1;
         $row['language'] = '*';
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row['filename']);
         }
         $cid = $row['catid'];
         $row['catid'] =& $categories[$cid]->new;
     }
     return $rows;
 }
コード例 #8
0
ファイル: users.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.4.
  * @throws	Exception
  */
 public function dataHook($rows)
 {
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         $row = (array) $row;
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row['usertype']);
             if (isset($row['uid'])) {
                 unset($row['uid']);
             }
         }
         // Chaging admin username and email
         if ($row['username'] == 'admin') {
             $row['username'] = $row['username'] . '-old';
             $row['email'] = $row['email'] . '-old';
         }
         // Remove unused fields.
         unset($row['gid']);
     }
     return $rows;
 }
コード例 #9
0
ファイル: categories.php プロジェクト: klas/matware-libraries
 /**
  * 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;
 }
コード例 #10
0
ファイル: database.php プロジェクト: klas/matware-libraries
 function __construct(JUpgradeproStep $step = null)
 {
     parent::__construct($step);
     $class = !empty($step->class) ? $step->class : 'JUpgradepro';
     $name = !empty($step->name) ? $step->name : '';
     $xmlpath = !empty($step->xmlpath) ? $step->xmlpath : '';
     JLoader::import('helpers.jupgradepro', JPATH_COMPONENT_ADMINISTRATOR);
     JUpgradeproHelper::requireClass($name, $xmlpath, $class);
     // @@ Fix bug using PHP < 5.2.3 version
     if (version_compare(PHP_VERSION, '5.2.3', '<')) {
         $this->_conditions = call_user_func(array($class, 'getConditionsHook'));
     } else {
         $this->_conditions = $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);
 }
コード例 #11
0
ファイル: weblinks.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	3.0.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Getting the component parameter with global settings
     $params = $this->getParams();
     // Getting the categories id's
     $categories = $this->getMapList('categories', 'com_weblinks');
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         // Convert the array into an object.
         $row = (array) $row;
         $cid = $row['catid'];
         $row['catid'] =& $categories[$cid]->new;
         $row['language'] = '*';
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             $row['created'] = $row['date'];
             unset($row['approved']);
             unset($row['archived']);
             unset($row['date']);
             unset($row['sid']);
         }
         unset($row['published']);
     }
     return $rows;
 }
コード例 #12
0
ファイル: step.php プロジェクト: klas/matware-libraries
 /**
  * Updating the steps table
  *
  * @return  boolean  True if the user and pass are authorized
  *
  * @since   1.0
  * @throws  InvalidArgumentException
  */
 public function _nextID($total = false)
 {
     $update_cid = (int) $this->_getStepID() + 1;
     $this->_updateID($update_cid);
     echo JUpgradeproHelper::isCli() ? "•" : "";
 }
コード例 #13
0
ファイル: jupgrade.php プロジェクト: klas/matware-libraries
 /**
  *
  * @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)
 {
     if ($step == null) {
         return false;
     }
     // Correct the 3rd party extensions class name
     if (isset($step->element)) {
         $step->class = empty($step->class) ? 'JUpgradeproExtensions' : $step->class;
     }
     // Getting the class name
     $class = '';
     if (isset($step->class)) {
         $class = $step->class;
     }
     // Require the correct file
     if (is_object($step)) {
         JUpgradeproHelper::requireClass($step->name, $step->xmlpath, $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 = 'JUpgradepro';
     }
     // Create our new jUpgradePro connector based on the options given.
     try {
         $instance = new $class($step);
     } catch (RuntimeException $e) {
         throw new RuntimeException(sprintf('Unable to load JUpgradepro object: %s', $e->getMessage()));
     }
     return $instance;
 }
コード例 #14
0
ファイル: sections.php プロジェクト: klas/matware-libraries
 /**
  * Run custom code after hooks
  *
  * @return	void
  * @since	3.0
  */
 public function afterHook()
 {
     // Fixing the parents
     $this->fixParents();
     // Insert existing categories
     $this->insertExisting();
     // Change protected to $observers object to disable it
     // @@ Prevent Joomla! 'Application Instantiation Error' when try to call observers
     // @@ See: https://github.com/joomla/joomla-cms/pull/3408
     if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
         $file = JPATH_LIBRARIES . '/joomla/observer/updater.php';
         $read = JFile::read($file);
         $read = str_replace("//call_user_func_array(\$eventListener, \$params)", "call_user_func_array(\$eventListener, \$params)", $read);
         $read = JFile::write($file, $read);
         require_once $file;
     }
 }
コード例 #15
0
ファイル: menus.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.4.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Get the query
     $query = $this->_db->getQuery(true);
     // Get the params
     $params = $this->getParams();
     // Get the table name
     $tablename = $this->getDestinationTable();
     // Getting the extensions id's of the new Joomla installation
     $query->clear();
     $query->select('extension_id, element');
     $query->from('#__extensions');
     $this->_db->setQuery($query);
     $extensions_ids = $this->_db->loadObjectList('element');
     // Initialize values
     $unique_alias_suffix = 1;
     $total = count($rows);
     $oldnewmap = array();
     // Getting the table and query
     $table = JTable::getInstance('Menu', 'JTable');
     // Start the update
     foreach ($rows as &$row) {
         // Convert the array into an object.
         $row = (object) $row;
         // Converting params to JSON
         $row->params = $this->convertParams($row->params);
         // Fixing language
         $row->language = '*';
         // Fixing access
         $row->access++;
         // Fixing level
         if (isset($row->sublevel)) {
             $row->level = $row->sublevel++;
         }
         // Prevent MySQL duplicate error
         // @@ Duplicate entry for key 'idx_client_id_parent_id_alias_language'
         $alias = $this->getAlias('#__menu', $row->alias);
         $row->alias = !empty($alias) ? $alias . "-" . rand(0, 999999) : $row->alias;
         // Fixing menus URLs
         $row = $this->migrateLink($row);
         // Get new/old id's values
         $rowMap = new stdClass();
         // Save the old id
         $rowMap->old = $row->id;
         // Fixing id if == 1 (used by root)
         if ($row->id == 1) {
             $query->clear();
             $query->select('id + 1');
             $query->from('#__menu');
             $query->order('id DESC');
             $query->limit(1);
             $this->_db->setQuery($query);
             $row->id = $this->_db->loadResult();
         }
         // Fixing extension_id
         if (isset($row->option)) {
             $row->component_id = isset($extensions_ids[$row->option]) ? $extensions_ids[$row->option]->extension_id : 0;
         }
         // Fixing name
         $row->title = $row->name;
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row->ordering);
         }
         // Not needed
         unset($row->id);
         unset($row->name);
         unset($row->option);
         unset($row->componentid);
         // Bind the data
         try {
             $table->bind((array) $row);
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Store to database
         try {
             $table->store();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Save the new id in rowmap and row
         $rowMap->new = $table->id;
         $row->id = $table->id;
         $oldnewmap[$rowMap->old] = $rowMap;
         // Save old and new id
         try {
             $this->_db->insertObject('#__jupgradepro_menus', $rowMap);
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
         $table->reset();
         $table->id = 0;
     }
     // now rebuild tree by fixing parents and location
     foreach ($rows as $row) {
         $table->reset();
         $table->id = 0;
         $row->lft = $row->rgt = null;
         $row->parent = isset($oldnewmap[$row->parent]) ? $oldnewmap[$row->parent]->new : 1;
         // Bind the data
         try {
             $table->bind((array) $row);
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         $table->setLocation($row->parent, 'last-child');
         try {
             $table->check();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         // Store to database
         try {
             $table->store();
         } catch (RuntimeException $e) {
             throw new RuntimeException($e->getMessage());
         }
         $table->rebuildPath($table->id);
         // Updating the steps table
         $this->_step->_nextID($total);
     }
     // rebuild table
     try {
         $table->rebuild();
     } catch (RuntimeException $e) {
         throw new RuntimeException($e->getMessage());
     }
     return false;
 }
コード例 #16
0
ファイル: modules.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.4.
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     // Getting the source table
     $table = $this->getSourceTable();
     // Getting the component parameter with global settings
     $params = $this->getParams();
     // Set up the mapping table for the old positions to the new positions.
     $map = self::getPositionsMap();
     $map_keys = array_keys($map);
     $total = count($rows);
     //
     foreach ($rows as $row) {
         // Convert the array into an object.
         $row = (object) $row;
         ## Change positions
         if ($params->positions == 0) {
             if (in_array($row->position, $map_keys)) {
                 $row->position = $map[$row->position];
             }
         }
         // Get old id
         $oldlist = new stdClass();
         $oldlist->old = $row->id;
         unset($row->id);
         if (version_compare(JUpgradeproHelper::getVersion('new'), '1.5', '>=')) {
             unset($row->numnews);
             unset($row->iscore);
             unset($row->control);
         }
         // Insert module
         if (!$this->_db->insertObject($table, $row)) {
             throw new Exception($this->_db->getErrorMsg());
         }
         // Get new id
         $oldlist->new = $this->_db->insertid();
         // Save old and new id
         if (!$this->_db->insertObject('#__jupgradepro_modules', $oldlist)) {
             throw new Exception($this->_db->getErrorMsg());
         }
         // Updating the steps table
         $this->_step->_nextID($total);
     }
     return false;
 }
コード例 #17
0
ファイル: users.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.4.
  * @throws	Exception
  */
 public function dataHook($rows)
 {
     // Do some custom post processing on the list.
     foreach ($rows as &$row) {
         $row = (array) $row;
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
             unset($row['usertype']);
         }
         // Remove unused fields.
         unset($row['gid']);
     }
     return $rows;
 }
コード例 #18
0
ファイル: category.php プロジェクト: klas/matware-libraries
 /**
  * Inserts a category
  *
  * @access  public
  * @param   row  An array whose properties match table fields
  * @since	0.4.
  */
 public function insertCategory($row, $parent = false)
 {
     // Get the category table
     $category = JTable::getInstance('Category', 'JTable', array('dbo' => $this->_db));
     // Disable observers calls
     // @@ Prevent Joomla! 'Application Instantiation Error' when try to call observers
     // @@ See: https://github.com/joomla/joomla-cms/pull/3408
     if (version_compare(JUpgradeproHelper::getVersion('new'), '3.0', '>=')) {
         //$category->_observers->doCallObservers(false);
     }
     // Get section and old id
     $oldlist = new stdClass();
     $oldlist->section = !empty($row['extension']) ? $row['extension'] : 0;
     $oldlist->old = isset($row['old_id']) ? (int) $row['old_id'] : (int) $row['id'];
     unset($row['old_id']);
     // Setting the default rules
     $rules = array();
     $rules['core.create'] = $rules['core.delete'] = $rules['core.edit'] = $rules['core.edit.state'] = $rules['core.edit.own'] = '';
     $row['rules'] = $rules;
     // Fix language
     $row['language'] = !empty($row['language']) ? $row['language'] : '*';
     // Fix language
     $row['level'] = !empty($row['level']) ? $row['level'] : 1;
     // Check if path is correct
     $row['path'] = empty($row['path']) ? $row['alias'] : $row['path'];
     // Get alias from title if its empty
     if ($row['alias'] == "") {
         $row['alias'] = JFilterOutput::stringURLSafe($row['title']);
     }
     // Check if has duplicated aliases
     $alias = $this->getAlias('#__categories', $row['alias'], $row['extension']);
     // Prevent MySQL duplicate error
     // @@ Duplicate entry for key 'idx_client_id_parent_id_alias_language'
     $row['alias'] = !empty($alias) ? $alias . "-" . rand(0, 999999) : $row['alias'];
     // Remove the default id if keep ids parameters is not enabled
     if ($this->params->keep_ids != 1) {
         // Unset id
         unset($row['id']);
         // Save the parent if old installation is 2.5 or greater
         if (version_compare(JUpgradeproHelper::getVersion('old'), '1.5', '>') && $row['parent_id'] != 1) {
             $oldlist->section = $row['parent_id'];
         } else {
             $parent = 1;
         }
     } else {
         if ($this->params->keep_ids == 1) {
             // Save section id if old Joomla! version is 1.0
             if (version_compare(JUpgradeproHelper::getVersion('old'), '1.0', '=') && isset($row['section'])) {
                 $oldlist->section = $row['section'];
             } else {
                 if (version_compare(JUpgradeproHelper::getVersion('old'), '1.5', '>') && $row['parent_id'] != 1) {
                     $oldlist->section = $row['parent_id'];
                 }
             }
         }
     }
     // Correct extension
     if (isset($row['extension'])) {
         if (is_numeric($row['extension']) || $row['extension'] == "" || $row['extension'] == "category") {
             $row['extension'] = "com_content";
         }
     }
     // Fixing extension name if it's section
     if ($row['extension'] == 'com_section') {
         unset($row['id']);
         $row['extension'] = "com_content";
         $parent = 1;
     }
     // If has parent made $path and get parent id
     if ($parent !== false) {
         // Setting the location of the new category
         $category->setLocation($parent, 'last-child');
     } else {
         $category->setLocation(1, 'last-child');
     }
     // Bind data to save category
     if (!$category->bind($row)) {
         throw new Exception($category->getError());
     }
     // Insert the category
     if (!$category->store()) {
         throw new Exception($category->getError());
     }
     // Get new id
     $oldlist->new = (int) $category->id;
     // Insert the row backup
     if (!$this->_db->insertObject('#__jupgradepro_categories', $oldlist)) {
         throw new Exception($this->_db->getErrorMsg());
     }
     return true;
 }
コード例 #19
0
ファイル: users.php プロジェクト: klas/matware-libraries
 /**
  * Method to get a map of the User id to ARO id.
  *
  * @returns	array	An array of the user id's keyed by ARO id.
  * @since	0.4.4
  * @throws	Exception on database error.
  */
 protected function getUserIdAroMap($aro_id)
 {
     // Get the version
     $old_version = JUpgradeproHelper::getVersion('old');
     // Get thge correct table key
     $key = $old_version == '1.0' ? 'aro_id' : 'id';
     $this->_driver->_db_old->setQuery('SELECT value' . ' FROM #__core_acl_aro' . ' WHERE ' . $key . ' = ' . $aro_id);
     $return = $this->_driver->_db_old->loadResult();
     $error = $this->_driver->_db_old->getErrorMsg();
     // Check for query error.
     if ($error) {
         throw new Exception($error);
     }
     return $return;
 }
コード例 #20
0
ファイル: contents.php プロジェクト: klas/matware-libraries
 /**
  * Sets the data in the destination database.
  *
  * @return	void
  * @since	0.5.3
  * @throws	Exception
  */
 public function dataHook($rows = null)
 {
     $params = $this->getParams();
     $table = $this->getDestinationTable();
     // Get category mapping
     $query = "SELECT * FROM #__jupgradepro_categories WHERE section REGEXP '^[\\-\\+]?[[:digit:]]*\\.?[[:digit:]]*\$' AND old > 0";
     $this->_db->setQuery($query);
     $catidmap = $this->_db->loadObjectList('old');
     // Find uncategorised category id
     $query = "SELECT id FROM #__categories WHERE extension='com_content' AND path='uncategorised' LIMIT 1";
     $this->_db->setQuery($query);
     $defaultId = $this->_db->loadResult();
     // Initialize values
     $aliases = array();
     $total = count($rows);
     //
     // Insert content data
     //
     foreach ($rows as $row) {
         $row = (array) $row;
         // Check if title isn't blank
         $row['title'] = !empty($row['title']) ? $row['title'] : "###BLANK###";
         // Map catid
         $row['catid'] = isset($catidmap[$row['catid']]) ? $catidmap[$row['catid']]->new : $defaultId;
         // Setting the default rules
         $rules = array();
         $rules['core.delete'] = array('6' => true);
         $rules['core.edit'] = array('6' => true, '4' => 1);
         $rules['core.edit.state'] = array('6' => true, '5' => 1);
         $row['rules'] = $rules;
         // Add tags if Joomla! is greater than 3.1
         if (version_compare(JUpgradeproHelper::getVersion('new'), '3.1', '>=')) {
             $row['metadata'] = $row['metadata'] . "\ntags=";
         }
         // Converting the metadata to JSON
         $row['metadata'] = $this->convertParams($row['metadata'], false);
         if ($this->params->keep_ids == 1) {
             // JTable:store() run an update if id exists into the object so we create them first
             $object = new stdClass();
             $object->id = $row['id'];
             // Inserting the content
             if (!$this->_db->insertObject($table, $object)) {
                 throw new Exception($this->_db->getErrorMsg());
             }
         } else {
             unset($row['id']);
         }
         // Get the asset table
         $content = JTable::getInstance('Content', 'JTable', array('dbo' => $this->_db));
         // Aliases
         $row['alias'] = !empty($row['alias']) ? $row['alias'] : "###BLANK###";
         $row['alias'] = JApplication::stringURLSafe($row['alias']);
         // Prevent MySQL duplicate error
         // @@ Duplicate entry for key 'idx_client_id_parent_id_alias_language'
         if ($content->load(array('alias' => $row['alias'], 'catid' => $row['catid']))) {
             $content->reset();
             $content->id = 0;
             // Set the modified alias
             $row['alias'] .= "-" . rand(0, 99999999);
         }
         // Bind data to save content
         if (!$content->bind($row)) {
             throw new Exception($content->getError());
         }
         // Check the content
         if (!$content->check()) {
             throw new Exception($content->getError());
         }
         // Insert the content
         if (!$content->store()) {
             throw new Exception($content->getError());
         }
         // Updating the steps table
         $this->_step->_nextID($total);
     }
     return false;
 }
コード例 #21
0
ファイル: extensions.php プロジェクト: klas/matware-libraries
 /**
  * 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;
 }