else
					{
						$adminList->AddGroupError($e->getCode().': '.$e->getMessage());
					}
				}
			}
			Adv\YandexBannerTable::setSkipRemoteUpdate(false);
		}
		else
		{
			try
			{
				switch($_REQUEST['action'])
				{
					case 'stop':
						$engine->stopBanners($campaign['XML_ID'], array_keys($bannersList));
						break;

					case 'resume':
						$engine->resumeBanners($campaign['XML_ID'], array_keys($bannersList));
						break;

					case 'moderate':
						$engine->moderateBanners($campaign['XML_ID'], array_keys($bannersList));
						$engine->updateCampaignManual($campaign['ID']);
						break;

					case 'archive':
						$engine->archiveBanners($campaign['XML_ID'], array_keys($bannersList));
						break;
Exemple #2
0
 public static function checkQuantityAgent()
 {
     if (!IsModuleInstalled("catalog")) {
         return __CLASS__ . "::checkQuantityAgent();";
     }
     $dbRes = YandexBannerTable::getList(array('filter' => array(array('=AUTO_QUANTITY_ON' => YandexBannerTable::MARKED), array('=AUTO_QUANTITY_OFF' => YandexBannerTable::MARKED), 'LOGIC' => "OR"), 'select' => array('ID', 'XML_ID', 'CAMPAIGN_ID', 'CAMPAIGN_XML_ID' => 'CAMPAIGN.XML_ID', 'AUTO_QUANTITY_ON', 'AUTO_QUANTITY_OFF')));
     $engine = new YandexDirect();
     $bannersListToStop = array();
     $bannersListToResume = array();
     $bannersListToUnMarkStopped = array();
     $bannersListToUnMarkResumed = array();
     $bannersLogData = array();
     while ($banner = $dbRes->fetch()) {
         if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToResume[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToResume[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_ON;
             if ($banner["AUTO_QUANTITY_OFF"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkStopped[] = $banner["ID"];
             }
         } else {
             if (!isset($bannersListToResume[$banner["CAMPAIGN_XML_ID"]])) {
                 $bannersListToStop[$banner["CAMPAIGN_XML_ID"]] = array();
             }
             $bannersListToStop[$banner["CAMPAIGN_XML_ID"]][$banner["ID"]] = $banner["XML_ID"];
             $causeCode = AutologTable::CODE_QUANTITY_OFF;
             if ($banner["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED) {
                 $bannersListToUnMarkResumed[] = $banner["ID"];
             }
         }
         $bannersLogData[$banner["ID"]] = array('CAMPAIGN_ID' => $banner['CAMPAIGN_ID'], 'CAMPAIGN_XML_ID' => $banner['CAMPAIGN_XML_ID'], 'BANNER_ID' => $banner['ID'], 'BANNER_XML_ID' => $banner['XML_ID'], 'CAUSE_CODE' => $causeCode);
     }
     if (count($bannersLogData) > 0) {
         foreach ($bannersListToResume as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->resumeBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkResumed = array_merge($bannersListToUnMarkResumed, array_keys($bannersList));
             }
         }
         foreach ($bannersListToStop as $campaignId => $bannersList) {
             if (count($bannersList) > 0) {
                 $success = true;
                 try {
                     $engine->stopBanners($campaignId, array_values($bannersList));
                 } catch (YandexDirectException $e) {
                     $success = false;
                 }
                 foreach ($bannersList as $bannerId => $bannerXmlId) {
                     $logEntry = $bannersLogData[$bannerId];
                     $logEntry['ENGINE_ID'] = $engine->getId();
                     $logEntry['SUCCESS'] = $success ? AutologTable::SUCCESS : AutologTable::FAILURE;
                     AutologTable::add($logEntry);
                 }
                 $bannersListToUnMarkStopped = array_merge($bannersListToUnMarkStopped, array_keys($bannersList));
             }
         }
         if (count($bannersListToUnMarkStopped) > 0) {
             YandexBannerTable::unMarkStopped($bannersListToUnMarkStopped);
         }
         if (count($bannersListToUnMarkResumed) > 0) {
             YandexBannerTable::unMarkResumed($bannersListToUnMarkResumed);
         }
     }
     return __CLASS__ . "::checkQuantityAgent();";
 }