예제 #1
0
 function run()
 {
     // Make sure that the output is sent to the browser before
     // loading libraries and connecting to the db
     flush();
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Set longer time out, and ignore user abort
     if (!ini_get('safe_mode')) {
         @set_time_limit($aConf['maintenance']['timeLimitScripts']);
         @ignore_user_abort(true);
     }
     if (!defined('OA_VERSION')) {
         // If the code is executed inside delivery, the constants
         // need to be initialized
         require_once MAX_PATH . '/constants.php';
         setupConstants();
     }
     $oLock =& OA_DB_AdvisoryLock::factory();
     if ($oLock->get(OA_DB_ADVISORYLOCK_MAINTENANCE)) {
         OA::debug('Running Automatic Maintenance Task', PEAR_LOG_INFO);
         OA_Preferences::loadAdminAccountPreferences();
         require_once LIB_PATH . '/Maintenance.php';
         $oMaint = new OX_Maintenance();
         $oMaint->run();
         $oLock->release();
         OA::debug('Automatic Maintenance Task Completed', PEAR_LOG_INFO);
     } else {
         OA::debug('Automatic Maintenance Task not run: could not acquire lock', PEAR_LOG_INFO);
     }
 }
예제 #2
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();
     }
 }
예제 #3
0
 /**
  * Releases the database-level lock for the Maintenance Priority Engine process.
  *
  * @return mixed True if lock was released, a PEAR Error otherwise.
  */
 function releasePriorityLock()
 {
     if (empty($this->oLock)) {
         OA::debug('  - Lock wasn\'t acquired by the same DB connection', PEAR_LOG_ERR);
         return false;
     } elseif (!$this->oLock->hasSameId('mpe')) {
         OA::debug('  - Lock names to not match', PEAR_LOG_ERR);
         return false;
     }
     return $this->oLock->release();
 }
예제 #4
0
 /**
  * A method to run distributed maintenance.
  */
 function run()
 {
     if (empty($GLOBALS['_MAX']['CONF']['lb']['enabled'])) {
         OA::debug('Distributed stats disabled, not running Maintenance Distributed Engine', PEAR_LOG_INFO);
         return;
     }
     if (!empty($GLOBALS['_MAX']['CONF']['rawDatabase'])) {
         $GLOBALS['_MAX']['CONF']['database'] = $GLOBALS['_MAX']['CONF']['rawDatabase'] + $GLOBALS['_MAX']['CONF']['database'];
         OA::debug('rawDatabase functionality is being used, switching settings', PEAR_LOG_INFO);
     }
     $oLock =& OA_DB_AdvisoryLock::factory();
     if (!$oLock->get(OA_DB_ADVISORYLOCK_DISTRIBUTED)) {
         OA::debug('Maintenance Distributed Engine Already Running', PEAR_LOG_INFO);
         return;
     }
     OA::debug('Running Maintenance Distributed Engine', PEAR_LOG_INFO);
     // Attempt to increase PHP memory
     OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
     // Ensure the current time is registered with the OA_ServiceLocator
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oNow =& $oServiceLocator->get('now');
     if (!$oNow) {
         // Record the current time, and register with the OA_ServiceLocator
         $oNow = new Date();
         $oServiceLocator->register('now', $oNow);
     }
     OA::debug(' - Current time is ' . $oNow->format('%Y-%m-%d %H:%M:%S') . ' ' . $oNow->tz->getShortName(), PEAR_LOG_DEBUG);
     // Get the components of the deliveryLog extension
     $aBuckets = OX_Component::getComponents('deliveryLog');
     // Copy buckets' records with "interval_start" up to and including previous OI start,
     // and then prune the data processed
     $aPreviousOperationIntervalDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNow);
     OA::debug(' - Will process data for all operation intervals before and up to start', PEAR_LOG_DEBUG);
     OA::debug('   time of ' . $aPreviousOperationIntervalDates['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aPreviousOperationIntervalDates['start']->tz->getShortName(), PEAR_LOG_DEBUG);
     foreach ($aBuckets as $sBucketName => $oBucketClass) {
         if ($oBucketClass->testStatisticsMigration($oBucketClass->getStatisticsMigration())) {
             $oBucketClass->processBucket($aPreviousOperationIntervalDates['start']);
             $oBucketClass->pruneBucket($aPreviousOperationIntervalDates['start']);
         } else {
             OA::debug('  - Skipping ' . $sBucketName, PEAR_LOG_DEBUG);
         }
     }
     $oLock->release();
     OA::debug('Maintenance Distributed Engine Completed', PEAR_LOG_INFO);
 }
예제 #5
0
 /**
  * A factory method which returns the currently supported best advisory lock
  * instance.
  *
  * @return OA_DB_AdvisoryLock Reference to an OA_DB_AdvisoryLock object.
  */
 function &factory($sType = null)
 {
     if (is_null($sType)) {
         $oDbh =& OA_DB::singleton();
         if (PEAR::isError($oDbh)) {
             OA::debug('Error connecting to database to obtain locking object. Native error follows:', PEAR_LOG_ERR);
             OA::debug($oDbh, PEAR_LOG_ERR);
             OA::debug('Will re-try connection...', PEAR_LOG_ERR);
             $retryCount = 0;
             while (PEAR::isError($oDbh) && $retryCount < 6) {
                 $retryCount++;
                 sleep(10);
                 OA::debug('Re-try connection attempt #' . $retryCount, PEAR_LOG_ERR);
                 $oDbh =& OA_DB::singleton();
             }
             if (PEAR::isError($oDbh)) {
                 OA::debug('Failed in re-try attempts to connect to database. Aborting.', PEAR_LOG_CRIT);
                 exit;
             }
         }
         $aDsn = MDB2::parseDSN($oDbh->getDSN());
         $sType = $aDsn['phptype'];
     }
     include_once MAX_PATH . '/lib/OA/DB/AdvisoryLock/' . $sType . '.php';
     $sClass = "OA_DB_AdvisoryLock_" . $sType;
     $oLock = new $sClass();
     if (!$oLock->_isLockingSupported()) {
         // Fallback to file based locking if the current class won't work
         $oLock =& OA_DB_AdvisoryLock::factory('file');
     }
     return $oLock;
 }