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; }
$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 { if($back_url == '') { LocalRedirect("/bitrix/admin/seo_search_yandex_direct.php?lang=".LANGUAGE_ID); }