Exemplo n.º 1
0
 /**
  * A method to run maintenance.
  */
 function run()
 {
     // Print a blank line in the debug log file when maintenance starts
     OA::debug();
     // Do not run if distributed stats are enabled
     if (!empty($this->aConf['lb']['enabled'])) {
         OA::debug('Distributed stats enabled, not running maintenance tasks', PEAR_LOG_INFO);
         return;
     }
     // Acquire the maintenance lock
     $oLock =& OA_DB_AdvisoryLock::factory();
     if ($oLock->get(OA_DB_ADVISORYLOCK_MAINTENANCE)) {
         OA::switchLogIdent('maintenance');
         OA::debug();
         OA::debug('Running Maintenance Engine', PEAR_LOG_INFO);
         // Attempt to increase PHP memory
         OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
         // Set UTC timezone
         OA_setTimeZoneUTC();
         // Get last run
         $oLastRun = $this->getLastRun();
         // Update the timestamp for old maintenance code and auto-maintenance
         $this->updateLastRun();
         // Record the current time, and register with the OA_ServiceLocator
         $oDate = new Date();
         $oServiceLocator =& OA_ServiceLocator::instance();
         $oServiceLocator->register('now', $oDate);
         // Check the operation interval is valid
         $result = OX_OperationInterval::checkOperationIntervalValue($this->aConf['maintenance']['operationInterval']);
         if (PEAR::isError($result)) {
             // Unable to continue!
             $oLock->release();
             OA::debug('Aborting maintenance: Invalid Operation Interval length', PEAR_LOG_CRIT);
             exit;
         }
         // Run the Maintenance Statistics Engine (MSE) process
         $this->_runMSE();
         // Run the "midnight" tasks, if required
         if ($this->isMidnightMaintenance($oLastRun)) {
             $this->_runMidnightTasks();
         }
         // Release lock before starting MPE
         $oLock->release();
         // Run the Maintenance Priority Engine (MPE) process, ensuring that the
         // process always runs, even if instant update of priorities is disabled
         $this->_runMPE();
         // Log the completion of the entire ME process
         OA::switchLogIdent('maintenance');
         $oEndDate = new Date();
         $oDateSpan = new Date_Span();
         $oDateSpan->setFromDateDiff($oDate, $oEndDate);
         OA::debug('Maintenance Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ', taking ' . $oDateSpan->format('%H:%M:%S') . ')', PEAR_LOG_INFO);
         OA::switchLogIdent();
     } else {
         OA::switchLogIdent('maintenance');
         OA::debug('Maintenance Engine not run: could not acquire lock', PEAR_LOG_INFO);
         OA::switchLogIdent();
     }
 }
 /**
  * A method to test the checkOperationIntervalValue() method.
  *
  */
 function testCheckOperationIntervalValue()
 {
     OA::disableErrorHandling();
     for ($i = -1; $i <= 61; $i++) {
         $result = OX_OperationInterval::checkOperationIntervalValue($i);
         if ($i == 1 || $i == 2 || $i == 3 || $i == 4 || $i == 5 || $i == 6 || $i == 10 || $i == 12 || $i == 15 || $i == 20 || $i == 30 || $i == 60) {
             $this->assertTrue($result);
         } else {
             $this->assertTrue(PEAR::isError($result));
         }
         $result = OX_OperationInterval::checkOperationIntervalValue(120);
         $this->assertTrue(PEAR::isError($result));
     }
     OA::enableErrorHandling();
 }
Exemplo n.º 3
0
require_once OX_PATH . '/lib/pear/Date.php';
// Standard messages
$haltMessage = "\nThe {$scriptName} script will NOT be run.\n\n";
if ($argc !== 2) {
    echo "\nRequires the hostname to be passed in as a string, as per the standard maintenance CLI script.\n";
    echo $haltMessage;
    exit;
}
if (!defined('INTERVAL_START') || !defined('INTERVAL_END')) {
    echo "\nPlease ensure that you have read the comments in the {$scriptName} script.\n\nYou will also find out how to make this script work by reading the comments. :-)\n";
    echo $haltMessage;
    exit;
}
// Initialise the script
RV::disableErrorHandling();
$result = OX_OperationInterval::checkOperationIntervalValue(OX_OperationInterval::getOperationInterval());
RV::enableErrorHandling();
if (PEAR::isError($result)) {
    $message = "\nThe operation interval in your OpenX configuration file is not valid. Please see the OpenX\ndocumentation for more details on valid operation interval values.\n";
    echo $message;
    echo $haltMessage;
    exit;
}
$oStartDate = new Date(INTERVAL_START);
$result = OX_OperationInterval::checkDateIsStartDate($oStartDate);
if (!$result) {
    $message = "\nThe start date defined in the {$scriptName} script is not a valid operation interval start date.\nPlease edit the statisticsTestAndCorrect.php script before running.\n";
    echo $message;
    echo $haltMessage;
    exit;
}