Beispiel #1
0
 /**
  * Backup all modified files
  *
  * @return  void
  */
 public function backupAction()
 {
     // Initialize variables
     $app = JFactory::getApplication();
     $joomlaConfig = JFactory::getConfig();
     $packageFile = $joomlaConfig->get('tmp_path') . '/jsn-' . $this->template['id'] . '.zip';
     $templatePath = JPATH_ROOT . '/templates/' . $this->template['name'];
     $backupPath = $joomlaConfig->get('tmp_path') . '/' . $this->template['name'] . '_modified_files.zip';
     if (is_readable($packageFile)) {
         $modifiedFiles = JSNTplHelper::getModifiedFilesBeingUpdated($this->template['name'], $packageFile);
     } else {
         $modifiedFiles = JSNTplHelper::getModifiedFiles($this->template['name']);
         $modifiedFiles = array_merge($modifiedFiles['add'], $modifiedFiles['edit']);
     }
     // Check if backup was done before
     if (!$app->getUserState('jsn-tplfw-backup-done') or !is_file($backupPath)) {
         // Read all modified files
         foreach ($modifiedFiles as $file) {
             // Create array of file name and content for making archive later
             $files[] = array('name' => $file, 'data' => JFile::read("{$templatePath}/{$file}"));
         }
         // Create backup archive
         $archiver = new JSNTplArchiveZip();
         $archiver->create($backupPath, $files);
         // State that backup is created
         $app->setUserState('jsn-tplfw-backup-done', 1);
     }
     $this->setResponse($backupPath);
 }