예제 #1
0
 /**
  * Checks the archive's data integrity by performing a dry-run extraction (no data is written to disk, just making
  * sure the archive can be extracted). If you have enabled "Upload archive part immediately" this won't run and
  * produce a warning instead.
  *
  * @param   Finalization  $parent
  *
  * @return  bool  True when done or an error occurred
  */
 public function test_extract($parent)
 {
     // If for any reason we're called outside the Finalization context let's give up without a fight
     if (!$parent instanceof Finalization) {
         return true;
     }
     // Load the configuration engine
     $config = Factory::getConfiguration();
     // Only run if we're explicitly enabled
     $enabled = $config->get('akeeba.advanced.integritycheck', 0);
     if (!$enabled) {
         return true;
     }
     // Make sure the "Process each part immediately" option is not enabled
     if ($config->get('engine.postproc.common.after_part', 0, false)) {
         $parent->setWarning(JText::_('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_PROCESSIMMEDIATELY'));
         return true;
     }
     // Make sure an archiver engine producing backup archives of JPA, JPS or ZIP files is in use
     $archiver = Factory::getArchiverEngine();
     $extension = $archiver->getExtension();
     $extension = strtoupper($extension);
     $extension = ltrim($extension, '.');
     if (!in_array($extension, array('JPA', 'JPS', 'ZIP'))) {
         $parent->setWarning(JText::_('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_INVALIDARCHIVERTYPE'));
         return true;
     }
     // Set the KICKSTART constant to prevent Akeeba Restore from taking over the page output
     if (!defined('KICKSTART')) {
         define('KICKSTART', 1);
     }
     // Try to load Akeeba Restore
     try {
         $this->loadAkeebaRestore();
     } catch (\RuntimeException $e) {
         $parent->setError($e->getMessage());
         return true;
     }
     // Set up the Akeeba Restore engine, either from a serialised factory or from scratch
     $factory = $config->get('volatile.finalization.testextract.factory', null, false);
     if (!is_null($factory) && is_string($factory)) {
         \AKFactory::unserialize($factory);
     } else {
         $this->setUpAkeebaRestore();
     }
     $parent->relayStep('Archive integrity check');
     $parent->relaySubstep('Testing if archive can be extracted');
     \AKFactory::set('kickstart.enabled', true);
     /** @var \AKAbstractUnarchiver $engine */
     $engine = \AKFactory::getUnarchiver();
     $observer = new FakeRestorationObserver();
     $engine->attach($observer);
     $engine->tick();
     $ret = $engine->getStatusArray();
     // Did an error occur?
     if ($ret['Error'] != '') {
         $parent->setError(JText::sprintf('COM_AKEEBA_ENGINE_TEXTEXTRACT_ERR_INTEGRITYCHECKFAILED', $ret['Error']));
         return true;
     }
     // Did we finish successfully?
     if (!$ret['HasRun']) {
         Factory::getLog()->log(LogLevel::INFO, __CLASS__ . ": The archive's integrity has been validated");
         $config->set('volatile.finalization.testextract.factory', null, false);
         return true;
     }
     // Step finished and we need one more step to proceed.
     $factory = \AKFactory::serialize();
     $config->set('volatile.finalization.testextract.factory', $factory, false);
     return false;
 }
예제 #2
0
         $retArray['status'] = false;
         $retArray['done'] = true;
         $retArray['message'] = $ret['Error'];
     } elseif (!$ret['HasRun']) {
         $retArray['files'] = $observer->filesProcessed;
         $retArray['bytesIn'] = $observer->compressedTotal;
         $retArray['bytesOut'] = $observer->uncompressedTotal;
         $retArray['status'] = true;
         $retArray['done'] = true;
     } else {
         $retArray['files'] = $observer->filesProcessed;
         $retArray['bytesIn'] = $observer->compressedTotal;
         $retArray['bytesOut'] = $observer->uncompressedTotal;
         $retArray['status'] = true;
         $retArray['done'] = false;
         $retArray['factory'] = AKFactory::serialize();
     }
     break;
 case 'finalizeRestore':
     $root = AKFactory::get('kickstart.setup.destdir');
     // Remove the installation directory
     recursive_remove_directory($root . '/installation');
     $postproc = AKFactory::getPostProc();
     // Rename htaccess.bak to .htaccess
     if (file_exists($root . '/htaccess.bak')) {
         if (file_exists($root . '/.htaccess')) {
             $postproc->unlink($root . '/.htaccess');
         }
         $postproc->rename($root . '/htaccess.bak', $root . '/.htaccess');
     }
     // Remove restoration.php
예제 #3
0
 function doAjax()
 {
     $ajax = $this->getState('ajax');
     switch ($ajax) {
         // FTP Connection test for DirectFTP
         case 'testftp':
             // Grab request parameters
             $config = array('host' => $this->input->get('host', '', 'none', 2), 'port' => $this->input->get('port', 21, 'int'), 'user' => $this->input->get('user', '', 'none', 2), 'pass' => $this->input->get('pass', '', 'none', 2), 'initdir' => $this->input->get('initdir', '', 'none', 2), 'usessl' => $this->input->get('usessl', 'cmd') == 'true', 'passive' => $this->input->get('passive', 'cmd') == 'true');
             // Perform the FTP connection test
             $test = new AEArchiverDirectftp();
             $test->initialize('', $config);
             $errors = $test->getError();
             if (empty($errors)) {
                 $result = true;
             } else {
                 $result = $errors;
             }
             break;
         case 'restoreFilesPing':
         case 'restoreFilesStart':
         case 'restoreFilesStep':
         case 'restoreFilesFinalize':
             global $restoration_setup;
             $restoration_setup = $this->getRestorationParameters();
             define('KICKSTART', 1);
             include_once JPATH_COMPONENT_ADMINISTRATOR . '/restore.php';
             akeebaTinyHackForRestorationObserver();
             masterSetup();
             $retArray = array('status' => true, 'message' => null);
             switch ($ajax) {
                 case 'restoreFilesPing':
                     // ping task - realy does nothing!
                     $timer = AKFactory::getTimer();
                     $timer->enforce_min_exec_time();
                     break;
                 case 'restoreFilesStart':
                     AKFactory::nuke();
                     // Reset the factory
                 // Reset the factory
                 case 'restoreFilesStep':
                     $config = JFactory::getConfig();
                     if (version_compare(JVERSION, '3.0', 'ge')) {
                         $tmp_path = $config->get('tmp_path', '');
                     } else {
                         $tmp_path = $config->getValue('tmp_path', '');
                     }
                     $override = array('rename_dirs' => array('sql' => rtrim($tmp_path, '/\\') . '/sql'));
                     $engine = AKFactory::getUnarchiver($override);
                     // Get the engine
                     $observer = new RestorationObserver();
                     // Create a new observer
                     $engine->attach($observer);
                     // Attach the observer
                     $engine->tick();
                     $ret = $engine->getStatusArray();
                     if ($ret['Error'] != '') {
                         $retArray['status'] = false;
                         $retArray['done'] = true;
                         $retArray['message'] = $ret['Error'];
                     } elseif (!$ret['HasRun']) {
                         $retArray['files'] = $observer->filesProcessed;
                         $retArray['bytesIn'] = $observer->compressedTotal;
                         $retArray['bytesOut'] = $observer->uncompressedTotal;
                         $retArray['status'] = true;
                         $retArray['done'] = true;
                     } else {
                         $retArray['files'] = $observer->filesProcessed;
                         $retArray['bytesIn'] = $observer->compressedTotal;
                         $retArray['bytesOut'] = $observer->uncompressedTotal;
                         $retArray['status'] = true;
                         $retArray['done'] = false;
                         $retArray['factory'] = AKFactory::serialize();
                     }
                     break;
                 case 'restoreFilesFinalize':
                     $root = AKFactory::get('kickstart.setup.destdir');
                     // Remove the sql dump directory
                     $config = JFactory::getConfig();
                     if (version_compare(JVERSION, '3.0', 'ge')) {
                         $tmp_path = $config->get('tmp_path', '');
                     } else {
                         $tmp_path = $config->getValue('tmp_path', '');
                     }
                     $sqldir = rtrim($tmp_path, '/\\') . '/sql';
                     recursive_remove_directory($sqldir);
                     break;
             }
             return $retArray;
             break;
         case 'dbRestoreStart':
             $this->dbRestorationInit();
         case 'dbRestore':
             $result = $this->dbRestore();
             break;
             // Unrecognized AJAX task
         // Unrecognized AJAX task
         default:
             $result = false;
             break;
     }
     return $result;
 }