示例#1
0
 protected function _run()
 {
     if ($this->getState() == 'postrun') {
         AliceUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Already finished");
         $this->setStep('');
         $this->setSubstep('');
         return;
     } else {
         $this->setState('running');
     }
     // Load the version defines
     AEPlatform::getInstance()->load_version_defines();
     $registry = AliceFactory::getConfiguration();
     // Write log file's header
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Alice Log Inspector and Correction of Errors " . AKEEBA_VERSION . ' (' . AKEEBA_DATE . ')');
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "What went wrong?");
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "--- System Information ---");
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "PHP Version        :" . PHP_VERSION);
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "PHP OS             :" . PHP_OS);
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "PHP SAPI           :" . PHP_SAPI);
     if (function_exists('php_uname')) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, "OS Version         :" . php_uname('s'));
     }
     if (isset($_SERVER['SERVER_SOFTWARE'])) {
         $server = $_SERVER['SERVER_SOFTWARE'];
     } elseif ($sf = getenv('SERVER_SOFTWARE')) {
         $server = $sf;
     } else {
         $server = 'n/a';
     }
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Web Server         :" . $server);
     $platformData = AEPlatform::getInstance()->getPlatformVersion();
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, $platformData['name'] . " version    :" . $platformData['version']);
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, "User agent         :" . phpversion() <= "4.2.1" ? getenv("HTTP_USER_AGENT") : $_SERVER['HTTP_USER_AGENT']);
     }
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Safe mode          :" . ini_get("safe_mode"));
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Display errors     :" . ini_get("display_errors"));
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Error reporting    :" . self::error2string());
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Error display      :" . self::errordisplay());
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Disabled functions :" . ini_get("disable_functions"));
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "open_basedir restr.:" . ini_get('open_basedir'));
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Max. exec. time    :" . ini_get("max_execution_time"));
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Memory limit       :" . ini_get("memory_limit"));
     if (function_exists("memory_get_usage")) {
         AliceUtilLogger::WriteLog(_AE_LOG_INFO, "Current mem. usage :" . memory_get_usage());
     }
     AliceUtilLogger::WriteLog(_AE_LOG_INFO, "--------------------------------------------------------------------------------");
     if (!version_compare(PHP_VERSION, '5.3.0', 'ge')) {
         AliceUtilLogger::WriteLog(_AE_LOG_WARNING, "You are using an outdated version of PHP. Akeeba Engine may not work properly. Please upgrade to PHP 5.3 or later.");
     }
     $this->setState('postrun');
 }
 protected function _run()
 {
     // Run in a loop until we run out of time, or breakflag is set
     $registry = AliceFactory::getConfiguration();
     $timer = AliceFactory::getTimer();
     // Let's check if I already have a stack coming from previous call
     $this->log = $registry->get('volatile.alice.logToAnalyze');
     $this->checks = $registry->get('volatile.alice.' . $this->checksName . '.checks', array());
     $this->totalChecks = $registry->get('volatile.alice.' . $this->checksName . '.totalChecks', 0);
     // No incoming stack, let's build it now
     if (!$this->checks) {
         $this->checks = AliceUtilScripting::getChecksStack($this->checksName);
         $this->totalChecks = count($this->checks);
     }
     while ($timer->getTimeLeft() > 0 && !$registry->get('volatile.breakflag', false) && count($this->checks)) {
         if ($this->getState() == 'postrun') {
             AliceUtilLogger::WriteLog(_AE_LOG_DEBUG, __CLASS__ . " :: Already finished");
             $this->setStep("-");
             $this->setSubstep("");
             break;
         } else {
             // Did I finished every check?
             if (!$this->checks) {
                 return;
             }
             $error = '';
             $solution = '';
             $className = array_shift($this->checks);
             $check = new $className($this->log);
             $this->setSubstep($check->getName());
             $this->progress = ($this->totalChecks - count($this->checks)) / $this->totalChecks;
             // Well, check, do your job!
             try {
                 $check->check();
             } catch (Exception $e) {
                 // Mhm... log didn't passed the check. Let's save the error and the suggested solution
                 $error = $e->getMessage();
                 $solution = $check->getSolution();
             }
             $result = $check->getResult();
             $feedback = $registry->get('volatile.alice.feedback', array());
             $feedback[] = array('check' => $check->getName(), 'result' => $result, 'error' => $error, 'solution' => $solution);
             $registry->set('volatile.alice.feedback', $feedback);
             unset($check);
         }
     }
     // Let's save everything
     $registry->set('volatile.alice.requirements.checks', $this->checks);
     $registry->set('volatile.alice.requirements.totalChecks', $this->totalChecks);
     $this->setState('postrun');
 }
 public function runAnalysis()
 {
     $ret_array = array();
     $ajaxTask = $this->getState('ajax');
     $log = $this->getState('log');
     switch ($ajaxTask) {
         case 'start':
             $tag = 'alice';
             AliceUtilLogger::WriteLog(true);
             AliceUtilLogger::WriteLog(_AE_LOG_INFO, 'Starting analysis');
             AliceCoreKettenrad::reset(array('maxrun' => 0));
             AliceUtilTempvars::reset($tag);
             $kettenrad = AliceCoreKettenrad::load($tag);
             $options = array('logToAnalyze' => AEUtilLogger::logName($log));
             $kettenrad->setup($options);
             $kettenrad->tick();
             if ($kettenrad->getState() != 'running') {
                 $kettenrad->tick();
             }
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             AliceCoreKettenrad::save($tag);
             break;
         case 'step':
             $tag = 'alice';
             $kettenrad = AliceCoreKettenrad::load($tag);
             $kettenrad->tick();
             $ret_array = $kettenrad->getStatusArray();
             $kettenrad->resetWarnings();
             // So as not to have duplicate warnings reports
             AliceCoreKettenrad::save($tag);
             if ($ret_array['HasRun'] == 1) {
                 // Let's get tests result
                 $config = AliceFactory::getConfiguration();
                 $feedback = $config->get('volatile.alice.feedback');
                 $ret_array['Results'] = json_encode($feedback);
                 // Clean up
                 AliceFactory::nuke();
                 AliceUtilTempvars::reset($tag);
             }
             break;
         default:
             break;
     }
     return $ret_array;
 }
示例#4
0
 /**
  * Returns an array with domain keys and domain class names for the current
  * analysis. The idea is that shifting this array walks through the analysis
  * process. When the array is empty, the analysis is done.
  *
  * @return array
  */
 public static function getDomainChain()
 {
     JLoader::import('joomla.filesystem.folder');
     $basepath = JPATH_ADMINISTRATOR . '/components/com_akeeba/alice/core/domain';
     $files = JFolder::files($basepath, '.php');
     $result = array();
     foreach ($files as $file) {
         if ($file == 'abstract.php') {
             continue;
         }
         $file = str_replace('.php', '', $file);
         $temp = AliceFactory::getDomainObject($file);
         $result[$temp->priority] = array('domain' => $file, 'class' => ucfirst($file), 'name' => $temp->getStepName());
         unset($temp);
     }
     // Sort domains by priority
     ksort($result);
     return $result;
 }
 /**
  * The public interface to an engine part. This method takes care for
  * calling the correct method in order to perform the initialisation -
  * run - finalisation cycle of operation and return a proper reponse array.
  *
  * @param   int     $nesting
  *
  * @return  array    A Reponse Array
  */
 public final function tick($nesting = 0)
 {
     $configuration = AliceFactory::getConfiguration();
     $timer = AliceFactory::getTimer();
     // Call the right action method, depending on engine part state
     switch ($this->getState()) {
         case "init":
             $this->_prepare();
             $breakFlag = $configuration->set('volatile.breakflag', false);
             break;
         case "prepared":
             $this->_run();
             break;
         case "running":
             $this->_run();
             break;
         case "postrun":
             $this->_finalize();
             $breakFlag = $configuration->set('volatile.breakflag', false);
             break;
     }
     // If there is still time, we are not finished and there is no break flag set, re-run the tick()
     // method.
     $breakFlag = $configuration->get('volatile.breakflag', false);
     if (!in_array($this->getState(), array('finished', 'error')) && $timer->getTimeLeft() > 0 && !$breakFlag && $nesting < 20 && $this->nest_logging) {
         // Nesting is only applied if $this->nest_logging == true (currently only Kettenrad has this)
         $nesting++;
         if ($this->nest_logging) {
             AliceUtilLogger::WriteLog(_AE_LOG_DEBUG, "*** Batching successive steps (nesting level {$nesting})");
         }
         $out = $this->tick($nesting);
     } else {
         // Return the output array
         $out = $this->_makeReturnTable();
         // Things to do for nest-logged parts (currently, only Kettenrad is)
         if ($this->nest_logging) {
             if ($breakFlag) {
                 AliceUtilLogger::WriteLog(_AE_LOG_DEBUG, "*** Engine steps batching: Break flag detected.");
             }
             // Reset the break flag
             $configuration->set('volatile.breakflag', false);
             // Log that we're breaking the step
             AliceUtilLogger::WriteLog(_AE_LOG_DEBUG, "*** Batching of engine steps finished. I will now return control to the caller.");
             // Enforce minimum execution time
             $timer = AliceFactory::getTimer();
             $timer->enforce_min_exec_time(true);
         }
     }
     // Send a Return Table back to the caller
     return $out;
 }
示例#6
0
 /**
  * Gets the percentage of the backup process done so far.
  *
  * @return string
  */
 public function getProgress()
 {
     // Get the overall percentage (based on domains complete so far)
     $remaining_steps = count($this->domain_chain);
     $remaining_steps++;
     $overall = 1 - $remaining_steps / $this->total_steps;
     // How much is this step worth?
     $this_max = 1 / $this->total_steps;
     // Get the percentage done of the current object
     if (!empty($this->class)) {
         $object = AliceFactory::getDomainObject($this->class);
     } else {
         $object = null;
     }
     if (!is_object($object)) {
         $local = 0;
     } else {
         $local = $object->getProgress();
     }
     $percentage = (int) (100 * ($overall + $local * $this_max));
     if ($percentage < 0) {
         $percentage = 0;
     }
     if ($percentage > 100) {
         $percentage = 100;
     }
     return $percentage;
 }