/** * A private method that determines which (if any) operation intervals need the zone * impression forecast values to be updated for ALL zones. * * @access private * @return mixed One of the following three values will be returned, depending on what * ZIF values need to be updated: * - true: Update the ZIF values for all operation intervals. * - false: No ZIF values need to be updated (eg. this is the second, or greater, * time that the MPE has been run in this operation interval, so there * are no new statistics values summarised by the MSE to allow the ZIF * values to be udpated). * - array: An array with the start and end operation interval IDs of the * range to update; the first may be higher than the second, in * the event that the range spans from the end of one week into the * start of the next week. */ function _getUpdateTypeRequired() { OA::debug('- Calculating range of operation intervals which require ZIF update', PEAR_LOG_DEBUG); // Set default return value $return = false; if (is_null($this->oStatisticsUpdatedToDate)) { // The MSE has never been run; there are no stats. Update all operation intervals (with the // default zone forecast value) so that this new installation of OpenX can ran: return true OA::debug(' - No previous maintenance statisitcs run, so update all OIs required', PEAR_LOG_DEBUG); $return = true; } elseif (is_null($this->oPriorityUpdatedToDate)) { // The MPE has never updated zone forecasts before. Update all operation intervals (with the // default zone forecast value) so that this new installation of OpenX can ran: return true OA::debug(' - No previous maintenance priority run, so update all OIs required', PEAR_LOG_DEBUG); $return = true; } elseif (OX_OperationInterval::getOperationInterval() != $this->priorityOperationInterval) { // The operation interval has changed since the last run, force an update all: return true OA::debug(' - OPERATION INTERVAL LENGTH CHANGE SINCE LAST RUN', PEAR_LOG_DEBUG); OA::debug(' - Update of all OIs required', PEAR_LOG_DEBUG); $return = true; } else { // If stats was run after priority, then the maintenance stats updated to date will be equal to, // or after, the maintenance priority updated to date (as the maintenance priority updated to // date is one operation interval ahead of where statistics is) if ($this->oStatisticsUpdatedToDate->equals($this->oPriorityUpdatedToDate) || $this->oStatisticsUpdatedToDate->after($this->oPriorityUpdatedToDate)) { // If a week or more has passed since the last priority update, update all: return true $oSpan = new Date_Span(); $oUpdatedToDateCopy = new Date(); $oUpdatedToDateCopy->copy($this->oPriorityUpdatedToDate); $oDateNowCopy = new Date(); $oDateNowCopy->copy($this->oDateNow); $oSpan->setFromDateDiff($oUpdatedToDateCopy, $oDateNowCopy); if ($oSpan->day >= 7) { OA::debug(' - One week has passed since last run, so update all OIs required', PEAR_LOG_DEBUG); $return = true; } else { // Get the operation intervals for each run $statsOpIntId = OX_OperationInterval::convertDateToOperationIntervalID($this->oStatisticsUpdatedToDate); $priorityOpIntId = OX_OperationInterval::convertDateToOperationIntervalID($this->oPriorityUpdatedToDate); // Always predict one interval ahead of the statistics engine $statsOpIntId = OX_OperationInterval::nextOperationIntervalID($statsOpIntId); // As long as the operation intervals are not in the same interval, priority should be run if ($statsOpIntId != $priorityOpIntId) { OA::debug(' - Found OI range to update', PEAR_LOG_DEBUG); $return = array($priorityOpIntId, $statsOpIntId); } else { OA::debug(' - MPE has already run this operation interval, no ZIF update required', PEAR_LOG_DEBUG); $return = false; } } } } return $return; }
/** * A private method to perform assertions on the contents of the * log_maintenance_priority table. * * @access private * @param integer $id Optional row ID to test on, if not set, tests * that table is empty. * @param PEAR::Date $oBeforeUpdateDate The before date to test the row with. * @param PEAR::Date $oAfterUpdateDate The after date to test the row with. * @param integer $oi The operation interval to test the row with. * @param integer $runType The run type value to test the row with. * @param string $updatedTo The updated to date to test the row with, if any. */ function _assertLogMaintenance($id = null, $oBeforeUpdateDate = null, $oAfterUpdateDate = null, $oi = null, $runType = null, $updatedTo = null) { $aConf = $GLOBALS['_MAX']['CONF']; $tableName = $aConf['table']['prefix'] . 'log_maintenance_priority'; $table = $this->oDbh->quoteIdentifier($tableName, true); $query = "\n SELECT\n start_run,\n end_run,\n operation_interval,\n run_type,\n updated_to\n FROM\n {$table}"; if (!is_null($id)) { $query .= "\n WHERE\n log_maintenance_priority_id = {$id}"; } $rc = $this->oDbh->query($query); $aRow = $rc->fetchRow(); if (is_null($id)) { // Check there are no rows returned $this->assertNull($aRow); } else { // Check the returned row's values $oStartRunDate = new Date($aRow['start_run']); $oEndRunDate = new Date($aRow['end_run']); $result = $oBeforeUpdateDate->before($oStartRunDate); $this->assertTrue($result); $result = $oBeforeUpdateDate->before($oEndRunDate); $this->assertTrue($result); $result = $oAfterUpdateDate->after($oStartRunDate); $this->assertTrue($result); $result = $oAfterUpdateDate->after($oEndRunDate); $this->assertTrue($result); $result = $oStartRunDate->after($oEndRunDate); $this->assertFalse($result); $this->assertEqual($aRow['operation_interval'], $oi); $this->assertEqual($aRow['run_type'], $runType); if (!is_null($updatedTo)) { $this->assertEqual($aRow['updated_to'], $updatedTo); } else { $this->assertNull($aRow['updated_to']); } } }