Beispiel #1
0
 public function updateCampaignManual($campaignId = null)
 {
     $newCampaigns = array();
     $res = array('added' => 0, 'updated' => 0, 'error' => 0);
     $keys = array();
     if (!is_array($campaignId) && $campaignId > 0) {
         $campaignId = array($campaignId);
     }
     if (is_array($campaignId) && count($campaignId) > 0) {
         $dbRes = YandexCampaignTable::getList(array('filter' => array('=ID' => $campaignId, '=ENGINE_ID' => $this->getId()), 'select' => array('XML_ID')));
         while ($campaign = $dbRes->fetch()) {
             $keys[] = $campaign['XML_ID'];
         }
     } else {
         $campaignList = $this->getCampaignList();
         foreach ($campaignList as $campaignInfo) {
             $keys[] = $campaignInfo['CampaignID'];
         }
     }
     if (count($keys) > 0) {
         $campaignList = $this->getCampaign($keys);
         $campaignListSorted = array();
         foreach ($campaignList as $campaignInfo) {
             $campaignListSorted[$campaignInfo['CampaignID']] = $campaignInfo;
         }
         $dbCampaigns = YandexCampaignTable::getList(array('filter' => array('=XML_ID' => array_keys($campaignListSorted), '=ENGINE_ID' => $this->getId())));
         YandexCampaignTable::setSkipRemoteUpdate(true);
         while ($campaign = $dbCampaigns->fetch()) {
             if (isset($campaignListSorted[$campaign['XML_ID']])) {
                 $result = YandexCampaignTable::update($campaign['ID'], array("SETTINGS" => $campaignListSorted[$campaign['XML_ID']]));
                 unset($campaignListSorted[$campaign['XML_ID']]);
                 if ($result->isSuccess()) {
                     $res['updated']++;
                 } else {
                     $res['error']++;
                 }
             }
         }
         foreach ($campaignListSorted as $campaignId => $campaignInfo) {
             $result = YandexCampaignTable::add(array("SETTINGS" => $campaignInfo));
             if ($result->isSuccess()) {
                 $newCampaigns[] = $result->getId();
                 $res['added']++;
             } else {
                 $res['error']++;
             }
         }
         YandexCampaignTable::setSkipRemoteUpdate(false);
     }
     if (count($newCampaigns) > 0) {
         set_time_limit(300);
         $res['new'] = $newCampaigns;
         $res['banner'] = array();
         $cnt = ceil(count($newCampaigns) / static::MAX_CAMPAIGNS_BANNER_UPDATE);
         for ($i = 0; $i < $cnt; $i++) {
             $res['banner'] = array_merge($res['banner'], $this->updateBannersManual(array_slice($newCampaigns, $i * static::MAX_CAMPAIGNS_BANNER_UPDATE, static::MAX_CAMPAIGNS_BANNER_UPDATE)));
         }
         if (count($newCampaigns) <= static::MAX_CAMPAIGNS_BANNER_UPDATE) {
             $res['banner'] = $this->updateBannersManual($newCampaigns);
         }
     }
     return $res;
 }
                            $engine->archiveCampaign($campaign['XML_ID']);
                            break;
                        case 'unarchive':
                            $engine->unArchiveCampaign($campaign['XML_ID']);
                            break;
                        case 'stop':
                            $engine->stopCampaign($campaign['XML_ID']);
                            break;
                        case 'resume':
                            $engine->resumeCampaign($campaign['XML_ID']);
                            break;
                    }
                    $campaignInfo = $engine->getCampaign(array($campaign['XML_ID']));
                    $campaignInfo = $campaignInfo[0];
                    Adv\YandexCampaignTable::setSkipRemoteUpdate(true);
                    $result = Adv\YandexCampaignTable::update($campaignId, array("SETTINGS" => $campaignInfo));
                    Adv\YandexCampaignTable::setSkipRemoteUpdate(false);
                    if (!$result->isSuccess()) {
                        $errorsList = $result->getErrorMessages();
                        foreach ($errorsList as $errorMessage) {
                            $adminList->AddGroupError($errorMessage, $campaignId);
                        }
                    }
                } catch (Engine\YandexDirectException $e) {
                    $adminList->AddGroupError($e->getCode() . ': ' . $e->getMessage());
                }
            }
        }
    }
}
$arHeaders = array(array("id" => "ID", "content" => Loc::getMessage("SEO_CAMPAIGN_ID"), "sort" => "ID", "default" => true), array("id" => "STATUS", "content" => Loc::getMessage('SEO_CAMPAIGN_STATUS'), "default" => true), array("id" => "NAME", "content" => Loc::getMessage('SEO_CAMPAIGN_NAME'), "sort" => "NAME", "default" => true), array("id" => "XML_ID", "content" => Loc::getMessage('SEO_CAMPAIGN_XML_ID'), "sort" => "XML_ID", "default" => true), array("id" => "STRATEGY", "content" => Loc::getMessage('SEO_CAMPAIGN_STRATEGY'), "default" => true), array("id" => "LAST_UPDATE", "content" => Loc::getMessage('SEO_CAMPAIGN_LAST_UPDATE'), "sort" => "LAST_UPDATE", "default" => true), array("id" => "BANNER_CNT", "content" => Loc::getMessage('SEO_CAMPAIGN_BANNER_CNT'), "default" => true), array("id" => "SHOW", "content" => Loc::getMessage('SEO_STATUS_SHOW'), "default" => true), array("id" => "SHOW", "content" => Loc::getMessage('SEO_STATUS_SHOW'), "default" => true), array("id" => "SUM", "content" => Loc::getMessage('SEO_CAMPAIGN_SUM'), "default" => true), array("id" => "REST", "content" => Loc::getMessage('SEO_CAMPAIGN_REST'), "default" => true), array("id" => "SHOWS", "content" => Loc::getMessage('SEO_CAMPAIGN_SHOWS'), "default" => true), array("id" => "CLICKS", "content" => Loc::getMessage('SEO_CAMPAIGN_CLICKS'), "default" => true));
			$campaignSettings['Strategy'],
			$request["STRATEGY_SETTINGS"][$campaignSettings['Strategy']['StrategyName']]
		);
	}

	$campaignSettings['EmailNotification']['SendWarn'] = $campaignSettings['EmailNotification']['SendWarn'] == 'Y';

	$campaignSettings['MinusKeywords'] = preg_split("/[\\n,;]+\\s*/", $campaignSettings['MinusKeywords']);

	$campaignFields = array(
		"SETTINGS" => $campaignSettings
	);

	if($ID > 0)
	{
		$result = Adv\YandexCampaignTable::update($ID, $campaignFields);
	}
	else
	{
		$result = Adv\YandexCampaignTable::add($campaignFields);
	}

	if($result->isSuccess())
	{
		$ID = $result->getId();
		if($request["apply"]<>'')
		{
			LocalRedirect('/bitrix/admin/seo_search_yandex_direct_edit.php?lang='.LANGUAGE_ID.'&ID='.$ID.'&'.$tabControl->ActiveTabParam());
		}
		else
		{