Commit 8a52ff1b by Vladislav

#20304 Проблемы на epl3

1 parent 2373d96a
......@@ -61,18 +61,14 @@ class DictionaryCampaignsSyncByCampaign extends Command
GoalKeyword::upsert($data_keywords, [
'dictionary_campaign_id',
'dictionary_campaign_external_id',
'goal_ad_group_id',
'goal_ad_group_external_id',
'keyword_id',
'deleted_at',
], [
'dictionary_campaign_id',
'dictionary_campaign_external_id',
'goal_ad_group_id',
'goal_ad_group_external_id',
'keyword_id',
'deleted_at',
]);
$goalKeywordQuery = GoalKeyword::where('dictionary_campaign_id', $dictionaryCampaign->getKey())
......
......@@ -40,9 +40,9 @@ class KeywordsDelete extends Command
*/
public function handle()
{
$tokens = Tokens::whereHas('dictionaryCampaignsForExternalWithTrashed.goalKeywordsForExternalOnlyTrashed')
$tokens = Tokens::whereHas('dictionaryCampaignsForExternalWithTrashed.goalKeywordsDelete')
->with([
'dictionaryCampaignsForExternalWithTrashed.goalKeywordsForExternalOnlyTrashed',
'dictionaryCampaignsForExternalWithTrashed.goalKeywordsDelete',
])
->where('type', '!=', Tokens::MAIN)
->get();
......@@ -53,7 +53,7 @@ class KeywordsDelete extends Command
$factory->getRequest('Keywords', 'delete')
->call([
'ids' => $token->dictionaryCampaignsForExternalWithTrashed->pluck('goalKeywordsForExternalOnlyTrashed')
'ids' => $token->dictionaryCampaignsForExternalWithTrashed->pluck('goalKeywordsDelete')
->collapse()
->pluck('external_id')
->toArray(),
......
......@@ -3,6 +3,7 @@
namespace App\Models;
use App\Models\Pivots\GoalKeyword;
use App\Models\Pivots\GoalKeywordDelete;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
......@@ -111,11 +112,19 @@ class Keyword extends Model
parent::boot();
static::deleted(function (Keyword $keyword) {
if (!$keyword->isForceDeleting()) {
$keyword->goalKeywords->each(function (GoalKeyword $goalKeyword) {
GoalKeywordDelete::updateOrCreateByMain($goalKeyword);
$goalKeyword->delete();
});
}
});
}
......
......@@ -82,6 +82,8 @@ use Illuminate\Support\Collection;
* @method static Builder|DictionaryCampaign whereUpdatedSelf($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalKeyword[] $goalKeywords
* @property-read int|null $goal_keywords_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalKeywordDelete[] $goalKeywordsDelete
* @property-read int|null $goal_keywords_delete_count
*/
class DictionaryCampaign extends Pivot
{
......@@ -426,9 +428,9 @@ class DictionaryCampaign extends Pivot
return $this->goalKeywords()->needUpdated();
}
public function goalKeywordsForExternalOnlyTrashed()
public function goalKeywordsDelete()
{
return $this->goalKeywords()->forExternal()->onlyTrashed();
return $this->hasMany(GoalKeywordDelete::class, 'dictionary_campaign_id');
}
}
......@@ -47,8 +47,6 @@ use Illuminate\Support\Collection;
class GoalKeyword extends Pivot
{
use SoftDeletes;
protected $table = 'goal_keywords';
protected $fillable = [
......@@ -130,7 +128,6 @@ class GoalKeyword extends Pivot
'goal_ad_group_id' => $goalAdGroup->getKey(),
'goal_ad_group_external_id' => $goalAdGroup->external_id,
'keyword_id' => $keyword->getKey(),
'deleted_at' => null,
];
}
......
<?php
namespace App\Models\Pivots;
use App\Models\Keyword;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;
/**
* App\Models\Pivots\GoalKeywordDelete
*
* @property int $id
* @property int $external_id
* @property int $dictionary_campaign_external_id
* @property int $goal_ad_group_external_id
* @property int $dictionary_campaign_id
* @property int $goal_ad_group_id
* @property int $keyword_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read Keyword $keyword
* @method static Builder|GoalKeyword newModelQuery()
* @method static Builder|GoalKeyword newQuery()
* @method static Builder|GoalKeyword query()
* @method static Builder|GoalKeyword whereCreatedAt($value)
* @method static Builder|GoalKeyword whereDictionaryCampaignExternalId($value)
* @method static Builder|GoalKeyword whereDictionaryCampaignId($value)
* @method static Builder|GoalKeyword whereExternalId($value)
* @method static Builder|GoalKeyword whereExternalUpdatedAt($value)
* @method static Builder|GoalKeyword whereExternalUploadAt($value)
* @method static Builder|GoalKeyword whereGoalAdGroupExternalId($value)
* @method static Builder|GoalKeyword whereGoalAdGroupId($value)
* @method static Builder|GoalKeyword whereId($value)
* @method static Builder|GoalKeyword whereKeywordId($value)
* @method static Builder|GoalKeyword whereUpdatedAt($value)
* @method static Builder|GoalKeyword whereUpdatedNeed($value)
* @mixin \Eloquent
*/
class GoalKeywordDelete extends Pivot
{
protected $table = 'goal_keywords_delete';
protected $fillable = [
'external_id',
'goal_ad_group_external_id',
'dictionary_campaign_external_id',
'goal_ad_group_id',
'dictionary_campaign_id',
'keyword_id',
];
public $incrementing = true;
static public function updateOrCreateByMain(GoalKeyword $goalKeyword)
{
if (
!$goalKeyword->external_id
||
!$goalKeyword->goal_ad_group_external_id
||
!$goalKeyword->dictionary_campaign_external_id
) {
return null;
}
return GoalKeywordDelete::updateOrCreate([
'external_id' => $goalKeyword->external_id,
'goal_ad_group_external_id' => $goalKeyword->goal_ad_group_external_id,
'dictionary_campaign_external_id' => $goalKeyword->dictionary_campaign_external_id,
'goal_ad_group_id' => $goalKeyword->goal_ad_group_id,
'dictionary_campaign_id' => $goalKeyword->dictionary_campaign_id,
'keyword_id' => $goalKeyword->keyword_id,
]);
}
public function keyword()
{
return $this->belongsTo(Keyword::class, 'keyword_id');
}
public function dictionaryCampaign()
{
return $this->belongsTo(DictionaryCampaign::class, 'dictionary_campaign_id');
}
}
......@@ -39,6 +39,7 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaigns
* @property-read int|null $dictionary_campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternalWithTrashed
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
......
......@@ -7,6 +7,7 @@ use App\Models\Campaigns;
use App\Models\Pivots\DictionaryCampaign;
use App\Models\Pivots\GoalAdGroup;
use App\Models\Pivots\GoalKeyword;
use App\Models\Pivots\GoalKeywordDelete;
use App\Models\Variable;
use App\Service\Contract\APIRequest;
use App\Service\Requests\DirectRequest;
......@@ -60,7 +61,7 @@ class DeleteKeywords extends DirectRequest
$external_id = (string)$delete_result['Id'];
GoalKeyword::onlyTrashed()->where('external_id', $external_id)->forceDelete();
GoalKeywordDelete::where('external_id', $external_id)->delete();
}
} catch (\Exception $e) {
......
......@@ -16,12 +16,10 @@ class CreateGoalKeywordsUnique extends Migration
Schema::table('goal_keywords', function (Blueprint $table) {
$table->unique([
'dictionary_campaign_id',
'dictionary_campaign_external_id',
'goal_ad_group_id',
'goal_ad_group_external_id',
'keyword_id',
'deleted_at',
], 'goal_keywords_unique');
$table->dropSoftDeletes();
});
}
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGoalKeywordsDeleteTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('goal_keywords_delete', function (Blueprint $table) {
$table->id();
$table->bigInteger('external_id')->nullable();
$table->bigInteger('dictionary_campaign_external_id')->nullable();
$table->bigInteger('goal_ad_group_external_id')->nullable();
$table->bigInteger('dictionary_campaign_id')->unsigned();
$table->bigInteger('goal_ad_group_id')->unsigned();
$table->bigInteger('keyword_id')->unsigned();
$table->timestamps();
$table->foreign('dictionary_campaign_id')->references('id')->on('dictionary_campaigns')
->cascadeOnDelete();
$table->foreign('goal_ad_group_id')->references('id')->on('goal_ad_groups')
->cascadeOnDelete();
$table->foreign('keyword_id')->references('id')->on('keywords')
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('goal_keywords_delete');
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!