public function check() { $handle = @fopen($this->logFile, 'r'); $error = false; if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } while (($line = fgets($handle)) !== false) { $pos = strpos($line, '|Loaded profile'); if ($pos !== false) { // Ok, I just passed the "Loaded profile" line, let's see if it's a broken install $line = fgets($handle); $logline = trim(substr($line, 24)); // Empty line?? Most likely it's a broken install if ($logline == '|') { $error = true; } break; } } fclose($handle); if ($error) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . " Test error, most likely this installation is broken"); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_RUNTIME_ERRORS_CORRUPTED_INSTALL_ERROR')); } AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . " Test passed, installation seems ok."); return true; }
public function check() { $db = AEFactory::getDatabase(); // Can I execute SHOW statements? try { $result = $db->setQuery('SHOW TABLES')->query(); } catch (Exception $e) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW TABLES statement"); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR')); } if (!$result) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW TABLES statement"); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR')); } try { $result = $db->setQuery('SHOW CREATE TABLE ' . $db->nameQuote('#__ak_profiles'))->query(); } catch (Exception $e) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW CREATE TABLE statement"); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR')); } if (!$result) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . " Test failed, can't execute SHOW CREATE TABLE statement"); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_REQUIREMENTS_DBPERMISSIONS_ERROR')); } return true; }
public function check() { $handle = @fopen($this->logFile, 'r'); if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } $prev_data = ''; $buffer = 65536; $tables = array(); $ex_tables = array(); while (!feof($handle)) { $data = $prev_data . fread($handle, $buffer); // Let's find the last occurrence of a new line $newLine = strrpos($data, "\n"); // I didn't hit any EOL char, let's keep reading if ($newLine === false) { $prev_data = $data; continue; } else { // Gotcha! Let's roll back to its position $prev_data = ''; $rollback = strlen($data) - $newLine + 1; $len = strlen($data); $data = substr($data, 0, $newLine); // I have to rollback only if I read the whole buffer (ie I'm not at the end of the file) // Using this trick should be much more faster than calling ftell to know where we are if ($len == $buffer) { fseek($handle, -$rollback, SEEK_CUR); } } // Let's save every scanned table preg_match_all('#AEDumpNativeMysql :: Adding.*?\\(internal name (.*?)\\)#i', $data, $matches); if (isset($matches[1])) { $tables = array_merge($tables, $matches[1]); } } fclose($handle); // Let's loop on saved tables and look at their prefixes foreach ($tables as $table) { preg_match('/^(.*?_)/', $table, $matches); if ($matches[1] !== '#_' && !in_array($matches[1], $ex_tables)) { $ex_tables[] = $matches[1]; } } if (count($ex_tables)) { if (count($ex_tables) > 0 && count($ex_tables) <= 3) { $this->setResult(0); } else { $this->setResult(-1); } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, user is trying to backup ' . count($ex_tables) . ' different databases at once.'); throw new Exception(JText::_('ALICE_ANALYZE_RUNTIME_ERRORS_TOOMUCHDBS_ERROR')); } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed, there are no issues while creating the backup archive '); return true; }
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 check() { // Customer is not on windows, this problem happened on Windows only if (!$this->isWin()) { return true; } $handle = @fopen($this->logFile, 'r'); if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } $prev_data = ''; $buffer = 65536; $error = false; while (!feof($handle)) { $data = $prev_data . fread($handle, $buffer); // Let's find the last occurrence of a new line $newLine = strrpos($data, "\n"); // I didn't hit any EOL char, let's keep reading if ($newLine === false) { $prev_data = $data; continue; } else { // Gotcha! Let's roll back to its position $prev_data = ''; $rollback = strlen($data) - $newLine + 1; $len = strlen($data); $data = substr($data, 0, $newLine); // I have to rollback only if I read the whole buffer (ie I'm not at the end of the file) // Using this trick should be much more faster than calling ftell to know where we are if ($len == $buffer) { fseek($handle, -$rollback, SEEK_CUR); } } if (preg_match('#Could not open archive file.*? for append#i', $data, $tmp_matches) !== false) { $error = true; } } fclose($handle); if ($error) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, could not open backup file for append'); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_RUNTIME_ERRORS_WINCANTAPPEND_ERROR')); } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed, there are no issues while creating the backup archive '); return true; }
public function check() { $handle = @fopen($this->logFile, 'r'); $limit = false; $usage = false; if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } // Memory information is on a single line and it is at the beginning, so I can start reading one line at time while (($line = fgets($handle)) !== false) { if (!$limit) { $pos = strpos($line, '|Memory limit'); if ($pos !== false) { $limit = trim(substr($line, strpos($line, ':', $pos) + 1)); $limit = str_ireplace('M', '', $limit); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected memory limit: ' . $limit); } } if (!$usage) { $pos = strpos($line, '|Current mem. usage'); if ($pos !== false) { $usage = trim(substr($line, strpos($line, ':', $pos) + 1)); // Converting to Mb for better handling $usage = round($usage / 1024 / 1024, 2); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected memory usage: ' . $usage); } } if ($limit && $usage) { break; } } fclose($handle); if ($limit && $usage) { $available = $limit - $usage; if ($available >= 16) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed, detected available memory: ' . $available); } else { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, detected available memory: ' . $available); $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_MEMORY_TOO_FEW', $available)); } } else { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . " Test error, couldn't detect available memory."); } return true; }
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; }
public function check() { $handle = @fopen($this->logFile, 'r'); $found = false; if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } // PHP information is on a single line, so I can start reading one line at time while (($line = fgets($handle)) !== false) { $pos = strpos($line, '|PHP Version'); if ($pos !== false) { $found = true; $version = trim(substr($line, strpos($line, ':', $pos) + 1)); // PHP too old (well, this should never happen) if (version_compare($version, '5.3', 'lt')) { fclose($handle); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, detected version: ' . $version); $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_PHP_VERSION_ERR_TOO_NEW', $version)); } /* elseif(version_compare($version, '5.5', 'ge')) { fclose($handle); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName.' Test failed, detected version: '.$version); $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_PHP_VERSION_ERR_TOO_OLD', $version)); } */ break; } } if ($found) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed, detected version: ' . $version); } else { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . " Test error, couldn't detect PHP version."); } fclose($handle); return true; }
public function check() { // Instead of reading the log, I can simply take the JDatabase object and test it $connector = JFactory::getDbo()->name; $version = JFactory::getDbo()->getVersion(); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected database connector: ' . $connector); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected database version: ' . $version); if ($connector == 'mysql' || $connector == 'mysqli') { if (version_compare($version, '5.0.47', 'lt')) { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_VERSION_TOO_OLD', $version)); } } elseif ($connector == 'oracle') { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_UNSUPPORTED', 'SqlAzure')); } elseif ($connector == 'pdo') { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_UNSUPPORTED', 'PDO')); } elseif ($connector == 'postgresql') { if (version_compare($version, '8.3.18', 'lt')) { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_VERSION_TOO_OLD', $version)); } } elseif ($connector == 'sqlsrv' || $connector == 'sqlzure') { if (version_compare($version, '10.50.1600.1', 'lt')) { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_VERSION_TOO_OLD', $version)); } } elseif ($connector == 'sqlite') { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_UNSUPPORTED', 'SQLite')); } else { // Unknown database type, throw exception $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_REQUIREMENTS_DATABASE_UNKNOWN')); } return true; }
public static function openLog($tag = null) { self::$logName = self::logName($tag); @touch(self::$logName); }
public function check() { $handle = @fopen($this->logFile, 'r'); if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } $prev_data = ''; $buffer = 65536; $starting = array(); $saving = array(); while (!feof($handle)) { $data = $prev_data . fread($handle, $buffer); // Let's find the last occurrence of a new line $newLine = strrpos($data, "\n"); // I didn't hit any EOL char, let's keep reading if ($newLine === false) { $prev_data = $data; continue; } else { // Gotcha! Let's roll back to its position $prev_data = ''; $rollback = strlen($data) - $newLine + 1; $len = strlen($data); $data = substr($data, 0, $newLine); // I have to rollback only if I read the whole buffer (ie I'm not at the end of the file) // Using this trick should be much more faster than calling ftell to know where we are if ($len == $buffer) { fseek($handle, -$rollback, SEEK_CUR); } } preg_match_all('#Starting Step number (\\d+)#i', $data, $tmp_matches); if (isset($tmp_matches[1])) { $starting = array_merge($starting, $tmp_matches[1]); } preg_match_all('#Saving Kettenrad instance#i', $data, $tmp_matches); if (isset($tmp_matches[0])) { $saving = array_merge($saving, $tmp_matches[0]); } } fclose($handle); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected starting steps: ' . count($starting)); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected saving steps: ' . count($saving)); // Check that the number of "Starting step" and "Saving kettenrad" is the same if (count($starting) != count($saving)) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed : ' . count($starting) . ' starting vs ' . count($saving) . ' savings'); $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_RUNTIME_ERRORS_KETTENRAD_SAVING_DIFFERS', count($starting), count($saving))); } // Plus, check that none of "Starting step" number is repeated, EXCEPT for the first one (it's ok) foreach ($starting as $stepNumber) { if ($stepNumber == 1) { continue; } if (count(array_keys($starting, $stepNumber)) > 1) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, step ' . $stepNumber . ' ran more once'); $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_RUNTIME_ERRORS_KETTENRAD_STARTING_MORE_ONCE', $stepNumber)); } } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed : ' . count($starting) . ' starting vs ' . count($saving) . ' savings'); return true; }
public function check() { $handle = @fopen($this->logFile, 'r'); if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } $prev_data = ''; $buffer = 65536; $bigfiles = array(); while (!feof($handle)) { $data = $prev_data . fread($handle, $buffer); // Let's find the last occurrence of a new line $newLine = strrpos($data, "\n"); // I didn't hit any EOL char, let's keep reading if ($newLine === false) { $prev_data = $data; continue; } else { // Gotcha! Let's roll back to its position $prev_data = ''; $rollback = strlen($data) - $newLine + 1; $len = strlen($data); $data = substr($data, 0, $newLine); // I have to rollback only if I read the whole buffer (ie I'm not at the end of the file) // Using this trick should be much more faster than calling ftell to know where we are if ($len == $buffer) { fseek($handle, -$rollback, SEEK_CUR); } } preg_match_all('#(_before_|\\*after\\*) large file: (<root>.*?) \\- size: (\\d+)#i', $data, $tmp_matches); // Record valid matches only (ie with a filesize) if (isset($tmp_matches[3]) && $tmp_matches[3]) { for ($i = 0; $i < count($tmp_matches[2]); $i++) { // Get flagged files only once; I could have a breaking step after, before or BOTH a large file $key = md5($tmp_matches[2][$i]); if (!isset($bigfiles[$key])) { $bigfiles[$key] = array('filename' => $tmp_matches[2][$i], 'size' => round($tmp_matches[3][$i] / 1024 / 1024, 2)); } } } } fclose($handle); // Let's log all the results foreach ($bigfiles as $file) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Large file detected, position: ' . $file['filename'] . ' size: ' . $file['size'] . ' Mb'); } $badfiles = array(); // Now let's throw Exceptions if something is wrong foreach ($bigfiles as $file) { $badfiles[] = $file; // More than 10 Mb? Always set the result to error, no matter what if ($file['size'] >= 10) { $this->setResult(-1); } elseif ($file['size'] > 2 && $file['size'] < 10 && $this->getResult() >= 0) { $this->setResult(0); } } if ($badfiles) { $errorMsg = array(); foreach ($badfiles as $bad) { $errorMsg[] = 'File: ' . $bad['filename'] . ' ' . $bad['size'] . ' Mb'; } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test failed, found the following bad files:' . "\n" . implode("\n", $errorMsg)); throw new Exception(JText::sprintf('ALICE_ANALIZE_FILESYSTEM_LARGE_FILES_ERROR', '<br/>' . implode('<br/>', $errorMsg))); } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed, no large files issue detected.'); return true; }
/** * 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; }
public function check() { $handle = @fopen($this->logFile, 'r'); if ($handle === false) { AliceUtilLogger::WriteLog(_AE_LOG_ERROR, $this->checkName . ' Test error, could not open backup log file.'); return false; } $prev_data = ''; $buffer = 65536; $starting = array(); $saving = array(); while (!feof($handle)) { $data = $prev_data . fread($handle, $buffer); // Let's find the last occurrence of a new line $newLine = strrpos($data, "\n"); // I didn't hit any EOL char, let's keep reading if ($newLine === false) { $prev_data = $data; continue; } else { // Gotcha! Let's roll back to its position $prev_data = ''; $rollback = strlen($data) - $newLine + 1; $len = strlen($data); $data = substr($data, 0, $newLine); // I have to rollback only if I read the whole buffer (ie I'm not at the end of the file) // Using this trick should be much more faster than calling ftell to know where we are if ($len == $buffer) { fseek($handle, -$rollback, SEEK_CUR); } } preg_match_all('#(\\d{6}\\s\\d{2}:\\d{2}:\\d{2})\\|.*?Starting Step number#i', $data, $tmp_matches); if (isset($tmp_matches[1])) { $starting = array_merge($starting, $tmp_matches[1]); } preg_match_all('#(\\d{6}\\s\\d{2}:\\d{2}:\\d{2})\\|.*?Saving Kettenrad instance#i', $data, $tmp_matches); if (isset($tmp_matches[1])) { $saving = array_merge($saving, $tmp_matches[1]); } } fclose($handle); // If there is an issue with starting and saving instances, I can't go on, first of all fix that if (count($saving) != count($starting)) { AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Could not proceed, starting and saving steps are different.'); $this->setResult(-1); throw new Exception(JText::_('ALICE_ANALYZE_RUNTIME_ERRORS_TIMEOUT_KETTENRAD_BROKEN')); } $temp = array(); // Let's expand the date part so I can safely work with that strings foreach ($starting as $item) { $temp[] = '20' . substr($item, 0, 2) . '-' . substr($item, 2, 2) . '-' . substr($item, 4, 2) . substr($item, 6); } $starting = $temp; $temp = array(); // Let's expand the date part so I can safely work with that strings foreach ($saving as $item) { $temp[] = '20' . substr($item, 0, 2) . '-' . substr($item, 2, 2) . '-' . substr($item, 4, 2) . substr($item, 6); } $saving = $temp; $maxExcution = $this->detectMaxExec(); // Ok, did I had any timeout between the start and saving step (ie page loads)? for ($i = 0; $i < count($starting); $i++) { $duration = strtotime($saving[$i]) - strtotime($starting[$i]); AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Detected page running time: ' . $duration . ' seconds'); if ($duration > $maxExcution) { $this->setResult(-1); throw new Exception(JText::sprintf('ALICE_ANALYZE_RUNTIME_ERRORS_TIMEOUT_MAX_EXECUTION', $duration)); } } AliceUtilLogger::WriteLog(_AE_LOG_INFO, $this->checkName . ' Test passed : ' . count($starting) . ' starting vs ' . count($saving) . ' savings'); return true; }
/** * Resets the Kettenrad state, wipping out any pending backups and/or stale * temporary data. * @param array $config Configuration parameters for the reset operation */ public static function reset($config = array()) { $default_config = array('log' => false, 'maxrun' => 0); $config = (object) array_merge($default_config, $config); // Pause logging if so desired AliceUtilLogger::WriteLog(_AE_LOG_INFO, 'Resetting Kettenrad instance'); if (!$config->log) { AliceUtilLogger::WriteLog(false, ''); } // Cache the factory before proceeding $factory = AliceFactory::serialize(); // @todo Here should happen all reset logic when we start another analysis // Reload the factory AliceFactory::unserialize($factory); unset($factory); // Unpause logging if it was previously paused if (!$config->log) { AliceUtilLogger::WriteLog(true, ''); } AliceUtilLogger::WriteLog(_AE_LOG_INFO, 'Done resetting Kettenrad instance'); }