예제 #1
0
파일: data.php 프로젝트: densem-2013/exikom
 /**
  * Do any preparation needed before doing real data restore.
  *
  * @param   string   &$backup       Path to folder containing extracted backup files.
  * @param   boolean  $checkEdition  Check for matching edition before restore?
  *
  * @return  void
  */
 protected function beforeRestore(&$backup, $checkEdition = true)
 {
     // Initialize variables
     $com = preg_replace('/^com_/i', '', JFactory::getApplication()->input->getCmd('option'));
     $info = JSNUtilsXml::loadManifestCache();
     $jVer = new JVersion();
     // Extract backup file
     if (!JArchive::extract($backup, substr($backup, 0, -4))) {
         throw new Exception(JText::_('JSN_EXTFW_DATA_EXTRACT_UPLOAD_FILE_FAIL'));
     }
     $backup = substr($backup, 0, -4);
     // Auto-detect backup XML file
     $files = glob("{$backup}/*.xml");
     foreach ($files as $file) {
         $this->data = JSNUtilsXml::load($file);
         // Check if this XML file contain backup data for our product
         if (strcasecmp($this->data->getName(), 'backup') == 0 and isset($this->data['extension-name']) and isset($this->data['extension-version']) and isset($this->data['joomla-version'])) {
             // Store backup XML file name
             $this->xml = basename($file);
             // Simply break the loop if we found backup file
             break;
         }
         unset($this->data);
     }
     if (isset($this->data)) {
         // Check if Joomla series match
         if (!$jVer->isCompatible((string) $this->data['joomla-version'])) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_JOOMLA_VERSION_NOT_MATCH'));
         }
         // Check if extension match
         if ((string) $this->data['extension-name'] != 'JSN ' . preg_replace('/JSN\\s*/i', '', JText::_($info->name))) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT'));
         } elseif (isset($this->data['extension-edition']) and $checkEdition and (!($const = JSNUtilsText::getConstant('EDITION')) or (string) $this->data['extension-edition'] != $const)) {
             throw new Exception(JText::_('JSN_EXTFW_DATA_INVALID_PRODUCT_EDITION'));
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], '=') and !$checkEdition) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         } elseif (!version_compare($info->version, (string) $this->data['extension-version'], 'ge')) {
             // Get update link for out-of-date product
             $ulink = $info->authorUrl;
             if (isset($this->data['update-url'])) {
                 $ulink = (string) $this->data['update-url'];
             } elseif ($const = JSNUtilsText::getConstant('UPDATE_LINK')) {
                 $ulink = $const;
             }
             throw new Exception(JText::_('JSN_EXTFW_DATA_PRODUCT_VERSION_OUTDATE') . '&nbsp;<a href="' . $ulink . '" class="jsn-link-action">' . JText::_('JSN_EXTFW_GENERAL_UPDATE_NOW') . '</a>');
         }
     } else {
         throw new Exception(JText::_('JSN_EXTFW_DATA_BACKUP_XML_NOT_FOUND'));
     }
     $dataForm = $this->getForm();
     if (!empty($dataForm) && count($dataForm)) {
         foreach ($dataForm as $formId) {
             if (!empty($formId->form_id) && (int) $formId->form_id) {
                 $this->_db->setQuery("DROP TABLE IF EXISTS #__jsn_uniform_submissions_{$formId->form_id}");
                 $this->_db->execute();
             }
         }
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submissions') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissions();
     }
     if (JSNUniformHelper::checkTableSql('#__jsn_uniform_submission_data') === false) {
         JSNUniformHelper::createTableIfNotExistsSubmissionData();
     }
 }