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 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; }
/** * A method to test when there are no old format raw requests, * impressions and clicks. */ function testNoData() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; // Prepare an array of the required tables used in testing $aTables = array($aConf['table']['prefix'] . $aConf['table']['data_raw_ad_request'] => $aConf['table']['prefix'] . 'data_bkt_r', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'] => $aConf['table']['prefix'] . 'data_bkt_m', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_click'] => $aConf['table']['prefix'] . 'data_bkt_c'); // Install the openXDeliveryLog plugin, which will create the // data bucket tables required for testing TestEnv::installPluginPackage('openXDeliveryLog', false); // Ensure that there are no old format raw data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Ensure that there are no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Run the migration of raw data DAL code for a given OI $oStart = new Date('2009-01-09 12:00:00'); $oEnd = new Date('2009-01-09 12:59:59'); $this->oDal->migrateRawRequests($oStart, $oEnd); $this->oDal->migrateRawImpressions($oStart, $oEnd); $this->oDal->migrateRawClicks($oStart, $oEnd); // Re-test that there are still no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Uninstall the installed plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test environment configuration TestEnv::restoreConfig(); }
function outdateSession() { $sessionId = SESSIONID; $prefix = OA_Dal::getTablePrefix(); $table = $this->dbh->quoteIdentifier($prefix . 'session'); $this->dbh->exec("UPDATE {$table} set lastused = '2005-01-01 01:00:00' WHERE sessionid = '{$sessionId}'"); }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $this->prefix = $aConf['prefix']; $this->tblPreferences = $aConf['prefix'] . ($aConf['preferences'] ? $aConf['preferences'] : 'preferences'); $query = "INSERT INTO " . $this->oDbh->quoteIdentifier($this->tblPreferences, true) . "\n (preference_name, account_type)\n VALUES('campaign_ecpm_enabled', 'MANAGER')"; $ret = $this->oDbh->query($query); //check for error if (PEAR::isError($ret)) { $this->logError($ret->getUserInfo()); return false; } $this->logOnly("Added 'campaign_ecpm_enabled' preference to 'MANAGER' account"); return true; }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $prefix = $aConf['prefix']; $tblBanners = $prefix . ($aConf['banners'] ? $aConf['banners'] : 'banners'); $tblAza = $prefix . ($aConf['ad_zone_assoc'] ? $aConf['ad_zone_assoc'] : 'ad_zone_assoc'); $query = "\n SELECT\n bannerid,\n 0 AS zoneid,\n " . MAX_AD_ZONE_LINK_DIRECT . " AS link_type\n FROM\n " . $this->oDbh->quoteIdentifier($tblBanners, true) . " b LEFT JOIN\n " . $this->oDbh->quoteIdentifier($tblAza, true) . " aza ON (b.bannerid = aza.ad_id AND aza.zone_id = 0)\n WHERE\n aza.ad_id IS NULL\n "; $query = "\n INSERT INTO " . $this->oDbh->quoteIdentifier($tblAza, true) . "\n (ad_id, zone_id, link_type)\n " . $query; $ret = $this->oDbh->exec($query); //check for error if (PEAR::isError($ret)) { $this->logError($ret->getUserInfo()); return false; } $this->logOnly("Added {$ret} missing banner links to zone 0"); return true; }
function _getQuotedTableName($table) { $table = $this->getPrefix() . ($GLOBALS['_MAX']['CONF']['table'][$table] ? $GLOBALS['_MAX']['CONF']['table'][$table] : $table); $quoted = $this->oDBH->quoteIdentifier($table, true); if (PEAR::isError($quoted)) { $this->_logError('Error quoting identifier: ' . $quoted->getUserInfo()); return $table; } return $quoted; }
function execute($aParams) { // Insert the required application variable flag to ensure that // when the maintenance script next runs, it will process all // raw data into the new bucket format, so that any raw data not // previously summarised will be accounted for $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $this->tblApplicationVariable = $aConf['prefix'] . ($aConf['application_variable'] ? $aConf['application_variable'] : 'application_variable'); $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($this->tblApplicationVariable, true) . "\n (\n name,\n value\n )\n VALUES\n (\n 'mse_process_raw',\n '1'\n )"; $this->logOnly("Setting application variable flag to ensure ME processes old sytle raw data on next run..."); $rs = $this->oDbh->exec($query); // Check for errors if (PEAR::isError($rs)) { $this->logError($rs->getUserInfo()); return false; } $this->logOnly("Application variable flag to ensure ME processes old sytle raw data on next run correctly set."); return true; }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; // Recompile the delivery limitations to update the compiled limitations as well $this->oUpgrade->addPostUpgradeTask('Recompile_Acls'); $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $this->prefix = $aConf['prefix']; $this->tblPreferences = $aConf['prefix'] . ($aConf['preferences'] ? $aConf['preferences'] : 'preferences'); $this->tblAccountPreferenceAssoc = $aConf['prefix'] . ($aConf['account_preference_assoc'] ? $aConf['account_preference_assoc'] : 'account_preference_assoc'); $query = "SELECT preference_id\n FROM " . $this->oDbh->quoteIdentifier($this->tblPreferences, true) . "\n WHERE preference_name = 'auto_alter_html_banners_for_click_tracking'"; $rs = $this->oDbh->query($query); //check for error if (PEAR::isError($rs)) { $this->logError($rs->getUserInfo()); return false; } $preferenceId = $rs->fetchRow(MDB2_FETCHMODE_ASSOC); $preferenceId = $preferenceId['preference_id']; if (!empty($preferenceId)) { $sql = "DELETE FROM " . $this->oDbh->quoteIdentifier($this->tblAccountPreferenceAssoc, true) . " WHERE preference_id = {$preferenceId}"; $rs = $this->oDbh->exec($sql); //check for error if (PEAR::isError($rs)) { $this->logError($rs->getUserInfo()); return false; } $this->logOnly("Removed entries in account_preferences_assoc table related to auto_alter_html_banners_for_click_tracking"); $sql = "DELETE FROM " . $this->oDbh->quoteIdentifier($this->tblPreferences, true) . " WHERE preference_id = {$preferenceId}"; $rs = $this->oDbh->exec($sql); //check for error if (PEAR::isError($rs)) { $this->logError($rs->getUserInfo()); return false; } $this->logOnly("Removed auto_alter_html_banners_for_click_tracking preference in preferences table"); } return true; }
/** * Update the "Administrator Account" account to "System Administrator", if * it still exists for the user, for improved understanding of the account * purpose */ function _updateAdministratorAccountToSystemAdministrator() { $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $this->logOnly("Attempting to rename the 'Administrator Account' account to 'System Administrator' in the 'accounts' table"); $tblAccounts = $aConf['prefix'] . ($aConf['accounts'] ? $aConf['accounts'] : 'accounts'); $query = "UPDATE " . $this->oDbh->quoteIdentifier($tblAccounts, true) . " SET account_name = 'System Administrator' WHERE account_name = 'Administrator account'"; $result = $this->oDbh->query($query); if (!PEAR::isError($result)) { $this->logOnly("Renamed the old 'Administrator Account' account in the 'accounts' table"); } else { $this->logError("Failed to rename the old 'Administrator Account' account in the 'accounts' table"); } }
/** * 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']); } } }
/** * Create a VIEW */ public function createView($view_name, $table_name) { $query = 'CREATE VIEW ' . $this->db->quoteIdentifier($view_name, true) . ' (id) AS SELECT id FROM ' . $this->db->quoteIdentifier($table_name, true) . ' WHERE id > 1'; return $this->db->exec($query); }
/** * A method to test when there are old format raw requests, * impressions and clicks, in the operation interval being * migrated. */ function testComplexValidData() { $aConf =& $GLOBALS['_MAX']['CONF']; $aConf['maintenance']['operationInterval'] = 60; // Prepare an array of the required tables used in testing $aTables = array($aConf['table']['prefix'] . $aConf['table']['data_raw_ad_request'] => $aConf['table']['prefix'] . 'data_bkt_r', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_impression'] => $aConf['table']['prefix'] . 'data_bkt_m', $aConf['table']['prefix'] . $aConf['table']['data_raw_ad_click'] => $aConf['table']['prefix'] . 'data_bkt_c'); // Install the openXDeliveryLog plugin, which will create the // data bucket tables required for testing TestEnv::installPluginPackage('openXDeliveryLog', false); // Ensure that there are no old format raw data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Ensure that there are no new format bucket data foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 0); } // Insert some old style raw data in an operation interval // that will not be migrated foreach ($aTables as $rawTable => $bucketTable) { $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 11:30:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); } // Ensure that the old format raw data was inserted correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 1); } // Insert some old style raw data in an operation interval // that will be migrated foreach ($aTables as $rawTable => $bucketTable) { $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:30:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:31:00',\n 1,\n 0,\n 1\n )"; $this->oDbh->exec($query); $query = "\n INSERT INTO\n " . $this->oDbh->quoteIdentifier($rawTable, true) . "\n (\n date_time,\n ad_id,\n creative_id,\n zone_id\n )\n VALUES\n (\n '2009-01-09 12:32:00',\n 2,\n 0,\n 3\n )"; $this->oDbh->exec($query); } // Ensure that the old format raw data was inserted correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($rawTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 4); } // Run the migration of raw data DAL code for a given OI $oStart = new Date('2009-01-09 12:00:00'); $oEnd = new Date('2009-01-09 12:59:59'); $this->oDal->migrateRawRequests($oStart, $oEnd); $this->oDal->migrateRawImpressions($oStart, $oEnd); $this->oDal->migrateRawClicks($oStart, $oEnd); // Test that the data was migrated correctly foreach ($aTables as $rawTable => $bucketTable) { $query = "\n SELECT\n COUNT(*) AS count\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['count'], 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true); $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true) . "\n WHERE\n creative_id = 1"; $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['interval_start'], '2009-01-09 12:00:00'); $this->assertEqual($aRow['creative_id'], 1); $this->assertEqual($aRow['zone_id'], 1); $this->assertEqual($aRow['count'], 2); $query = "\n SELECT\n *\n FROM\n " . $this->oDbh->quoteIdentifier($bucketTable, true) . "\n WHERE\n creative_id = 2"; $rsResult = $this->oDbh->query($query); $this->assertNotA($rsReults, 'PEAR_Error'); $rows = $rsResult->numRows(); $this->assertEqual($rows, 1); $aRow = $rsResult->fetchRow(); $this->assertEqual($aRow['interval_start'], '2009-01-09 12:00:00'); $this->assertEqual($aRow['creative_id'], 2); $this->assertEqual($aRow['zone_id'], 3); $this->assertEqual($aRow['count'], 1); } // Uninstall the installed plugin TestEnv::uninstallPluginPackage('openXDeliveryLog', false); // Restore the test environment configuration TestEnv::restoreConfig(); }
function execute($aParams) { $this->oUpgrade =& $aParams[0]; $this->oDbh =& OA_DB::singleton(); $aConf = $GLOBALS['_MAX']['CONF']['table']; $this->prefix = $aConf['prefix']; $this->tblCampaigns = $aConf['prefix'] . ($aConf['campaigns'] ? $aConf['campaigns'] : 'campaigns'); $this->queryUpdateTemplate = "UPDATE " . $this->oDbh->quoteIdentifier($this->tblCampaigns, true) . "\n SET revenue_type = %s\n WHERE campaignid in (%s)"; $query = 'SELECT campaignid, clicks, conversions FROM ' . $this->oDbh->quoteIdentifier($this->tblCampaigns, true) . ' c WHERE c.revenue_type IS NULL '; $rs = $this->oDbh->query($query); //check for error if (PEAR::isError($rs)) { $this->logError($rs->getUserInfo()); return false; } /* process campaigns and derive the revenue_type from set limits if (conversions set) -> revenue type is CPA else if (clicks set) -> revenue type is CPC else if (impressions set) -> revenue type is CPM else -> default to CPM */ $aCPMCampaigns = array(); $aCPCCampaigns = array(); $aCPACampaigns = array(); while ($aCampaign = $rs->fetchRow(MDB2_FETCHMODE_ASSOC)) { if ($aCampaign['conversions'] > 0) { $aCPACampaigns[] = $aCampaign['campaignid']; } else { if ($aCampaign['clicks'] > 0) { $aCPCCampaigns[] = $aCampaign['campaignid']; } else { //views set or no limits CPM as well $aCPMCampaigns[] = $aCampaign['campaignid']; } } } /* update campaigns accordingly 'MAX_FINANCE_CPM', 1); 'MAX_FINANCE_CPC', 2); 'MAX_FINANCE_CPA', 3); */ $cpmCount = count($aCPMCampaigns); $cpcCount = count($aCPCCampaigns); $cpaCount = count($aCPACampaigns); $count = $cpmCount + $cpcCount + $cpaCount; $this->logOnly("Found " + $count + " campaign(s) to set missing revenue type: " + ($cpmCount > 0 ? "{$cpmCount} to CPM," : '') + ($cpcCount > 0 ? "{$cpcCount} to CPC," : '') + ($cpaCount > 0 ? "{$cpaCount} to CPA" : '')); if ($cpmCount > 0) { $query = sprintf($this->queryUpdateTemplate, MAX_FINANCE_CPM, implode(',', $aCPMCampaigns)); $result = $this->oDbh->exec($query); if (PEAR::isError($result)) { $this->logError($result->getUserInfo()); return false; } else { $this->logOnly("Successfully updated 'revenue_type' of {$result} campaign(s) to CPM"); } } if ($cpcCount > 0) { $query = sprintf($this->queryUpdateTemplate, MAX_FINANCE_CPC, implode(',', $aCPCCampaigns)); $result = $this->oDbh->exec($query); if (PEAR::isError($result)) { $this->logError($result->getUserInfo()); return false; } else { $this->logOnly("Successfully updated 'revenue_type' of {$result} campaign(s) to CPC"); } } if ($cpaCount > 0) { $query = sprintf($this->queryUpdateTemplate, MAX_FINANCE_CPA, implode(',', $aCPACampaigns)); $result = $this->oDbh->exec($query); if (PEAR::isError($result)) { $this->logError($result->getUserInfo()); return false; } else { $this->logOnly("Successfully updated 'revenue_type' of {$result} campaign(s) to CPA"); } } return true; }
/** * Delimited identifiers are a nightmare with InterBase, so they're disabled * * @param string $str identifier name to be quoted * @param bool $check_option check the 'quote_identifier' option * * @return string quoted identifier string * * @access public */ function quoteIdentifier($str, $check_option = false) { if ($check_option && !$this->options['quote_identifier']) { return $str; } return parent::quoteIdentifier(strtoupper($str), $check_option); }
/** * Inserts associations between zone and ad objects (campaign or banner) * represented by this handler. * * @param MDB2_Driver_Common $oDbh */ function insertAssocs($oDbh) { $assocTable = $oDbh->quoteIdentifier($this->prefix . $this->getAssocTable(), true); $adObjectColumn = $this->getAdObjectColumn(); $aResult = array(); foreach ($this->aAdObjectIds as $adObjectId) { if (is_numeric($adObjectId)) { $sql = "\n INSERT INTO {$assocTable} (zone_id, {$adObjectColumn})\n VALUES ({$this->zone_id}, {$adObjectId})"; $result = $oDbh->exec($sql); if (PEAR::isError($result)) { return $result; } } else { $aResult[] = 'Invalid data found during migration_tables_core_127: ' . $sql; } } return count($aResult) ? $aResult : true; }
function _getTablename($tableName) { return $this->oDbh->quoteIdentifier($this->_getTablenameUnquoted($tableName), true); }