function alterDatabaseActionTable() { $this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn())); $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; OA_DB::setCaseSensitive(); $aPrev = $this->oSchema->getDefinitionFromDatabase(array($prefix . 'database_action')); OA_DB::disableCaseSensitive(); $aCurr = $this->_getLatestDatabaseActionSchema($prefix); $aChanges = $this->oSchema->compareDefinitions($aCurr, $aPrev); if (is_array($aChanges) && count($aChanges) > 0) { if (isset($aChanges['tables']['change'][$prefix . 'database_action'])) { if (isset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey'])) { unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['add']['database_action_pkey']); unset($aChanges['tables']['change'][$prefix . 'database_action']['indexes']['change']); } if (isset($aChanges['tables']['change'][$prefix . 'database_action']['add']['database_action_id'])) { $result = $this->oSchema->alterDatabase($aCurr, $aPrev, $aChanges); if (PEAR::isError($result)) { $this->oUpgrade->oLogger->logError($result->getUserInfo()); return false; } $this->oUpgrade->oLogger->log('database_action table schema successfully upgraded'); return true; } } } $this->oUpgrade->oLogger->log('database_action table schema upgrade unnecessary'); return true; }
/** * A method to test the saveAllocatedImpressions method. */ function testSaveAllocatedImpressions() { $oDbh =& OA_DB::singleton(); $oDal = new OA_Dal_Maintenance_Priority(); // Create the required temporary table for the tests $oTable =& OA_DB_Table_Priority::singleton(); $oTable->createTable('tmp_ad_zone_impression'); // Prepare the test data $aData = array(array('ad_id' => 56, 'zone_id' => 11, 'required_impressions' => 9997, 'requested_impressions' => 9000), array('ad_id' => 56, 'zone_id' => 12, 'required_impressions' => 24, 'requested_impressions' => 24)); $result = $oDal->saveAllocatedImpressions($aData); $query = "SELECT * FROM " . $oDbh->quoteIdentifier('tmp_ad_zone_impression', true) . " ORDER BY ad_id, zone_id"; $rc = $oDbh->query($query); $result = $rc->fetchAll(); $this->assertTrue(is_array($result)); $this->assertTrue(count($result) == 2); $tmp = $result[0]; $this->assertTrue(array_key_exists('ad_id', $tmp)); $this->assertEqual($tmp['ad_id'], 56); $this->assertTrue(array_key_exists('zone_id', $tmp)); $this->assertEqual($tmp['zone_id'], 11); $this->assertTrue(array_key_exists('required_impressions', $tmp)); $this->assertEqual($tmp['required_impressions'], 9997); $this->assertTrue(array_key_exists('requested_impressions', $tmp)); $this->assertEqual($tmp['requested_impressions'], 9000); $tmp = $result[1]; $this->assertTrue(array_key_exists('ad_id', $tmp)); $this->assertEqual($tmp['ad_id'], 56); $this->assertTrue(array_key_exists('zone_id', $tmp)); $this->assertEqual($tmp['zone_id'], 12); $this->assertTrue(array_key_exists('required_impressions', $tmp)); $this->assertEqual($tmp['required_impressions'], 24); $this->assertTrue(array_key_exists('requested_impressions', $tmp)); $this->assertEqual($tmp['requested_impressions'], 24); TestEnv::dropTempTables(); }
function execute($aParams) { $this->oUpgrade = $aParams[0]; if ($this->oUpgrade->oDbh->dbsyntax == 'pgsql') { $prefix = $this->oUpgrade->oDBUpgrader->prefix; $result = $this->oUpgrade->oDbh->exec("ALTER TABLE {$prefix}zones ALTER zonename TYPE varchar(245)"); // This ALTER TABLE needs to run in UTC because it stores a UTC timestamp $result = $this->oUpgrade->oDbh->exec("SET timezone = 'UTC'"); $result = $this->oUpgrade->oDbh->exec("ALTER TABLE {$prefix}session ALTER lastused TYPE timestamp"); $result = $this->oUpgrade->oDbh->exec("SET timezone = DEFAULT"); $result = $this->oUpgrade->oDbh->exec("ALTER TABLE {$prefix}images ALTER t_stamp TYPE timestamp"); $result = $this->oUpgrade->oDbh->exec("DROP INDEX " . OA_phpAdsNew::phpPgAdsPrefixedIndex('banners_clientid_idx', $prefix)); $result = $this->oUpgrade->oDbh->exec("DROP INDEX " . OA_phpAdsNew::phpPgAdsPrefixedIndex('clients_parent_idx', $prefix)); $result = $this->oUpgrade->oDbh->exec("DROP INDEX " . OA_phpAdsNew::phpPgAdsPrefixedIndex('zones_affiliateid_idx', $prefix)); $aForeignKeys = $this->oUpgrade->oDbh->getAssoc("\n SELECT\n r.conname AS fk,\n c.relname AS table\n FROM\n pg_catalog.pg_class c JOIN\n pg_catalog.pg_constraint r ON (r.conrelid = c.oid)\n WHERE\n c.relname IN ('{$prefix}acls', '{$prefix}banners', '{$prefix}clients', '{$prefix}zones') AND\n pg_catalog.pg_table_is_visible(c.oid) AND\n r.contype = 'f'\n ORDER BY\n 1,2\n "); foreach ($aForeignKeys as $fkey => $table) { $result = $this->oUpgrade->oDbh->exec("ALTER TABLE {$table} DROP CONSTRAINT {$fkey}"); } $aIndexes = array(OA_phpAdsNew::phpPgAdsPrefixedIndex('acls_bannerid_idx', $prefix) => 'acls_bannerid', OA_phpAdsNew::phpPgAdsPrefixedIndex('acls_bannerid_executionorder_udx', $prefix) => 'acls_bannerid_executionorder', OA_phpAdsNew::phpPgAdsPrefixedIndex('acls_bannerid_idx', $prefix) => 'acls_bannerid', OA_phpAdsNew::phpPgAdsPrefixedIndex('adclicks_bid_date_idx', $prefix) => 'adclicks_bannerid_date', OA_phpAdsNew::phpPgAdsPrefixedIndex('adclicks_date_idx', $prefix) => 'adclicks_date', OA_phpAdsNew::phpPgAdsPrefixedIndex('adclicks_zoneid_idx', $prefix) => 'adclicks_zoneid', OA_phpAdsNew::phpPgAdsPrefixedIndex('adstats_bid_day_idx', $prefix) => 'adstats_bannerid_day', OA_phpAdsNew::phpPgAdsPrefixedIndex('adstats_zoneid_idx', $prefix) => 'adstats_zoneid', OA_phpAdsNew::phpPgAdsPrefixedIndex('adviews_bid_date_idx', $prefix) => 'adviews_bannerid_date', OA_phpAdsNew::phpPgAdsPrefixedIndex('adviews_date_idx', $prefix) => 'adviews_date', OA_phpAdsNew::phpPgAdsPrefixedIndex('adviews_zoneid_idx', $prefix) => 'adviews_zoneid', OA_phpAdsNew::phpPgAdsPrefixedIndex('zones_zonename_zoneid_idx', $prefix) => 'zones_zonenameid'); foreach ($aIndexes as $oldIndex => $newIndex) { $result = $this->oUpgrade->oDbh->exec("ALTER INDEX {$oldIndex} RENAME TO {$prefix}{$newIndex}"); } $aFunctions = array('unix_timestamp(timestamptz)', 'from_unixtime(int4)', 'to_days(timestamptz)', 'dayofmonth(timestamptz)', 'month(timestamptz)', 'year(timestamptz)', 'week(timestamptz)', 'hour(timestamptz)', 'date_format(timestamptz, text)', 'if(bool, varchar, varchar)'); foreach ($aFunctions as $function) { $result = $this->oUpgrade->oDbh->exec("DROP FUNCTION {$function}"); } OA_DB::createFunctions(); } return true; }
/** * Tests creating/dropping all of the MPE temporary tables. * * Requirements: * Test 1: Test that all MPE temporary tables can be created and dropped. */ function testAllMaintenanceStatisticsTables() { $tmpTables = array('tmp_ad_impression', 'tmp_ad_click', 'tmp_tracker_impression_ad_impression_connection', 'tmp_tracker_impression_ad_click_connection', 'tmp_ad_connection'); // Test 1 $conf =& $GLOBALS['_MAX']['CONF']; $conf['table']['prefix'] = ''; $oDbh =& OA_DB::singleton(); foreach ($tmpTables as $tableName) { $query = "SELECT * FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } $oTable =& OA_DB_Table_Statistics::singleton(); foreach ($tmpTables as $tableName) { $oTable->createTable($tableName); } $aExistingTables = OA_DB_Table::listOATablesCaseSensitive(); foreach ($tmpTables as $tableName) { // Test that the table has been created $query = "SELECT * FROM {$tableName}"; $result = $oDbh->query($query); $this->assertTrue($result); // Test that the table can be dropped // Use a different query to overcome MDB2 query buffering $query = "SELECT foo FROM {$tableName}"; OA::disableErrorHandling(); $result = $oDbh->query($query); OA::enableErrorHandling(); $this->assertEqual(strtolower(get_class($result)), 'mdb2_error'); } // Restore the testing environment TestEnv::restoreEnv(); }
function setUp() { $this->oDbh = OA_DB::singleton(OA_DB::getDsn()); $this->oTable = new OA_DB_Table(); $this->oTable->init(MAX_PATH . '/lib/OA/Upgrade/tests/data/migration_test_1.xml'); $this->aDefinition = $this->oTable->aDefinition; }
/** * The constructor method. */ function Test_OA_DB_XmlCache() { $this->UnitTestCase(); $this->oDbh = OA_DB::singleton(); $this->oCache = new OA_DB_XmlCache(); $this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false)); }
/** * Constructor * * @param array $conf array, if null reads the global variable * @param array $pref array, if null reads the global variable */ function __construct($conf = null, $pref = null) { $this->aConf = is_null($conf) ? $GLOBALS['_MAX']['CONF'] : $conf; $this->aPref = is_null($pref) ? $GLOBALS['_MAX']['PREF'] : $pref; $this->_conf = $this->aConf['oacSync']; $this->oDbh =& OA_DB::singleton(); }
/** * The constructor method. */ function __construct() { parent::__construct(); $this->oDbh = OA_DB::singleton(); $this->oCache = new OA_DB_XmlCache(); $this->oSchema =& MDB2_Schema::factory($this->oDbh, array('force_defaults' => false)); }
function removeDashboardColumns() { $this->oSchema = MDB2_Schema::factory(OA_DB::singleton(OA_DB::getDsn())); $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; $table = 'preference'; $aColumns = array('ad_clicks_sum', 'ad_views_sum', 'ad_clicks_per_second', 'ad_views_per_second', 'ad_cs_data_last_sent', 'ad_cs_data_last_sent', 'ad_cs_data_last_received'); OA_DB::setCaseSensitive(); $aDef = $this->oSchema->getDefinitionFromDatabase(array($prefix . $table)); OA_DB::disableCaseSensitive(); if (is_array($aDef) && count($aDef) > 0) { $aTask['remove'] = array(); if (isset($aDef['tables'][$prefix . $table])) { foreach ($aColumns as $column) { if (isset($aDef['tables'][$prefix . $table]['fields'][$column])) { $aTask['remove'][$column] = array(); $this->oUpgrade->oLogger->logOnly("preference.{$column} found"); } } } if (count($aTask['remove'] > 0)) { $result = $this->oSchema->db->manager->alterTable($prefix . $table, $aTask, false); } } $this->oUpgrade->oLogger->logOnly('preference table schema upgrade for dashboard unnecessary'); return true; }
function testSqlForInsert() { $sql = OA_DB_Sql::sqlForInsert('zones', array('zonetype' => 1, 'name' => "120x72")); $oDbh = OA_DB::singleton(); $table = $oDbh->quoteIdentifier($this->getPrefix() . 'zones', true); $this->assertEqual("INSERT INTO {$table} (zonetype,name) VALUES (1,'120x72')", $sql); }
function UserMigration() { // We will need the admin and per-agency languages to assign the correct "Default" languages to advertiser and websites if (!$this->init(OA_DB::singleton())) { $this->_logError('Failed to initialise UserMigration class'); return false; } $this->_log('Initialised UserMigration class, construction begun'); $table = $this->_getQuotedTableName('preference'); // Get admin language $query = "\n SELECT\n agencyid AS id,\n language AS language\n FROM\n {$table}\n WHERE\n agencyid = 0\n "; $adminLang = $this->oDBH->getAssoc($query); if (PEAR::isError($adminLang)) { $this->_logError("Error while retrieving admin language: " . $adminLang->getUserInfo()); return false; } // Get agency languages $table = $this->_getQuotedTableName('agency'); $query = "\n SELECT\n agencyid AS id,\n language AS language\n FROM\n {$table}"; $agencyLang = $this->oDBH->getAssoc($query); if (PEAR::isError($agencyLang)) { $this->_logError("Error while retrieving agency languages: " . $agencyLang->getUserInfo()); return false; } // Set the admin's language for id 0, then set each agencies language as specified, using admins if unset $this->aLanguageByAgency[0] = !empty($adminLang[0]) ? $adminLang[0] : 'english'; foreach ($agencyLang as $id => $language) { if (!empty($language)) { $this->aLanguageByAgency[$id] = $language; } else { $this->aLanguageByAgency[$id] = $this->aLanguageByAgency[0]; } } $this->_log('UserMigration class, construction complete'); }
/** * A method that uses the getAllCampaigns() method to obtain all campaigns * that meet the requirements of this class. That is: * * - The campaign is active, and has a priority of at least 1; and * - The campaign has daily inventory requirements. * * @access private * @return array An array of {@link OX_Maintenance_Priority_Campaign} objects. */ function _getValidCampaigns() { $conf = $GLOBALS['_MAX']['CONF']; $oDbh = OA_DB::singleton(); $table = $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['campaigns'], true); $aWheres = array(array("{$table}.priority >= 1", 'AND'), array("{$table}.status = " . OA_ENTITY_STATUS_RUNNING, 'AND'), array("({$table}.target_impression > 0 OR {$table}.target_click > 0 OR {$table}.target_conversion > 0)", 'AND'), array("({$table}.expire_time IS NULL OR ({$table}.views = -1 AND {$table}.clicks = -1 AND {$table}.conversions = -1))", 'AND')); return $this->_getAllCampaigns($aWheres); }
function init($aParams) { $this->className = get_class($this); $this->oDBUpgrade = $aParams[0]; $this->_log('****************************************'); $this->oDbh = OA_DB::singleton(OA_DB::getDsn()); return true; }
function _getAuditObject($classToTest) { $oAuditor = new $classToTest(); $oDbh = OA_DB::singleton(OA_DB::getDsn()); $oAuditor->prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; $oAuditor->oDbh = $oDbh; return $oAuditor; }
function __construct() { // Get a connection to the datbase $this->oDbh =& OA_DB::singleton(); // Locate all plugins (packages) that have been installed $oPluginManager = new OX_PluginManager(); $this->aPackages = $oPluginManager->getPackagesList(); }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; if ($this->oDbh->dbsyntax == 'pgsql') { $oTable =& $this->oUpgrade->oDBUpgrader->oTable; foreach ($oTable->aDefinition['tables'] as $tableName => $aTable) { foreach ($aTable['fields'] as $fieldName => $aField) { if (!empty($aField['autoincrement'])) { // Check actual sequence name $oldSequenceName = $this->getLinkedSequence($prefix . $tableName, $fieldName); if ($oldSequenceName) { $newSequenceName = OA_DB::getSequenceName($this->oDbh, $tableName, $fieldName); if ($oldSequenceName != $newSequenceName) { $this->logOnly("Non standard sequence name found: " . $oldSequenceName); $qTable = $this->oDbh->quoteIdentifier($prefix . $tableName, true); $qField = $this->oDbh->quoteIdentifier($fieldName, true); $qOldSequence = $this->oDbh->quoteIdentifier($oldSequenceName, true); $qNewSequence = $this->oDbh->quoteIdentifier($newSequenceName, true); OA::disableErrorHandling(); $result = $this->oDbh->exec("ALTER TABLE {$qOldSequence} RENAME TO {$qNewSequence}"); if (PEAR::isError($result)) { if ($result->getCode() == MDB2_ERROR_ALREADY_EXISTS) { $result = $this->oDbh->exec("DROP SEQUENCE {$qNewSequence}"); if (PEAR::isError($result)) { $this->logError("Could not drop existing sequence {$newSequenceName}: " . $result->getUserInfo()); return false; } $result = $this->oDbh->exec("ALTER TABLE {$qOldSequence} RENAME TO {$qNewSequence}"); } } if (PEAR::isError($result)) { $this->logError("Could not rename {$oldSequenceName} to {$newSequenceName}: " . $result->getUserInfo()); return false; } $result = $this->oDbh->exec("ALTER TABLE {$qTable} ALTER {$qField} SET DEFAULT nextval(" . $this->oDbh->quote($qNewSequence) . ")"); if (PEAR::isError($result)) { $this->logError("Could not set column default to sequence {$newSequenceName}: " . $result->getUserInfo()); return false; } OA::enableErrorHandling(); $result = $oTable->resetSequenceByData($tableName, $fieldName); if (PEAR::isError($result)) { $this->logError("Could not reset sequence value for {$newSequenceName}: " . $result->getUserInfo()); return false; } $this->logOnly("Successfully renamed {$oldSequenceName} to {$newSequenceName}"); } } else { $this->logOnly("No sequence found for {$tableName}.{$fieldName}"); } } } } } return true; }
function init() { $this->oDbh =& OA_DB::singleton(); if (PEAR::isError($this->oDbh)) { return false; } $this->oNow = new Date(); return true; }
function Test_OA_Dal_Delivery_getAccountTZs() { $this->UnitTestCase(); $this->oDbh = OA_DB::singleton(); $this->prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; // Disable caching $GLOBALS['OA_Delivery_Cache']['expiry'] = -1; MAX_Dal_Delivery_Include(); }
function test_putComponentGroupVersion() { $oVerCtrl = new OA_Version_Controller(); $oVerCtrl->init(OA_DB::singleton(OA_DB::getDsn())); $this->assertEqual($oVerCtrl->putComponentGroupVersion('plugin_test', 1001), 1001, 'error inserting plugin version'); $this->assertEqual($oVerCtrl->putComponentGroupVersion('plugin_test', 1002), 1002, 'error updating plugin version'); $this->assertNotEqual($oVerCtrl->getComponentGroupVersion('plugin_test'), 1001, 'wrong plugin version retrieved'); $this->_deleteTestRecord('plugin_test'); }
/** * The constructor method. */ function __construct() { parent::__construct(); // Prepare the database connection for use in the tests $this->oDbh = OA_DB::singleton(); // Prepare the MSE DAL for use in the tests $oFactory = new OX_Dal_Maintenance_Statistics_Factory(); $this->oDal = $oFactory->factory(); }
function __construct() { parent::__construct(); $this->oDbh = OA_DB::singleton(); $this->prefix = $GLOBALS['_MAX']['CONF']['table']['prefix']; // Disable caching $GLOBALS['OA_Delivery_Cache']['expiry'] = -1; MAX_Dal_Delivery_Include(); }
/** * The constructor method. */ function Test_OX_Dal_Maintenance_Statistics_migrateRawData_Complex() { $this->UnitTestCase(); // Prepare the database connection for use in the tests $this->oDbh = OA_DB::singleton(); // Prepare the MSE DAL for use in the tests $oFactory = new OX_Dal_Maintenance_Statistics_Factory(); $this->oDal = $oFactory->factory(); }
/** * A method to return a singleton database connection resource. * * Example usage: * $oDbh = OA_DB_Distributed::singleton(); * * Warning: In order to work correctly, the singleton method must * be instantiated statically and by reference, as in the above * example. * * @static * @param string $dsn Optional database DSN details - connects to the * database defined by the configuration file otherwise. * See {@link OA_DB::getDsn()} for format. * @return MDB2_Driver_Common An MDB2 connection resource, or PEAR_Error * on failure to connect. */ static function singleton($dsn = null) { // Get the DSN, if not set $dsn = is_null($dsn) ? OA_DB_Distributed::getDsn() : $dsn; // Should the connection have options set? $aDriverOptions = OA_DB_Distributed::getDsnOptions(); // Return the datbase connection return parent::singleton($dsn, $aDriverOptions); }
function getChannelsAndAffiliates() { $prefix = $this->getTablePrefix(); $oDbh = OA_DB::singleton(); $tableCh = $oDbh->quoteIdentifier($prefix . 'channel', true); $tableAf = $oDbh->quoteIdentifier($prefix . 'affiliates', true); $query = "\n SELECT\n ch.channelid,\n ch.affiliateid,\n ch.name,\n af.name AS affiliatename\n FROM\n {$tableCh} AS ch,\n {$tableAf} AS af\n WHERE\n af.affiliateid=ch.affiliateid\n ORDER BY ch.channelid\n "; return DBC::NewRecordSet($query); }
/** * Gets the details to for generating invocation code. * * @param int $zoneId the zone ID. * @return array zone details to be passed into MAX_Admin_Invocation::placeInvocationForm() * * @see MAX_Admin_Invocation::placeInvocationForm() */ function getZoneForInvocationForm($zoneId) { $prefix = $this->getTablePrefix(); $oDbh = OA_DB::singleton(); $tableZ = $oDbh->quoteIdentifier($prefix . 'zones', true); $tableAf = $oDbh->quoteIdentifier($prefix . 'affiliates', true); $query = "\n SELECT\n z.affiliateid,\n z.width,\n z.height,\n z.delivery,\n af.website\n FROM\n {$tableZ} AS z,\n {$tableAf} AS af\n WHERE\n z.zoneid = " . DBC::makeLiteral($zoneId) . "\n AND af.affiliateid = z.affiliateid"; $rsZone = DBC::FindRecord($query); return $rsZone->toArray(); }
/** * Connect to the the database * @return void * @access protected */ function connect() { // use existing connection $dbh =& OA_DB::singleton(); if (PEAR::isError($dbh)) { $this->RaiseError(); } else { $this->ConnectionId =& $dbh; } }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $prefix = $aConf['prefix']; foreach (array('tblAppVar' => 'application_variable', 'tblAccounts' => 'accounts', 'tblAgency' => 'agency', 'tblClients' => 'clients', 'tblCampaigns' => 'campaigns', 'tblBanners' => 'banners', 'tblAcls' => 'acls', 'tblPrefs' => 'preferences', 'tblAccPrefs' => 'account_preference_assoc') as $k => $v) { ${$k} = $this->oDbh->quoteIdentifier($prefix . ($aConf[$v] ? $aConf[$v] : $v), true); } // Get admin account ID $adminAccountId = (int) $this->oDbh->queryOne("SELECT value FROM {$tblAppVar} WHERE name = 'admin_account_id'"); if (PEAR::isError($adminAccountId)) { $this->logError("No admin account ID"); return false; } // Get preference ID for timezone $tzId = $this->oDbh->queryOne("SELECT preference_id FROM {$tblPrefs} WHERE preference_name = 'timezone'"); if (empty($tzId) || PEAR::isError($tzId)) { // Upgrading from 2.4 maybe? $tzId = 0; $this->logOnly("No timezone preference available, using default server timezone"); $adminTz = date_default_timezone_get(); if (empty($adminTz)) { // C'mon you should have set the timezone in your php.ini! $this->logOnly("No default server timezone, using UTC"); $adminTz = 'UTC'; } } else { // Get admin timezone $adminTz = $this->oDbh->queryOne("SELECT value FROM {$tblAccPrefs} WHERE preference_id = {$tzId} AND account_id = {$adminAccountId}"); if (empty($adminTz) || PEAR::isError($adminTz)) { $this->logOnly("No admin timezone, using UTC"); $adminTz = 'UTC'; } } $joinList = "{$tblBanners} b JOIN\n {$tblCampaigns} ca USING (campaignid) JOIN\n {$tblClients} cl USING (clientid) JOIN\n {$tblAgency} a USING (agencyid) LEFT JOIN\n {$tblAccPrefs} p ON (p.account_id = a.account_id AND p.preference_id = {$tzId})"; $tzPart = "COALESCE(p.value, " . $this->oDbh->quote($adminTz) . ")"; $wherePart = "\n ac.bannerid = b.bannerid AND\n \tac.type LIKE 'deliveryLimitations:Time:%' AND\n \tac.data NOT LIKE '%@%'\n "; if ($this->oDbh->dbsyntax == 'pgsql') { $query = "\n UPDATE\n {$tblAcls} ac\n SET\n data = data || '@' || {$tzPart}\n FROM\n {$joinList}\n WHERE\n {$wherePart}\n "; } else { $query = "\n UPDATE\n {$tblAcls} ac,\n {$joinList}\n SET\n ac.data = CONCAT(ac.data, '@', {$tzPart})\n WHERE\n {$wherePart}\n "; } $ret = $this->oDbh->exec($query); if (PEAR::isError($ret)) { $this->logError($ret->getUserInfo()); return false; } // Rebuild ACLs $this->oUpgrade->addPostUpgradeTask('Recompile_Acls'); // Also rebuild banner cache for OX-5184 $this->oUpgrade->addPostUpgradeTask('Rebuild_Banner_Cache'); $this->logOnly("Appended timezone information to {$ret} time based delivery limitations"); return true; }
function migrateData() { if (!$this->init(OA_DB::singleton())) { return false; } if ($this->statsCompacted()) { return $this->migrateCompactStats(); } else { return $this->migrateRawStats(); } }
/** * A method that uses the getAllCampaigns() method to obtain all campaigns * that meet the requirements of this class. That is: * * - The campaign has an expiration date (that is not already passed); and * - As a result of the above, the campaign must have an activation date that has * passed, or has the default fake activation date; and * - The campaign is active, and has a priority of at least 1; and * - The campaign has inventory requirements for the duration of its activation. * * @access private * @return array An array of {@link OX_Maintenance_Priority_Campaign} objects. */ function _getValidCampaigns() { $conf = $GLOBALS['_MAX']['CONF']; // Get current date $oDate = new Date($this->_getDate()); $oDate->toUTC(); $dateYMD = $oDate->getDate(DATE_FORMAT_ISO); $oDbh = OA_DB::singleton(); $table = $oDbh->quoteIdentifier($conf['table']['prefix'] . $conf['table']['campaigns'], true); $aWheres = array(array("{$table}.priority >= 1", 'AND'), array("{$table}.status = " . OA_ENTITY_STATUS_RUNNING, 'AND'), array("{$table}.expire_time >= '{$dateYMD}'", 'AND'), array("({$table}.views > 0 OR {$table}.clicks > 0 OR {$table}.conversions > 0)", 'AND')); return $this->_getAllCampaigns($aWheres); }
/** * The constructor method. */ function Test_OX_Dal_Maintenance_Statistics_manageCampaigns() { $this->UnitTestCase(); $this->doCampaigns = OA_Dal::factoryDO('campaigns'); $this->doClients = OA_Dal::factoryDO('clients'); $this->doBanners = OA_Dal::factoryDO('banners'); $this->doDIA = OA_Dal::factoryDO('data_intermediate_ad'); $this->oDbh =& OA_DB::singleton(); // Set the maintenance operation interval to 60 minutes $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; }