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); } }
function __construct() { // Check auto-maintenance settings $aConf = $GLOBALS['_MAX']['CONF']; $this->isAutoMaintenanceEnabled = !empty($aConf['maintenance']['autoMaintenance']); // Get time 1 hour ago $oServiceLocator =& OA_ServiceLocator::instance(); $oNow = $oServiceLocator->get('now'); if ($oNow) { $oOneHourAgo = new Date($oNow); } else { $oOneHourAgo = new Date(); } $oOneHourAgo->subtractSpan(new Date_Span('0-1-0-0')); // Get last runs $oLastCronRun = OX_Maintenance::getLastScheduledRun(); $oLastRun = OX_Maintenance::getLastRun(); // Reset minutes and seconds if (isset($oLastCronRun)) { $oLastCronRun->setMinute(0); $oLastCronRun->setSecond(0); } if (isset($oLastRun)) { $oLastRun->setMinute(0); $oLastRun->setSecond(0); } // Check if any kind of maintenance was run if (isset($oLastCronRun) && !$oOneHourAgo->after($oLastCronRun)) { $this->isScheduledMaintenanceRunning = true; } elseif (isset($oLastRun) && !$oOneHourAgo->after($oLastRun)) { $this->isAutoMaintenanceRunning = true; } }
function testIsMidnightMaintenance() { unset($GLOBALS['serverTimezone']); $oNowDate = new Date('2008-01-28 00:00:10'); $oServiceLocator =& OA_ServiceLocator::instance(); $oServiceLocator->register('now', $oNowDate); $oMaintenance = new OX_Maintenance(); // No previous run $oLastRun = null; $this->assertTrue($oMaintenance->isMidnightMaintenance($oLastRun)); // Last run was 6 seconds ago, midnight did already pass $oLastRun = new Date('2008-01-28 00:00:04'); $this->assertFalse($oMaintenance->isMidnightMaintenance($oLastRun)); // Last run was one hour ago, midnight has passed $oLastRun = new Date('2008-01-27 23:00:04'); $this->assertTrue($oMaintenance->isMidnightMaintenance($oLastRun)); // Midnight did already pass in CET $GLOBALS['serverTimezone'] = 'CET'; $this->assertFalse($oMaintenance->isMidnightMaintenance($oLastRun)); // Not midnight yet in New York, last run was at 17PM local time $GLOBALS['serverTimezone'] = 'EST'; $oLastRun = new Date('2008-01-27 12:00:04'); $this->assertFalse($oMaintenance->isMidnightMaintenance($oLastRun)); }
/** * A script file to run the Maintenance Statistics Engine and the * Maintenance Priority Engine processes. * * @package OpenXMaintenance * @subpackage Tools */ // Set the current path // Done this way so that it works in CLI PHP $path = dirname(__FILE__); // Require the timezone class, and get the system timezone, // storing in a global variable global $serverTimezone; require_once $path . '/../../lib/OX/Admin/Timezones.php'; $serverTimezone = OX_Admin_Timezones::getTimezone(); // Require the initialisation file require_once $path . '/../../init.php'; // Set longer time out, and ignore user abort if (!ini_get('safe_mode')) { @set_time_limit($conf['maintenance']['timeLimitScripts']); @ignore_user_abort(true); } // Required files require_once RV_PATH . '/lib/RV.php'; require_once MAX_PATH . '/lib/Max.php'; require_once OX_PATH . '/lib/OX.php'; require_once LIB_PATH . '/Maintenance.php'; $oMaint = new OX_Maintenance(); $oMaint->run(); // Update scheduled maintenance last run record $oMaint->updateLastRun(true);