/** * 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 $runSync = false; if ($this->isMidnightMaintenance($oLastRun)) { $this->_runMidnightTasks(); $runSync = true; } // 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(); // Run the Revive Adserver Sync process, to get details of any updates // to Revive Adserver, if the process is due to be run (because the // "midnight" tasks were triggered); this happens as the very last // thing to ensure that network issues or timeouts with the sync server // don't affect the normal running of the MSE & MPE, which are important // to have run properly! if ($runSync) { $this->_runReviveSync(); } } else { OA::switchLogIdent('maintenance'); OA::debug('Maintenance Engine not run: could not acquire lock', PEAR_LOG_INFO); OA::switchLogIdent(); } }
/** * The method to run the Maintenance Statistics Engine process. * * @static */ function run() { OA::switchLogIdent('maintenance'); // Get the configuration $aConf = $GLOBALS['_MAX']['CONF']; // Log the start of the process OA::debug('Running Maintenance Statistics Engine', PEAR_LOG_INFO); // Set longer time out, and ignore user abort if (!ini_get('safe_mode')) { @set_time_limit($aConf['maintenance']['timeLimitScripts']); @ignore_user_abort(true); } // Run the following code as the "Maintenance" user OA_Permission::switchToSystemProcessUser('Maintenance'); // Ensure the the current time is registered with the OA_ServiceLocator $oServiceLocator =& OA_ServiceLocator::instance(); $oDate =& $oServiceLocator->get('now'); if (!$oDate) { // Record the current time, and register with the OA_ServiceLocator $oDate = new Date(); $oServiceLocator->register('now', $oDate); } $this->aComponents = OX_Component::getListOfRegisteredComponentsForHook('addMaintenanceStatisticsTask'); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $obj->beforeMse(); } } } // Initialise the task runner object, for storing/running the tasks $this->oTaskRunner = new OA_Task_Runner(); // Register this object as the controlling class for the process, // so that tasks run by the task runner can locate this class to // update the report, etc. $oServiceLocator =& OA_ServiceLocator::instance(); $oServiceLocator->register('Maintenance_Statistics_Controller', $this); // Create and register an instance of the OA_Dal_Maintenance_Statistics DAL // class for the following tasks to use if (!$oServiceLocator->get('OX_Dal_Maintenance_Statistics')) { $oFactory = new OX_Dal_Maintenance_Statistics_Factory(); $oDal = $oFactory->factory(); $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal); } // Add the task to set the update requirements $oSetUpdateRequirements = new OX_Maintenance_Statistics_Task_SetUpdateRequirements(); $this->oTaskRunner->addTask($oSetUpdateRequirements); // Add the task to migrate the bucket data into the statistics tables $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData(); $this->oTaskRunner->addTask($oSummariseIntermediate); // Add the task to handle the de-duplication and rejection of empty conversions $oDeDuplicateConversions = new OX_Maintenance_Statistics_Task_DeDuplicateConversions(); $this->oTaskRunner->addTask($oDeDuplicateConversions); // Add the task to handle the updating of "intermediate" statistics with // conversion information, as a legacy issue until all code obtains // conversion data from the standard conversion statistics tables $oManageConversions = new OX_Maintenance_Statistics_Task_ManageConversions(); $this->oTaskRunner->addTask($oManageConversions); // Add the task to summarise the intermediate statistics into final form $oSummariseFinal = new OX_Maintenance_Statistics_Task_SummariseFinal(); $this->oTaskRunner->addTask($oSummariseFinal); // Add the task to log the completion of the task $oLogCompletion = new OX_Maintenance_Statistics_Task_LogCompletion(); $this->oTaskRunner->addTask($oLogCompletion); // Add the task to manage (enable/disable) campaigns $oManageCampaigns = new OX_Maintenance_Statistics_Task_ManageCampaigns(); $this->oTaskRunner->addTask($oManageCampaigns); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $this->oTaskRunner->addTask($obj->addMaintenanceStatisticsTask(), $obj->getExistingClassName(), $obj->getOrder()); } } } // Run the MSE process tasks $this->oTaskRunner->runTasks(); // addMaintenanceStatisticsTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $obj->afterMse(); } } } // Return to the "normal" user OA_Permission::switchToSystemProcessUser(); // Log the end of the process OA::debug('Maintenance Statistics Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO); OA::switchLogIdent(); }
/** * The method to run the Maintenance Priority Engine process. * * @static * @param boolean $alwaysRun Default value is false. If true, the Maintenance * Priority Engine process will always run, even if * instant priority updates have been disabled in the * configuration. Used to ensure that the maintenance * script process can always update priorities. * @return boolean True on MPE running correctly, false otherwise. */ function run($alwaysRun = false) { OA::switchLogIdent('maintenance'); // Get the configuration $aConf = $GLOBALS['_MAX']['CONF']; // Should the MPE process run? if (!$alwaysRun) { // Is instant update for priority set? if (!$aConf['priority']['instantUpdate']) { OA::debug('Instant update of priorities disabled, not running MPE', PEAR_LOG_INFO); return false; } OA::debug(); } // Log the start of the process OA::debug('Running Maintenance Priority Engine', PEAR_LOG_INFO); // Set longer time out, and ignore user abort if (!ini_get('safe_mode')) { @set_time_limit($aConf['maintenance']['timeLimitScripts']); @ignore_user_abort(true); } // Attempt to increase PHP memory OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance')); // Run the following code as the "Maintenance" user OA_Permission::switchToSystemProcessUser('Maintenance'); // Create a Maintenance DAL object $oDal = new OA_Dal_Maintenance_Priority(); // Try to get the MPE database-level lock $lock = $oDal->obtainPriorityLock(); if (!$lock) { OA::debug('Unable to obtain database-level lock, not running MPE', PEAR_LOG_ERR); return false; } // Ensure the the current time is registered with the OA_ServiceLocator $oServiceLocator =& OA_ServiceLocator::instance(); $oDate =& $oServiceLocator->get('now'); if (!$oDate) { // Record the current time, and register with the OA_ServiceLocator $oDate = new Date(); $oServiceLocator->register('now', $oDate); } // Run the MPE process for the AdServer module require_once MAX_PATH . '/lib/OA/Maintenance/Priority/AdServer.php'; $oMaintenancePriority = new OA_Maintenance_Priority_AdServer(); // TODO: OA_Maintenance_Priority_AdServer::updatePriorities // should be refactored to return a boolean we can check here. $oMaintenancePriority->updatePriorities(); // Release the MPE database-level lock $result = $oDal->releasePriorityLock(); if (PEAR::isError($result)) { // Unable to continue! OA::debug('Unable to release database-level lock', PEAR_LOG_ERR); return false; } // Return to the "normal" user OA_Permission::switchToSystemProcessUser(); // Log the end of the process OA::debug('Maintenance Priority Engine Completed (Started at ' . $oDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oDate->tz->getShortName() . ')', PEAR_LOG_INFO); OA::switchLogIdent(); return true; }
function _switchToDefaultLog() { $this->pluginLogSwitchCounter--; if ($this->pluginLogSwitchCounter == 0) { OA::switchLogIdent(); } }
define('E_DEPRECATED', 0); } setupServerVariables(); setupDeliveryConfigVariables(); $conf = $GLOBALS['_MAX']['CONF']; // Set this script's identifier (from the config file) in the global scope $GLOBALS['_OA']['invocationType'] = array_search(basename($_SERVER['SCRIPT_FILENAME']), $conf['file']); // Disable all notices and warnings, // as some PAN code still generates PHP warnings in places if (!empty($conf['debug']['production'])) { error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING ^ E_DEPRECATED); } else { // show all errors when developing error_reporting(E_ALL ^ E_DEPRECATED); } require_once MAX_PATH . '/lib/max/Delivery/common.php'; require_once MAX_PATH . '/lib/max/Delivery/cache.php'; ###START_STRIP_DELIVERY require_once MAX_PATH . '/lib/OA.php'; OA::switchLogIdent('delivery'); ###END_STRIP_DELIVERY // Set the viewer's remote information used in logging and delivery limitation evaluation MAX_remotehostSetInfo(); // Set common delivery parameters in the global scope MAX_commonInitVariables(); // Load cookie data from client/plugin MAX_cookieLoad(); // Unpack the packed capping cookies MAX_cookieUnpackCapping(); // Run any plugins which have registered themselves at postInit OX_Delivery_Common_hook('postInit');