Commit a564d7b1 by Vladislav

#20794 Сделать чтобы в целевых РК оставалась одна карточка

1 parent f09c1351
Showing with 8 additions and 16 deletions
......@@ -80,7 +80,6 @@ class GetAdGroups extends DirectRequest
}
$campaign_ids_synced_need = [];
$now = Carbon::now();
foreach ($response['result']['AdGroups'] as $ad_group) {
......@@ -118,7 +117,7 @@ class GetAdGroups extends DirectRequest
'serving_status' => $ad_group['ServingStatus'],
'restricted_region_ids' => $ad_group['RestrictedRegionIds'],
'updated_self' => null,
'updated_at' => $now,
'updated_at' => Carbon::now(),
'deleted_at' => null,
];
......@@ -169,6 +168,12 @@ class GetAdGroups extends DirectRequest
$negativeKeywordSharedSets_sync = $ad_group->negativeKeywordSharedSets()->sync($negative_keyword_shared_sets->pluck('id'));
}
}
if ($this->getToken()->isMain()) {
if (
!empty($this->getParams()['SelectionCriteria']['CampaignIds'])
&&
......@@ -178,7 +183,7 @@ class GetAdGroups extends DirectRequest
DB::update("UPDATE ad_groups ag
INNER JOIN campaigns ca ON ag.campaign_id = ca.id
SET ag.deleted_at = CURRENT_TIMESTAMP
SET ag.deleted_at = now()
WHERE ca.groups_loaded_at IS NOT NULL
AND ag.updated_at <= ca.groups_loaded_at
AND ag.deleted_at is null
......@@ -190,19 +195,6 @@ class GetAdGroups extends DirectRequest
]);
}
}
}
if ($this->getToken()->isMain()) {
if (isset($this->getParams()['SelectionCriteria']['CampaignIds'])) {
Campaigns::whereIn('external_id', $this->getParams()['SelectionCriteria']['CampaignIds'])
->update([
'groups_loaded_at' => Carbon::now(),
]);
}
if (count($campaign_ids_synced_need)) {
Campaigns::findMany(array_keys($campaign_ids_synced_need))->each(function (Campaigns $campaign) {
$campaign->dictionaryCampaigns()->update([
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!