Commit 3bf1442d by Vladislav

#20364 Загрузка и синхронизация расширений

1 parent beb1867e
...@@ -208,6 +208,44 @@ class DictionaryCampaignsSyncByCampaign extends Command ...@@ -208,6 +208,44 @@ class DictionaryCampaignsSyncByCampaign extends Command
and (ad.v_card_external_id is null or (ad.v_card_external_id is not null and vc.id is not null)) and (ad.v_card_external_id is null or (ad.v_card_external_id is not null and vc.id is not null))
"); ");
//обновляем связи целевых объявлений.
DB::insert("
UPDATE goal_advertisements gad
INNER JOIN advertisements ad on ad.id = gad.advertisement_id
INNER JOIN ad_groups ag on ad.ad_group_id = ag.id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
INNER JOIN dictionaries d on gag.dictionary_campaign_id = d.id
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id
LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gag.dictionary_campaign_id = gvc.dictionary_campaign_id
LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id
LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id
SET gad.goal_v_card_id = gvc.id,
gad.goal_v_card_external_id = gvc.external_id,
gad.goal_sitelink_id = gs.id,
gad.goal_sitelink_external_id = gs.external_id,
gad.updated_at = CURRENT_TIMESTAMP
WHERE (
(
gad.goal_sitelink_id != gs.id
or
(gad.goal_sitelink_id is null and gs.id is not null)
or
(gad.goal_sitelink_id is not null and gs.id is null)
)
or
(
gad.goal_v_card_id != gvc.id
or
(gad.goal_v_card_id is null and gvc.id is not null)
or
(gad.goal_v_card_id is not null and gvc.id is null)
)
)
");
//грузим связь объявлений к расширения которых по какой то причне нет в целевых. //грузим связь объявлений к расширения которых по какой то причне нет в целевых.
DB::insert(" DB::insert("
INSERT INTO goal_advertisement_goal_ad_extensions(goal_advertisement_id, goal_ad_extension_id, created_at, updated_at) INSERT INTO goal_advertisement_goal_ad_extensions(goal_advertisement_id, goal_ad_extension_id, created_at, updated_at)
...@@ -223,6 +261,16 @@ class DictionaryCampaignsSyncByCampaign extends Command ...@@ -223,6 +261,16 @@ class DictionaryCampaignsSyncByCampaign extends Command
WHERE gagae.goal_ad_extension_id is null WHERE gagae.goal_ad_extension_id is null
"); ");
//Удаляем лишнии связи объявлений к расширениям.
DB::insert("
DELETE goal_advertisement_goal_ad_extensions
FROM goal_advertisement_goal_ad_extensions
INNER JOIN goal_advertisements ga on goal_advertisement_goal_ad_extensions.goal_advertisement_id = ga.id
INNER JOIN goal_ad_extensions gae on goal_advertisement_goal_ad_extensions.goal_ad_extension_id = gae.id
INNER JOIN advertisements a on ga.advertisement_id = a.id
LEFT JOIN advertisement_ad_extensions aae on a.id = aae.advertisement_id and gae.ad_extension_id = aae.ad_extension_id
WHERE aae.ad_extension_id is null");
//грузим расширения которых по какой то причне нет в целевых. //грузим расширения которых по какой то причне нет в целевых.
DB::insert(" DB::insert("
INSERT INTO goal_retargetinglists(retargetinglist_id, token_id, created_at, updated_at) INSERT INTO goal_retargetinglists(retargetinglist_id, token_id, created_at, updated_at)
......
...@@ -85,7 +85,7 @@ class GetAds extends DirectRequest ...@@ -85,7 +85,7 @@ class GetAds extends DirectRequest
$ad_group = $ad_groups->get((string)$ad['AdGroupId']); $ad_group = $ad_groups->get((string)$ad['AdGroupId']);
if (!$ad_group) if (!$ad_group || !$ad_group->campaign)
continue; continue;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!