コード例 #1
0
 /**
  * A method to test the main run() method.
  */
 function testRun()
 {
     $aConf =& $GLOBALS['_MAX']['CONF'];
     $aConf['maintenance']['operationInterval'] = 60;
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oFactory = new OX_Dal_Maintenance_Statistics_Factory();
     $oDalMaintenanceStatsticsClassName = $oFactory->deriveClassName();
     // Test 1: Run, with the migration required but with no plugins installed
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_1', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_1($this);
     $oDal->expectNever('summariseBucketsRaw');
     $oDal->expectNever('summariseBucketsRawSupplementary');
     $oDal->expectNever('summariseBucketsAggregate');
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Create the "application_variable" table required for installing the plugin
     $oTables =& OA_DB_Table_Core::singleton();
     $oTables->createTable('application_variable');
     // Setup the default OpenX delivery logging plugin for the next test
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 2: Run, with plugins installed, but with the migration not required
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = false;
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_2', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_2($this);
     $oDal->expectNever('summariseBucketsRaw');
     $oDal->expectNever('summariseBucketsRawSupplementary');
     $oDal->expectNever('summariseBucketsAggregate');
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 3: Run, with plugins installed and with the migration required for a single
     //         operation interval
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_3', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_3($this);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 09:01:00'")));
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 4: Run, with plugins installed and with the migration required for a single
     //         operation interval + migration of raw data set to occur
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->insert();
     $oNowDate = new Date('2008-08-28 09:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 08:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_4', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_4($this);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectOnce('summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 09:01:00'")));
     $oDal->expectOnce('migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectOnce('migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectOnce('migrateRawClicks', array($oStartDate, $oEndDate));
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->find();
     $rows = $doApplication_variable->getRowCount();
     $this->assertEqual($rows, 0);
     // Test 5: Run, with plugins installed and with the migration required for multiple
     //         operation intervals
     $oNowDate = new Date('2008-08-28 11:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 10:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_5', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_5($this);
     $oDal->expectCallCount('summariseBucketsRaw', 3);
     $oDal->expectCallCount('summariseBucketsRawSupplementary', 3);
     $oDal->expectCallCount('summariseBucketsAggregate', 3);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 09:00:00'", 'interval_end' => "'2008-08-28 09:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 10:00:00'", 'interval_end' => "'2008-08-28 10:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oDal->expectNever('migrateRawRequests');
     $oDal->expectNever('migrateRawImpressions');
     $oDal->expectNever('migrateRawClicks');
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     // Test 6: Run, with plugins installed and with the migration required for multiple
     //         operation intervals + migration of raw data set to occur
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->insert();
     $oNowDate = new Date('2008-08-28 11:01:00');
     $oServiceLocator->register('now', $oNowDate);
     $oMaintenanceStatistics = new OX_Maintenance_Statistics();
     $oMaintenanceStatistics->updateIntermediate = true;
     $oMaintenanceStatistics->oLastDateIntermediate = new Date('2008-08-28 07:59:59');
     $oMaintenanceStatistics->oUpdateIntermediateToDate = new Date('2008-08-28 10:59:59');
     $oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
     Mock::generatePartial($oDalMaintenanceStatsticsClassName, 'MockOX_Dal_Maintenance_Statistics_Test_6', array('summariseBucketsRaw', 'summariseBucketsRawSupplementary', 'summariseBucketsAggregate', 'migrateRawRequests', 'migrateRawImpressions', 'migrateRawClicks'));
     $oDal = new MockOX_Dal_Maintenance_Statistics_Test_6($this);
     $oDal->expectCallCount('summariseBucketsRaw', 3);
     $oDal->expectCallCount('summariseBucketsRawSupplementary', 3);
     $oDal->expectCallCount('summariseBucketsAggregate', 3);
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversion');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRaw', array($aConf['table']['prefix'] . 'data_intermediate_ad_connection', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogConversion', 'logConversionVariable');
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsRawSupplementary', array($aConf['table']['prefix'] . 'data_intermediate_ad_variable_value', $oComponent->getStatisticsMigration(), array('start' => $oStartDate, 'end' => $oEndDate)));
     $aMap = array();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogClick', 'logClick');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogImpression', 'logImpression');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oComponent =& OX_Component::factory('deliveryLog', 'oxLogRequest', 'logRequest');
     $aMap[get_class($oComponent)] = $oComponent->getStatisticsMigration();
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 08:00:00'", 'interval_end' => "'2008-08-28 08:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 09:00:00'", 'interval_end' => "'2008-08-28 09:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'summariseBucketsAggregate', array($aConf['table']['prefix'] . 'data_intermediate_ad', $aMap, array('start' => $oStartDate, 'end' => $oEndDate), array('operation_interval' => '60', 'operation_interval_id' => OX_OperationInterval::convertDateToOperationIntervalID($oStartDate), 'interval_start' => "'2008-08-28 10:00:00'", 'interval_end' => "'2008-08-28 10:59:59'", 'creative_id' => 0, 'updated' => "'2008-08-28 11:01:00'")));
     $oStartDate = new Date('2008-08-28 07:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 09:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(0, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(0, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(0, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oStartDate = new Date('2008-08-28 08:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 10:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(1, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(1, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(1, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oStartDate = new Date('2008-08-28 09:59:59');
     $oStartDate->addSeconds(1);
     $oEndDate = new Date('2008-08-28 11:00:00');
     $oEndDate->subtractSeconds(1);
     $oDal->expectAt(2, 'migrateRawRequests', array($oStartDate, $oEndDate));
     $oDal->expectAt(2, 'migrateRawImpressions', array($oStartDate, $oEndDate));
     $oDal->expectAt(2, 'migrateRawClicks', array($oStartDate, $oEndDate));
     $oDal->OX_Dal_Maintenance_Statistics();
     $oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $oSummariseIntermediate->run();
     $oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
     $oDal->tally();
     $doApplication_variable = OA_Dal::factoryDO('application_variable');
     $doApplication_variable->name = 'mse_process_raw';
     $doApplication_variable->value = '1';
     $doApplication_variable->find();
     $rows = $doApplication_variable->getRowCount();
     $this->assertEqual($rows, 0);
     // Uninstall the installed plugins
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Reset the testing environment
     TestEnv::restoreEnv();
 }
コード例 #2
0
ファイル: republish.php プロジェクト: akirsch/revive-adserver
$result = OX_OperationInterval::checkDateIsStartDate($oStartDate);
if (!$result) {
    $message = "\nThe start date passed into the " . basename(__FILE__) . " script is not a valid operation interval start date.\nPlease pass in the start date in '%Y-%M-%d %H:%m:%s' format\n";
    echo $message;
    echo $haltMessage;
    exit;
}
$oEndDate = new Date(INTERVAL_END);
$result = OX_OperationInterval::checkDateIsEndDate($oEndDate);
if (!$result) {
    $message = "\nThe end date passed into the " . basename(__FILE__) . " script is not a valid operation interval end date.\nPlease pass in the end date in '%Y-%M-%d %H:%m:%s' format.\n";
    echo $message;
    echo $haltMessage;
    exit;
}
$oMigrator = new OX_Maintenance_Statistics_Task_MigrateBucketData();
if (PEAR::isError($oMigrator->oDbh)) {
    $message = "\nUnable to connect to the OpenX database.\n";
    echo $message;
    echo $haltMessage;
    exit;
}
/***************************************************************************/
// Advise the user of the operations that will be performed, and ask for
// permission before running.
echo "\nThe " . basename(__FILE__) . " script will look for any data_bkt_% records which are 'orphaned', and will perform summarisation of these records\nfor all operation intervals between '" . $oStartDate->format('%Y-%m-%d %H:%M:%S') . "' and '" . $oEndDate->format('%Y-%m-%d %H:%M:%S') . "'.\n\nPlease ensure that you have read the comments in the " . basename(__FILE__) . " script\n\nDepending on the speed of your database, this may take a long time to run. You may want to temporarily\ndisable your central maintenance script while this script runs.\n\nDo you want to proceed with the republishing? [y/N]: ";
if (empty($argv[4]) || $argv[4] != '-f') {
    $response = trim(fgets(STDIN));
    if (!($response == 'y' || $response == 'Y')) {
        echo $haltMessage;
        exit;
 /**
  * A method to test the _locateComponents() method.
  */
 function test_locateComponents()
 {
     $aConf = $GLOBALS['_MAX']['CONF'];
     // Test 1: There are no deliveryLog group plugins installed, test that
     //         an empty array is returned
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $aComponents = $oSummariseIntermediate->_locateComponents();
     $this->assertTrue(is_array($aComponents));
     $this->assertTrue(empty($aComponents));
     // Setup the default OpenX delivery logging plugin for the next test
     TestEnv::installPluginPackage('openXDeliveryLog', false);
     // Test 2: Test with the default OpenX delivery logging plugin installed
     $oSummariseIntermediate = new OX_Maintenance_Statistics_Task_MigrateBucketData();
     $aComponents = $oSummariseIntermediate->_locateComponents();
     $this->assertTrue(is_array($aComponents));
     $this->assertEqual(count($aComponents), 3);
     $dia = $aConf['table']['prefix'] . 'data_intermediate_ad';
     $this->assertTrue(is_array($aComponents[$dia]));
     $this->assertEqual(count($aComponents[$dia]), 3);
     $aComponentClasses = array();
     foreach ($aComponents[$dia] as $oComponent) {
         $aComponentClasses[] = get_class($oComponent);
     }
     $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogRequest_LogRequest', $aComponentClasses));
     $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogImpression_LogImpression', $aComponentClasses));
     $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogClick_LogClick', $aComponentClasses));
     $diac = $aConf['table']['prefix'] . 'data_intermediate_ad_connection';
     $this->assertTrue(is_array($aComponents[$diac]));
     $this->assertEqual(count($aComponents[$diac]), 1);
     $aComponentClasses = array();
     foreach ($aComponents[$diac] as $oComponent) {
         $aComponentClasses[] = get_class($oComponent);
     }
     $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogConversion_LogConversion', $aComponentClasses));
     $diavv = $aConf['table']['prefix'] . 'data_intermediate_ad_variable_value';
     $this->assertTrue(is_array($aComponents[$diavv]));
     $this->assertEqual(count($aComponents[$diavv]), 1);
     $aComponentClasses = array();
     foreach ($aComponents[$diavv] as $oComponent) {
         $aComponentClasses[] = get_class($oComponent);
     }
     $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogConversion_LogConversionVariable', $aComponentClasses));
     /*
     TODO: move this test from core code to the plugin.  only bundled plugins (or the test plugin) can be used in core tests
             // Setup the default OpenX country based impression and click delivery logging plugin for the next test
             TestEnv::installPluginPackage('openXDeliveryLogCountry', false);
             // Test 3: Test with the default OpenX delivery logging plugin and the OpenX country based impression
             //         and click delivery logging plugin installed
             $aComponents = $oSummariseIntermediate->_locateComponents();
             $this->assertTrue(is_array($aComponents));
             $this->assertEqual(count($aComponents), 4);
             $dia = $aConf['table']['prefix'] . 'data_intermediate_ad';
             $this->assertTrue(is_array($aComponents[$dia]));
             $this->assertEqual(count($aComponents[$dia]), 4);
             $aComponentClasses = array();
             foreach ($aComponents[$dia] as $oComponent) {
                 $aComponentClasses[] = get_class($oComponent);
             }
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogRequest_LogRequest', $aComponentClasses));
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogImpression_LogImpression', $aComponentClasses));
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogClick_LogClick', $aComponentClasses));
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogImpression_logImpressionBackup', $aComponentClasses));
             $diac = $aConf['table']['prefix'] . 'data_intermediate_ad_connection';
             $this->assertTrue(is_array($aComponents[$diac]));
             $this->assertEqual(count($aComponents[$diac]), 1);
             $aComponentClasses = array();
             foreach ($aComponents[$diac] as $oComponent) {
                 $aComponentClasses[] = get_class($oComponent);
             }
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogConversion_LogConversion', $aComponentClasses));
             $diavv = $aConf['table']['prefix'] . 'data_intermediate_ad_variable_value';
             $this->assertTrue(is_array($aComponents[$diavv]));
             $this->assertEqual(count($aComponents[$diavv]), 1);
             $aComponentClasses = array();
             foreach ($aComponents[$diavv] as $oComponent) {
                 $aComponentClasses[] = get_class($oComponent);
             }
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogConversion_LogConversionVariable', $aComponentClasses));
             $sc = $aConf['table']['prefix'] . 'stats_country';
             $this->assertTrue(is_array($aComponents[$sc]));
             $this->assertEqual(count($aComponents[$sc]), 2);
             $aComponentClasses = array();
             foreach ($aComponents[$sc] as $oComponent) {
                 $aComponentClasses[] = get_class($oComponent);
             }
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogCountry_LogImpressionCountry', $aComponentClasses));
             $this->assertTrue(in_array('Plugins_DeliveryLog_OxLogCountry_LogClickCountry', $aComponentClasses));
             // Uninstall the installed plugins
             TestEnv::uninstallPluginPackage('openXDeliveryLogCountry', false);
     */
     // Uninstall the installed plugins
     TestEnv::uninstallPluginPackage('openXDeliveryLog', false);
     // Reset the testing environment
     TestEnv::restoreEnv();
 }