/** * The method to run the Maintenance Priority process. * * @return boolean True if the MPE ran correctly, false otherwise. */ function updatePriorities() { // Run the required tasks // TODO: OA_Task::run should really return a boolean we could check here. $this->oTaskRunner->runTasks(); // addMaintenancePriorityTask hook if (!empty($this->aComponents) && is_array($this->aComponents)) { foreach ($this->aComponents as $componentId) { if ($obj = OX_Component::factoryByComponentIdentifier($componentId)) { $obj->afterMpe(); } } } }
/** * 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(); }
/** * A method to test addition of tasks to the task runner. */ function testAddTask() { // Generate a partial mock of the task class Mock::generatePartial('OA_Task', 'MockTask0', array('run')); $oTask0 = new MockTask0($this); Mock::generatePartial('OA_Task', 'MockTask1', array('run')); $oTask1 = new MockTask1($this); Mock::generatePartial('OA_Task', 'MockTask2', array('run')); $oTask2 = new MockTask2($this); Mock::generatePartial('OA_Task', 'MockTask3', array('run')); $oTask3 = new MockTask3($this); Mock::generatePartial('OA_Task', 'MockTask4', array('run')); $oTask4 = new MockTask4($this); // Create a task runner, and test addition of classes $oTaskRunner = new OA_Task_Runner(); $this->assertEqual(count($oTaskRunner->aTasks), 0); $return = $oTaskRunner->addTask('foo'); $this->assertFalse($return); $this->assertEqual(count($oTaskRunner->aTasks), 0); $return = $oTaskRunner->addTask($oTask0); $this->assertTrue($return); $this->assertEqual(count($oTaskRunner->aTasks), 1); $oTask = $oTaskRunner->aTasks[0]; $this->assertIsA($oTask, 'MockTask0'); $return = $oTaskRunner->addTask($oTask1); $this->assertTrue($return); $this->assertEqual(count($oTaskRunner->aTasks), 2); $oTask = $oTaskRunner->aTasks[0]; $this->assertIsA($oTask, 'MockTask0'); $oTask = $oTaskRunner->aTasks[1]; $this->assertIsA($oTask, 'MockTask1'); // Add after task $return = $oTaskRunner->addTask($oTask2, 'MockTask0', OA_Task_Runner::TASK_ORDER_AFTER); $this->assertTrue($return); $this->assertEqual(count($oTaskRunner->aTasks), 3); $oTask = $oTaskRunner->aTasks[0]; $this->assertIsA($oTask, 'MockTask0'); $oTask = $oTaskRunner->aTasks[1]; $this->assertIsA($oTask, 'MockTask2'); $oTask = $oTaskRunner->aTasks[2]; $this->assertIsA($oTask, 'MockTask1'); $return = $oTaskRunner->addTask($oTask2, 'InvalidClassName', OA_Task_Runner::TASK_ORDER_AFTER); $this->assertFalse($return); // Replace task $return = $oTaskRunner->addTask($oTask3, 'MockTask2', OA_Task_Runner::TASK_ORDER_REPLACE); $this->assertTrue($return); $this->assertEqual(count($oTaskRunner->aTasks), 3); $oTask = $oTaskRunner->aTasks[0]; $this->assertIsA($oTask, 'MockTask0'); $oTask = $oTaskRunner->aTasks[1]; $this->assertIsA($oTask, 'MockTask3'); $oTask = $oTaskRunner->aTasks[2]; $this->assertIsA($oTask, 'MockTask1'); $return = $oTaskRunner->addTask($oTask3, 'InvalidClassName', OA_Task_Runner::TASK_ORDER_REPLACE); $this->assertFalse($return); // Add before task $return = $oTaskRunner->addTask($oTask4, 'MockTask0', OA_Task_Runner::TASK_ORDER_BEFORE); $this->assertTrue($return); $this->assertEqual(count($oTaskRunner->aTasks), 4); $oTask = $oTaskRunner->aTasks[0]; $this->assertIsA($oTask, 'MockTask4'); $oTask = $oTaskRunner->aTasks[1]; $this->assertIsA($oTask, 'MockTask0'); $oTask = $oTaskRunner->aTasks[2]; $this->assertIsA($oTask, 'MockTask3'); $oTask = $oTaskRunner->aTasks[3]; $this->assertIsA($oTask, 'MockTask1'); $return = $oTaskRunner->addTask($oTask4, 'InvalidClassName', OA_Task_Runner::TASK_ORDER_BEFORE); $this->assertFalse($return); }