Commit 2d380372 by Vladislav

#20794 Сделать чтобы в целевых РК оставалась одна карточка (удаление связеые сущности группы)

1 parent a9b8de18
......@@ -2,8 +2,10 @@
namespace App\Console\Commands;
use App\Models\Pivots\GoalAdGroup;
use App\Models\Tokens;
use App\Service\Requests\Direct\DeleteAdGroups;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
......@@ -34,7 +36,7 @@ class AdGroupsDelete extends Command
}
/**
* Execute the console command.
* Execute the console command.7
*
* @return int
*/
......@@ -48,8 +50,28 @@ class AdGroupsDelete extends Command
INNER JOIN dictionaries d ON d.id = c.dictionary_id
WHERE gag.external_id is not null
AND ag.deleted_at is not null
AND d.token_id=" . $token->id);
AND gag.deleted_at is null
AND d.token_id=" . $token->id . "
AND NOT EXISTS (
SELECT 1 FROM goal_advertisements as ga
WHERE gag.id = ga.goal_ad_group_id
AND ga.deleted_at is null
AND ga.external_id is not null
)
AND NOT EXISTS (
SELECT 1 FROM goal_keywords as gk
WHERE gag.id = gk.goal_ad_group_id
AND gk.external_id is not null
)
AND NOT EXISTS (
SELECT 1 FROM goal_audience_targets as gat
WHERE gag.id = gat.goal_ad_group_id
AND gat.deleted_at is null
AND gat.external_id is not null
)
");
$ids = [];
foreach ($result as $item) {
$ids[] = $item->external_id;
}
......@@ -58,6 +80,13 @@ class AdGroupsDelete extends Command
continue;
}
foreach (array_chunk($ids, 1000) as $items) {
GoalAdGroup::whereIn('external_id', $items)
->update([
'reserve_delete_at' => Carbon::now(),
]);
}
$request = new DeleteAdGroups();
$request->setToken($token)
->call([
......
......@@ -42,18 +42,12 @@ class AdvertisementsDelete extends Command
*/
public function handle()
{
$token = Tokens::firstWhere('type', '!=', Tokens::MAIN);
if ($token) {
$this->sendRequest($token, Advertisement::needDeleted()->forNotReserveDelete()->get());
}
$tokens = Tokens::has('dictionaryCampaignsEnabledForExternalSynchronized.goalAdvertisementsForNeedDeletedForNotReserveDelete')
$tokens = Tokens::has('dictionaryCampaignsEnabledForExternalSynchronized.goalAudienceTargetsNeedDeleteForNotReserveDelete')
->where('type', '!=', Tokens::MAIN)
->get();
foreach ($tokens as $token) {
$this->sendRequest($token, $token->dictionaryCampaignsEnabledForExternalSynchronized->pluck('goalAdvertisementsForNeedDeletedForNotReserveDelete')->collapse());
$this->sendRequest($token, $token->dictionaryCampaignsEnabledForExternalSynchronized->pluck('goalAudienceTargetsNeedDeleteForNotReserveDelete')->collapse());
}
return 0;
......@@ -66,7 +60,11 @@ class AdvertisementsDelete extends Command
return;
}
foreach (array_chunk($ads->pluck('external_id')->toArray(), 1000) as $items) {
$ids = $ads->pluck('external_id')->toArray();
dd($ids);
foreach (array_chunk($ids, 1000) as $items) {
if ($token->isMain()) {
Advertisement::whereIn('external_id', $items)
->update([
......@@ -83,7 +81,7 @@ class AdvertisementsDelete extends Command
$request = new DeleteAds();
$request->setToken($token)
->call([
'ids' => $ads->pluck('external_id')->toArray(),
'ids' => $ids,
]);
}
......
<?php
namespace App\Console\Commands;
use App\Models\Pivots\GoalAudienceTarget;
use App\Models\Tokens;
use App\Service\Requests\Direct\AddAudienceTargets;
use App\Service\Requests\Direct\DeleteAudienceTarget;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\HasMany;
class AudienceTargetsDelete extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'audiencetargets:delete';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Удаление созданных условий нацеливания на аудиторию с целевого аккаунта';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
* @throws \Exception
*/
public function handle()
{
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalSynchronized.goalAudienceTargetsNeedDeleteForNotReserveDelete')
->where('type', '!=', Tokens::MAIN)
->get();
foreach ($tokens as $token) {
$token->load([
'dictionaryCampaignsEnabledForExternalSynchronized.goalAudienceTargetsNeedDeleteForNotReserveDelete',
]);
$goalAudienceTargets = $token->dictionaryCampaignsEnabledForExternalSynchronized->pluck('goalAudienceTargetsNeedDeleteForNotReserveDelete')
->collapse();
$ids = $goalAudienceTargets->pluck('external_id')->toArray();
foreach (array_chunk($ids, 1000) as $items) {
GoalAudienceTarget::whereIn('external_id', $items)
->update([
'reserve_delete_at' => Carbon::now(),
]);
}
$request = new DeleteAudienceTarget();
$request->setToken($token)
->call([
'ids' => $ids,
]);
}
return 0;
}
}
......@@ -92,12 +92,13 @@ class DictionaryCampaignsSyncByCampaign extends Command
//грузим группы которых по какой то причне нет в целевых.
DB::insert("
INSERT INTO goal_ad_groups(ad_group_id, dictionary_campaign_external_id, dictionary_campaign_id, name, negative_keywords, created_at, updated_at)
SELECT a.id, dc.external_id, dc.id, a.name, a.negative_keywords, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM ad_groups a
INNER JOIN campaigns c on a.campaign_id = c.id
SELECT ag.id, dc.external_id, dc.id, ag.name, ag.negative_keywords, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM ad_groups ag
INNER JOIN campaigns c on ag.campaign_id = c.id
INNER JOIN dictionary_campaigns dc on c.id = dc.campaign_id
LEFT JOIN goal_ad_groups gag on a.id = gag.ad_group_id AND gag.dictionary_campaign_id=dc.id
LEFT JOIN goal_ad_groups gag on ag.id = gag.ad_group_id AND gag.dictionary_campaign_id=dc.id AND gag.deleted_at is null
WHERE gag.ad_group_id is null
AND ag.deleted_at is null
");
$this->info('goal_ad_groups successful!');
......@@ -109,7 +110,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
INNER JOIN negative_keyword_shared_sets nkss on agnkss.negative_keyword_shared_set_id = nkss.id and nkss.deleted_at is null
INNER JOIN goal_negative_keyword_shared_sets gnkss on nkss.id = gnkss.negative_keyword_shared_set_id
INNER JOIN ad_groups ag on agnkss.ad_group_id = ag.id and ag.deleted_at is null
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id AND gag.deleted_at is null
INNER JOIN dictionary_campaigns dc on gag.dictionary_campaign_id = dc.id
INNER JOIN dictionaries d on dc.dictionary_id = d.id and d.token_id = gnkss.token_id
LEFT JOIN goal_ad_group_goal_negative_keyword_shared_sets gaggnkss on gnkss.id = gaggnkss.goal_negative_keyword_shared_set_id and gag.id = gaggnkss.goal_ad_group_id
......@@ -123,8 +124,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
goal_ad_group_id, keyword_id, created_at, updated_at)
SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, k.id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM keywords k
INNER JOIN ad_groups ag on k.ad_group_id = ag.id
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
INNER JOIN ad_groups ag on k.ad_group_id = ag.id AND ag.deleted_at is null
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id AND gag.deleted_at is null
LEFT JOIN goal_keywords gk on k.id = gk.keyword_id AND gk.goal_ad_group_id=gag.id
WHERE gk.keyword_id is null AND k.deleted_at is null
");
......@@ -158,8 +159,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
goal_ad_group_id, advertisement_id, goal_v_card_id, goal_v_card_external_id, goal_sitelink_id, goal_sitelink_external_id, created_at, updated_at)
SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, ad.id, gvc.id, gvc.external_id, gs.id, gs.external_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM advertisements ad
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 ad_groups ag on ad.ad_group_id = ag.id AND ag.deleted_at is null
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id AND gag.deleted_at is null
INNER JOIN dictionaries d on gag.dictionary_campaign_id = d.id
LEFT JOIN goal_advertisements gad on ad.id = gad.advertisement_id AND gad.goal_ad_group_id=gag.id and gad.deleted_at is null
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id
......@@ -216,8 +217,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
DB::update("
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 and gad.dictionary_campaign_id = gag.dictionary_campaign_id
INNER JOIN ad_groups ag on ad.ad_group_id = ag.id and ag.deleted_at is null
INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id and gad.dictionary_campaign_id = gag.dictionary_campaign_id and gag.deleted_at is null
INNER JOIN dictionary_campaigns dc on gad.dictionary_campaign_id = dc.id
INNER JOIN dictionaries d on dc.dictionary_id = d.id
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id
......@@ -320,8 +321,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
INNER JOIN dictionaries d on dc.dictionary_id = d.id
INNER JOIN retargetinglists r on aut.retargetinglist_external_id = r.external_id
INNER JOIN goal_retargetinglists gr on r.id = gr.retargetinglist_id AND d.token_id = gr.token_id
LEFT JOIN ad_groups ag on c.id = ag.campaign_id AND aut.ad_group_id = ag.id
LEFT JOIN goal_ad_groups gag on dc.id = gag.dictionary_campaign_id AND ag.id = gag.ad_group_id
LEFT JOIN ad_groups ag on c.id = ag.campaign_id AND aut.ad_group_id = ag.id AND ag.deleted_at is null
LEFT JOIN goal_ad_groups gag on dc.id = gag.dictionary_campaign_id AND ag.id = gag.ad_group_id AND gag.deleted_at is null
LEFT JOIN goal_audience_targets gaut on aut.id = gaut.audience_target_id and gaut.dictionary_campaign_id = dc.id
WHERE gaut.audience_target_id is null
");
......@@ -335,8 +336,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
FROM bid_modifiers bm
INNER JOIN campaigns c on bm.campaign_id = c.id
INNER JOIN dictionary_campaigns dc on dc.campaign_id = c.id
LEFT JOIN ad_groups ag on c.id = ag.campaign_id AND bm.ad_group_id = ag.id
LEFT JOIN goal_ad_groups gag on dc.id = gag.dictionary_campaign_id AND ag.id = gag.ad_group_id
LEFT JOIN ad_groups ag on c.id = ag.campaign_id AND bm.ad_group_id = ag.id AND ag.deleted_at is null
LEFT JOIN goal_ad_groups gag on dc.id = gag.dictionary_campaign_id AND ag.id = gag.ad_group_id AND gag.deleted_at is null
LEFT JOIN goal_bid_modifiers gbm on bm.id = gbm.bid_modifier_id and gbm.dictionary_campaign_id = dc.id
WHERE gbm.bid_modifier_id is null
");
......
......@@ -46,8 +46,25 @@ class KeywordsDelete extends Command
INNER JOIN keywords k ON gk.keyword_id=k.id
INNER JOIN dictionary_campaigns c ON c.id=gk.dictionary_campaign_id
INNER JOIN dictionaries d ON d.id=c.dictionary_id
WHERE gk.external_id is not null and k.deleted_at is not null AND d.token_id=" . $token->id;
WHERE gk.external_id is not null
AND d.token_id=" . $token->id ."
AND (
(k.deleted_at is not null)
OR (
EXISTS (
SELECT 1 FROM goal_ad_groups as gag
INNER JOIN ad_groups as ag on gag.ad_group_id = ag.id
AND gag.deleted_at is null
AND ag.deleted_at is not null
WHERE gk.goal_ad_group_id = gag.id
)
)
)
";
$result = DB::select($sql);
$ids = [];
foreach ($result as $item) {
$ids[] = $item->external_id;
......
......@@ -16,6 +16,7 @@ use App\Console\Commands\AdvertisementsDelete;
use App\Console\Commands\AdvertisementsLoadUpdated;
use App\Console\Commands\AdvertisementsUpdate;
use App\Console\Commands\AudienceTargetsAdd;
use App\Console\Commands\AudienceTargetsDelete;
use App\Console\Commands\BidModifiersAdd;
use App\Console\Commands\BidModifiersDelete;
use App\Console\Commands\BidModifiersUpdate;
......@@ -78,6 +79,10 @@ class Kernel extends ConsoleKernel
//будет выгружено после того, как будут выгруены листы ретаргетинга и обновлено с учетом
//этого таблица целвых аудиториц нацеливания
$schedule->command(AudienceTargetsAdd::class)->hourlyAt(10);
/* должен быть перед AdGroupsDelete */
$schedule->command(AudienceTargetsDelete::class)->hourlyAt(10);
/* должен быть перед AdGroupsDelete */
$schedule->command(KeywordsDelete::class)->hourlyAt(10);
$schedule->command(RetargetinglistsLoad::class)->hourlyAt(5);
$schedule->command(RetargetinglistsUpdate::class)->hourlyAt(10);
......@@ -120,7 +125,6 @@ class Kernel extends ConsoleKernel
$schedule->command(KeywordsAdd::class)->hourlyAt(40);
$schedule->command(KeywordsUpdate::class)->hourlyAt(40);
$schedule->command(KeywordsDelete::class)->hourlyAt(40);
$schedule->command(AdvertisementsDelete::class)->hourlyAt(45);
$schedule->command(AdvertisementsAdd::class)->hourlyAt(50);
......
......@@ -73,8 +73,11 @@ class ProcessCallAPI implements ShouldQueue
} catch (\Exception $e) {
//TODO: надо отдельно выделить ошибки вызовов, за которые списываются баллы
//https://yandex.ru/dev/direct/doc/dg/concepts/errors.html
Log::debug($this->api->getParams());
Log::debug($e);
//Log::debug($this->api->getParams());
Log::debug('');
Log::debug("Token id: {$this->api->getToken()->getKey()}");
Log::debug("Service: {$this->api->getService()}");
Log::debug("Method: {$this->api->getMethod()}");
$limits->removeRezerv($this->limitId);
throw $e;
}
......
......@@ -56,7 +56,10 @@ class ProcessCallLimitedAPI implements ShouldQueue//, ShouldBeUnique
}catch(\Exception $e){
//нет свободных баллов, замораживаем до следующего часа
Log::debug($e);
Log::debug('');
Log::debug('Нет свободных баллов, замораживаем до следующего часа');
Log::debug($e->getMessage());
Log::debug('');
$this->reRunHour();
return;
}
......
......@@ -569,4 +569,9 @@ class DictionaryCampaign extends Pivot
});
}
public function goalAudienceTargetsNeedDeleteForNotReserveDelete()
{
return $this->goalAudienceTargets()->needDeleted()->forNotReserveDelete();
}
}
......@@ -75,6 +75,7 @@ class GoalAdGroup extends Pivot
'updated_self',
'reserve_create_at',
'reserve_update_at',
'reserve_delete_at',
];
protected $casts = [
......@@ -85,6 +86,7 @@ class GoalAdGroup extends Pivot
'updated_self' => 'datetime',
'reserve_create_at' => 'datetime',
'reserve_update_at' => 'datetime',
'reserve_delete_at' => 'datetime',
];
public $incrementing = true;
......@@ -105,6 +107,7 @@ class GoalAdGroup extends Pivot
'updated_self',
'reserve_create_at',
'reserve_update_at',
'reserve_delete_at',
];
}
......
......@@ -6,6 +6,7 @@ use App\Models\Advertisement;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
/**
* App\Models\Pivots\GoalAdvertisement
......@@ -219,7 +220,19 @@ class GoalAdvertisement extends Pivot
*/
public function scopeNeedDeleted($query)
{
return $query->whereNotNull('deleted_need');
return $query->where(function (Builder $query) {
return $query->whereNotNull('deleted_need');
})->orWhere(function (Builder $query) {
return $query->whereExists(function (\Illuminate\Database\Query\Builder $query) {
$query->select(DB::raw(1))
->from('goal_ad_groups')
->join('ad_groups', 'goal_ad_groups.ad_group_id', '=', 'ad_groups.id')
->whereNull('goal_ad_groups.deleted_at')
->whereNotNull('goal_ad_groups.external_id')
->whereNotNull('ad_groups.deleted_at')
->whereColumn('goal_advertisements.goal_ad_group_id', 'goal_ad_groups.id');
});
});
}
/**
......
......@@ -6,6 +6,7 @@ use App\Models\AudienceTarget;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
class GoalAudienceTarget extends Pivot
{
......@@ -28,6 +29,7 @@ class GoalAudienceTarget extends Pivot
'updated_need',
'reserve_create_at',
'reserve_update_at',
'reserve_delete_at',
];
protected $casts = [
......@@ -36,6 +38,7 @@ class GoalAudienceTarget extends Pivot
'updated_need' => 'datetime',
'reserve_create_at' => 'datetime',
'reserve_update_at' => 'datetime',
'reserve_delete_at' => 'datetime',
];
public $incrementing = true;
......@@ -56,6 +59,7 @@ class GoalAudienceTarget extends Pivot
'updated_need',
'reserve_create_at',
'reserve_update_at',
'reserve_delete_at',
];
}
......@@ -90,6 +94,32 @@ class GoalAudienceTarget extends Pivot
* @param Builder $query
* @return Builder
*/
public function scopeNeedDeleted($query)
{
return $query->forExternal()->whereExists(function (\Illuminate\Database\Query\Builder $query) {
$query->select(DB::raw(1))
->from('goal_ad_groups')
->join('ad_groups', 'goal_ad_groups.ad_group_id', '=', 'ad_groups.id')
->whereNull('goal_ad_groups.deleted_at')
->whereNotNull('goal_ad_groups.external_id')
->whereNotNull('ad_groups.deleted_at')
->whereColumn('goal_audience_targets.goal_ad_group_id', 'goal_ad_groups.id');
});
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeForNotReserveDelete($query)
{
return $query->whereNull('reserve_delete_at');
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeNeedUpdated($query)
{
return $query->whereNotNull('updated_need');
......
......@@ -61,6 +61,29 @@ class AddAds extends DirectRequest
$goalAd = $this->goalAds->get($key);
if (!isset($add_result['Id'])) {
if (
isset($add_result['Errors'][0]['Code'])
&&
$add_result['Errors'][0]['Code'] == 8800
&&
isset($add_result['Errors'][0]['Details'])
&&
$add_result['Errors'][0]['Details'] === 'Ad group not found'
) {
if ($this->getToken()->isMain()) {
Advertisement::where('id', $goalAd->id)
->forceDelete();
} else {
GoalAdvertisement::where('id', $goalAd->id)
->forceDelete();
}
continue;
}
Log::debug("AddAds, empty Id");
Log::debug($add_result);
Log::debug($this->getParams()['Ads'][$key]);
......
......@@ -33,37 +33,45 @@ class DeleteAdGroups extends DirectRequest
public function handle($response)
{
try {
if (!isset($response['result']['DeleteResults'])) {
return;
}
if (!isset($response['result']['DeleteResults'])) {
return;
}
foreach ($response['result']['DeleteResults'] as $key => $delete_result) {
if (!isset($delete_result['Id'])) {
Log::debug("DeleteAdGroups, empty Id");
Log::debug($delete_result);
Log::debug($this->getParams()['SelectionCriteria']['Ids'][$key]);
foreach ($response['result']['DeleteResults'] as $key => $delete_result) {
if (!isset($delete_result['Id'])) {
Log::debug("DeleteAdGroups, empty Id");
Log::debug($delete_result);
Log::debug($this->getParams()['SelectionCriteria']['Ids'][$key]);
if ($delete_result['Errors'][0]['Code'] == 8800){
if ($external_id = $this->getParams()['SelectionCriteria']['Ids'][$key]){
GoalAdGroup::where('external_id', $external_id)->delete();
}
if ($delete_result['Errors'][0]['Code'] == 8800) {
if ($external_id = $this->getParams()['SelectionCriteria']['Ids'][$key]) {
GoalAdGroup::where('external_id', $external_id)->delete();
}
continue;
}
$external_id = (string)$delete_result['Id'];
GoalAdGroup::where('external_id', $external_id)->delete();
GoalAdGroup::where('external_id', $this->getParams()['SelectionCriteria']['Ids'][$key])
->update([
'reserve_delete_at' => null,
]);
continue;
}
} catch (\Exception $e) {
Log::debug($e);
throw $e;
$external_id = (string)$delete_result['Id'];
GoalAdGroup::where('external_id', $external_id)->delete();
}
}
public function failed()
{
GoalAdGroup::whereIn('external_id', $this->getParams()['SelectionCriteria']['Ids'])
->update([
'reserve_delete_at' => null,
]);
}
private function requestPrepare($params)
{
$this->setService('AdGroups');
......
<?php
namespace App\Service\Requests\Direct;
use App\Jobs\ProcessCallLimitedAPI;
use App\Models\AudienceTarget;
use App\Models\Pivots\GoalAudienceTarget;
use App\Service\Contract\APIRequest;
use App\Service\Requests\DirectRequest;
use Illuminate\Support\Facades\Log;
class DeleteAudienceTarget extends DirectRequest
{
protected $max_count = 10000;
protected $timestamp;
public function call($params = null)
{
$this->requestPrepare($params);
$process = new ProcessCallLimitedAPI($this);
dispatch($process)->onQueue('limits');
}
public function getObjectsCount()
{
return count($this->getParams()['SelectionCriteria']['Ids']);
}
public function slice($maxObjects): ?APIRequest
{
return $this->sliceByKey($maxObjects, ['SelectionCriteria', 'Ids']);;
}
public function handle($response)
{
try {
if (!isset($response['result']['DeleteResults'])) {
return;
}
foreach ($response['result']['DeleteResults'] as $key => $delete_result) {
if (!isset($delete_result['Id'])) {
Log::debug("DeleteAudienceTargets, empty Id");
Log::debug($delete_result);
$external_id = $this->getParams()['SelectionCriteria']['Ids'][$key];
Log::debug($external_id);
if ($this->getToken()->isMain()) {
AudienceTarget::whereExternalId($external_id)
->update([
'reserve_delete_at' => null,
]);
} else {
GoalAudienceTarget::whereExternalId($external_id)
->update([
'reserve_delete_at' => null,
]);
}
continue;
}
$external_id = (string)$delete_result['Id'];
if ($this->getToken()->isMain()) {
AudienceTarget::whereExternalId($external_id)
->delete();
} else {
GoalAudienceTarget::whereExternalId($external_id)
->delete();
}
}
} catch (\Exception $e) {
Log::debug($e);
throw $e;
}
}
public function failed()
{
if ($this->getToken()->isMain()) {
AudienceTarget::whereIn('external_id', $this->getParams()['SelectionCriteria']['Ids'])
->update([
'reserve_delete_at' => null,
]);
} else {
GoalAudienceTarget::whereIn('external_id', $this->getParams()['SelectionCriteria']['Ids'])
->update([
'reserve_delete_at' => null,
]);
}
}
private function requestPrepare($params)
{
$this->setService('AudienceTargets');
$this->setMethod('delete');
$this->setParams([
'SelectionCriteria' => [
'Ids' => $params['ids'],
],
]);
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddGoalAdGroupsReserveDeleteColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('goal_ad_groups', function (Blueprint $table) {
$table->timestamp('reserve_delete_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddGoalAudienceTargetReserveDeleteColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('goal_audience_targets', function (Blueprint $table) {
$table->timestamp('reserve_delete_at')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!