/** * 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); }
/** * Check files modification state based on checksum. * Files that are not being updated will be ignored. * * @return void */ public function checkBeforeUpdateAction() { $packageFile = JFactory::getConfig()->get('tmp_path') . '/jsn-' . $this->template['id'] . '.zip'; // Check if downloaded template package existen if (!is_readable($packageFile)) { throw new Exception(JText::_('JSN_TPLFW_ERROR_DOWNLOAD_PACKAGE_FILE_NOT_FOUND')); } // Get list of modified files that are being updated $modifiedFiles = JSNTplHelper::getModifiedFilesBeingUpdated($this->template['name'], $packageFile); $hasModification = count($modifiedFiles); // Backup modified files that are being updated if ($hasModification) { $integrity = new JSNTplWidgetIntegrity(); $integrity->backupAction(); } $this->setResponse(array('hasModification' => (bool) $hasModification)); }