예제 #1
0
 /**
  * Create data backup then force user to download the backup file.
  *
  * @return  void
  */
 public function backup($options = array())
 {
     $tables = array();
     $showlist = false;
     $showcase = false;
     foreach ($options['tables'] as $table) {
         if (strpos($table, '#__imageshow_showlist') !== false) {
             $showlist = true;
         }
         if (strpos($table, '#__imageshow_showcase') !== false) {
             $showcase = true;
         }
     }
     // Get Joomla config
     $config = JFactory::getConfig();
     $objJSNISData = JSNISFactory::getObj('classes.jsn_is_data');
     // Initialize variables
     $com = preg_replace('/^com_/i', '', JFactory::getApplication()->input->getCmd('option'));
     $name = (isset($options['name']) and !empty($options['name'])) ? $options['name'] . (@$options['timestamp'] ? '_' . date('YmdHis') : '') : date('YmdHis');
     $name = array('zip' => "{$name}.zip", 'xml' => "jsn_{$com}_backup_db.xml");
     // Do any preparation needed before doing real data backup
     try {
         $this->beforeBackup($options, $name);
     } catch (Exception $e) {
         throw $e;
     }
     // Backup data from selected tables
     //$this->backupTables($options['tables']);
     $this->data = $objJSNISData->executeBackup($showlist, $showcase);
     // Backup files from selected folders
     $this->backupFiles($options['files']);
     // Do any extra work needed after doing real data backup
     try {
         $this->afterBackup($options, $name);
     } catch (Exception $e) {
         throw $e;
     }
     // Force client to download backup file
     if (isset($this->zippedBackup)) {
         if (!isset($options['no-download']) or !$options['no-download']) {
             JSNUtilsFile::forceDownload($name['zip'], $this->zippedBackup, 'application/zip', true);
         } else {
             // Store zipped backup to file system
             JFile::write($config->get('tmp_path') . '/' . $name['zip'], $this->zippedBackup);
             return $config->get('tmp_path') . '/' . $name['zip'];
         }
     }
     throw new Exception(JText::_('JSN_EXTFW_DATA_BACKUP_FAIL'));
 }
예제 #2
0
 /**
  * Backup selected database tables and/or files.
  *
  * @param   array  $options  Backup options.
  *
  * @return  void
  */
 public function backup($options = array())
 {
     // Get Joomla config and version object
     $config = JFactory::getConfig();
     $jVer = new JVersion();
     // Initialize variables
     $tag = isset($options['xmlRoot']) ? $options['xmlRoot'] : 'backup';
     $com = preg_replace('/^com_/i', '', JFactory::getApplication()->input->getCmd('option'));
     $info = JSNUtilsXml::loadManifestCache();
     $name = (isset($options['name']) and !empty($options['name'])) ? $options['name'] . (@$options['timestamp'] ? '_' . date('YmdHis') : '') : date('YmdHis');
     $name = array('zip' => "{$name}.zip", 'xml' => "jsn_{$com}_backup_db.xml");
     // Preset XML object for holding backed up data
     $this->data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><' . $tag . '></' . $tag . '>');
     $this->data->addAttribute('extension-name', 'JSN ' . preg_replace('/JSN\\s*/i', '', JText::_($info->name)));
     if ($const = JSNUtilsText::getConstant('EDITION')) {
         $this->data->addAttribute('extension-edition', $const);
     }
     $this->data->addAttribute('extension-version', $info->version);
     $this->data->addAttribute('joomla-version', $jVer->getShortVersion());
     // Do any preparation needed before doing real data backup
     try {
         $this->beforeBackup($options, $name);
     } catch (Exception $e) {
         throw $e;
     }
     // Backup data from selected tables
     $this->backupTables($options['tables']);
     // Backup files from selected folders
     $this->backupFiles($options['files']);
     // Do any extra work needed after doing real data backup
     try {
         $this->afterBackup($options, $name);
     } catch (Exception $e) {
         throw $e;
     }
     // Force client to download backup file
     if (isset($this->zippedBackup)) {
         if (!isset($options['no-download']) or !$options['no-download']) {
             JSNUtilsFile::forceDownload($name['zip'], $this->zippedBackup, 'application/zip', true);
         } else {
             // Store zipped backup to file system
             JFile::write($config->get('tmp_path') . '/' . $name['zip'], $this->zippedBackup);
             return $config->get('tmp_path') . '/' . $name['zip'];
         }
     }
     throw new Exception(JText::_('JSN_EXTFW_DATA_BACKUP_FAIL'));
 }