function OA_Dal_Delivery_getLinkedAds($search, $campaignid = '', $lastpart = true) { $conf = $GLOBALS['_MAX']['CONF']; // Sanitise parameteres $campaignid = (int) $campaignid; if ($campaignid > 0) { $precondition = " AND d.campaignid = '" . $campaignid . "' "; } else { $precondition = ''; } $aRows['xAds'] = array(); $aRows['cAds'] = array(); $aRows['clAds'] = array(); $aRows['ads'] = array(); $aRows['lAds'] = array(); $aRows['count_active'] = 0; $aRows['zone_companion'] = false; $aRows['count_active'] = 0; $totals = array('xAds' => 0, 'cAds' => 0, 'clAds' => 0, 'ads' => 0, 'lAds' => 0); $query = OA_Dal_Delivery_buildQuery($search, $lastpart, $precondition); $rAds = OA_Dal_Delivery_query($query); if (!is_resource($rAds)) { if (defined('OA_DELIVERY_CACHE_FUNCTION_ERROR')) { return OA_DELIVERY_CACHE_FUNCTION_ERROR; } else { return null; } } // Get timezone data $aTimezones = MAX_cacheGetAccountTZs(); while ($aAd = OA_Dal_Delivery_fetchAssoc($rAds)) { // Add timezone if (isset($aAd['account_id']) && isset($aTimezones['aAccounts'][$aAd['account_id']])) { $aAd['timezone'] = $aTimezones['aAccounts'][$aAd['account_id']]; } else { $aAd['timezone'] = $aTimezones['default']; } // Is the ad Exclusive, Low, or Normal Priority? if ($aAd['campaign_priority'] == -1) { // Ad is in an exclusive placement $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight']; $aRows['xAds'][$aAd['ad_id']] = $aAd; $aRows['count_active']++; $totals['xAds'] += $aAd['priority']; } elseif ($aAd['campaign_priority'] == 0) { // Ad is in a low priority placement $aAd['priority'] = $aAd['campaign_weight'] * $aAd['weight']; $aRows['lAds'][$aAd['ad_id']] = $aAd; $aRows['count_active']++; $totals['lAds'] += $aAd['priority']; } elseif ($aAd['campaign_priority'] == -2) { // Ad is in a low priority eCPM placement $aRows['eAds'][$aAd['ad_id']] = $aAd; $aRows['count_active']++; } else { // Ad is in a paid placement $aRows['ads'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd; $aRows['count_active']++; } // Also store Companion ads in additional array if ($aAd['campaign_companion'] == 1) { if ($aAd['campaign_priority'] == 0) { // Store a low priority companion ad $aRows['zone_companion'][] = $aAd['placement_id']; $aRows['clAds'][$aAd['ad_id']] = $aAd; $totals['clAds'] += $aAd['priority']; } else { // Store a paid priority companion ad $aRows['zone_companion'][] = $aAd['placement_id']; $aRows['cAds'][$aAd['campaign_priority']][$aAd['ad_id']] = $aAd; } } } // If there are exclusive ads, sort by priority if (isset($aRows['xAds']) && is_array($aRows['xAds'])) { $totals['xAds'] = _setPriorityFromWeights($aRows['xAds']); } // If there are paid ads, prepare array of priority totals // to allow delivery to do the scaling work later if (isset($aRows['ads']) && is_array($aRows['ads'])) { $totals['ads'] = _getTotalPrioritiesByCP($aRows['ads']); } // If there are low priority ads, sort by priority if (isset($aRows['lAds']) && is_array($aRows['lAds'])) { $totals['lAds'] = _setPriorityFromWeights($aRows['lAds']); } // If there are paid companion ads, prepare array of priority totals // to allow delivery to do the scaling work later if (isset($aRows['cAds']) && is_array($aRows['cAds'])) { $totals['cAds'] = _getTotalPrioritiesByCP($aRows['cAds']); } // If there are low priority companion ads, sort by priority if (isset($aRows['clAds']) && is_array($aRows['clAds'])) { $totals['clAds'] = _setPriorityFromWeights($aRows['clAds']); } $aRows['priority'] = $totals; return $aRows; }
/** * Creates all possible delivert cache files * * @param array $aIds array of DB Ids returned by _createTestData * @see _createTestData */ function _createTestCacheFiles($aIds) { // Create cache files not related to DB Objects MAX_cacheGetAccountTZs(); MAX_cacheCheckIfMaintenanceShouldRun(); MAX_cacheGetGoogleJavaScript(); // Create cache files for banners and images foreach ($aIds['banners'] as $bannerId) { MAX_cacheGetAd($bannerId); } foreach ($aIds['images'] as $filename) { MAX_cacheGetCreative($filename); } // Create cache files for zones foreach ($aIds['zones'] as $zoneId) { MAX_cacheGetZoneLinkedAds($zoneId); MAX_cacheGetZoneInfo($zoneId); } // Create cache files for websites foreach ($aIds['affiliates'] as $affiliateid) { OA_cacheGetPublisherZones($affiliateid); } // Create cache files for trackers foreach ($aIds['trackers'] as $trackerid) { MAX_cacheGetTracker($trackerid); MAX_cacheGetTrackerVariables($trackerid); } // Create cache files for channels foreach ($aIds['channel'] as $channelid) { MAX_cacheGetChannelLimitations($channelid); } // cache files for direct-selection are not created // due to problems with invalidating MAX_cacheGetLinkedAds }
/** * Method tests invalidateSystemSettingsCache method */ function test_invalidateSystemSettingsCache() { $interval = $GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] * 60; $delay = intval($GLOBALS['_MAX']['CONF']['maintenance']['operationInterval'] / 12 * 60); // store orginal settings $currentClick = $GLOBALS['_MAX']['CONF']['file']['click']; // Set maintenace timestamp to 48h ago $doAppVar = OA_Dal::factoryDO('application_variable'); $doAppVar->name = 'maintenance_timestamp'; $doAppVar->value = MAX_commonGetTimeNow() - 2 * $interval; $doAppVar->insert(); // Remember current cache $cachedJSData = MAX_cacheGetGoogleJavaScript(); $cachedTZData = MAX_cacheGetAccountTZs(); $cachedMaintenanceData = MAX_cacheCheckIfMaintenanceShouldRun(); // Change JS settings, Time Zone, and time of Last Run of maintenace $GLOBALS['_MAX']['CONF']['file']['click'] = 'click.php'; $doAppVar->name = 'maintenance_timestamp'; $doAppVar->value = MAX_commonGetTimeNow() + $delay + 1; $doAppVar->update(); // Add Admin user and set time zone in his preferences $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->account_type = 'ADMIN'; $accountId = DataGenerator::generateOne($doAccount); $doPreferences = OA_Dal::factoryDO('preferences'); $doPreferences->preference_name = 'timezone'; $doPreferences->value = 'new value'; $doPreferences->account_type = 'ADMIN'; $preferencesId = DataGenerator::generateOne($doPreferences); $doAccountPreferenceAssoc = OA_Dal::factoryDO('account_preference_assoc'); $doAccountPreferenceAssoc->account_id = $accountId; $doAccountPreferenceAssoc->preference_id = $preferencesId; $doAccountPreferenceAssoc->value = 'new value'; DataGenerator::generateOne($doAccountPreferenceAssoc); // Expect no changes in cache files $this->assertEqual(MAX_cacheGetGoogleJavaScript(), $cachedJSData); $this->assertEqual(MAX_cacheGetAccountTZs(), $cachedTZData); $this->assertEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedMaintenanceData); $this->oDeliveryCacheManager->invalidateSystemSettingsCache(); // Now expect changes in cache files $this->assertNotEqual(MAX_cacheGetGoogleJavaScript(), $cachedJSData); $this->assertNotEqual(MAX_cacheGetAccountTZs(), $cachedTZData); $this->assertNotEqual(MAX_cacheCheckIfMaintenanceShouldRun(), $cachedMaintenanceData); // restore orginal settings $GLOBALS['_MAX']['CONF']['file']['click'] = $currentClick; }
/** * Method tests invalidateGetAccountTZsCache method */ function test_invalidateGetAccountTZsCache() { $cachedData = MAX_cacheGetAccountTZs(); // Add Admin user and set time zone in his preferences $doAccount = OA_Dal::factoryDO('accounts'); $doAccount->account_type = 'ADMIN'; $accountId = DataGenerator::generateOne($doAccount); $doPreferences = OA_Dal::factoryDO('preferences'); $doPreferences->preference_name = 'timezone'; $doPreferences->value = 'new value'; $doPreferences->account_type = 'ADMIN'; $preferencesId = DataGenerator::generateOne($doPreferences); $doAccountPreferenceAssoc = OA_Dal::factoryDO('account_preference_assoc'); $doAccountPreferenceAssoc->account_id = $accountId; $doAccountPreferenceAssoc->preference_id = $preferencesId; $doAccountPreferenceAssoc->value = 'new value'; DataGenerator::generateOne($doAccountPreferenceAssoc); // Expect no changes in cache $this->assertEqual(MAX_cacheGetAccountTZs(), $cachedData); $this->oDeliveryCacheCommon->invalidateGetAccountTZsCache(); // Now expect changes in cache $this->assertNotEqual(MAX_cacheGetAccountTZs(), $cachedData); }