Commit 44836271 by Vladislav

Резервирование записи создания фраз

1 parent 4463a059
......@@ -2,9 +2,11 @@
namespace App\Console\Commands;
use App\Models\Pivots\GoalKeyword;
use App\Models\Tokens;
use App\Service\API\API;
use App\Service\Requests\APIRequest;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Facades\DB;
......@@ -57,12 +59,13 @@ class KeywordsAdd extends Command
$factory = APIRequest::getInstance(API::YANDEX);
$factory->setToken($token);
$factory->getRequest('Keywords', 'add')
->call([
'goalKeywords' => DB::table('goal_keywords')
$goalKeywords = DB::table('goal_keywords')
->join('keywords', 'goal_keywords.keyword_id', '=', 'keywords.id')
->whereNull('keywords.deleted_at')
->whereNull('goal_keywords.external_id')
->whereNull('goal_keywords.reserve_create_at')
->whereNotNull('goal_keywords.goal_ad_group_external_id')
->whereNotNull('goal_keywords.dictionary_campaign_external_id')
->whereIn('goal_keywords.dictionary_campaign_id', $token->dictionaryCampaignsEnabledForExternalSynchronized->pluck('id'))
->select([
'goal_keywords.id as id',
......@@ -74,7 +77,16 @@ class KeywordsAdd extends Command
'keywords.user_param_1 as user_param_1',
'keywords.user_param_2 as user_param_2',
])
->get(),
->get();
GoalKeyword::whereIn('id', $goalKeywords->pluck('id')->toArray())
->update([
'reserve_create_at' => Carbon::now(),
]);
$factory->getRequest('Keywords', 'add')
->call([
'goalKeywords' => $goalKeywords,
]);
}
......
......@@ -73,4 +73,10 @@ class ProcessCallAPI implements ShouldQueue
throw $e;
}
}
public function failed()
{
$this->api->failed();
}
}
......@@ -59,12 +59,14 @@ class GoalKeyword extends Pivot
'external_upload_at',
'external_updated_at',
'updated_need',
'reserve_create_at',
];
protected $casts = [
'external_upload_at' => 'datetime',
'external_updated_at' => 'datetime',
'updated_need' => 'datetime',
'reserve_create_at' => 'datetime',
];
public $incrementing = true;
......@@ -131,6 +133,15 @@ class GoalKeyword extends Pivot
];
}
public static function boot()
{
parent::boot();
static::deleted(function (GoalKeyword $goalKeyword) {
GoalKeywordDelete::updateOrCreateByMain($goalKeyword);
});
}
/**
* @param Builder $query
* @return Builder
......
......@@ -19,6 +19,7 @@ interface APIRequest{
function call($params = null);
function handle($response);
function failed();
function getObjectsCount();
function getMaxCount();
......
......@@ -131,6 +131,11 @@ class APIRequest implements \App\Service\Contract\APIRequest
}
function failed()
{
}
function getObjectsCount()
{
throw new \Exception('Не задано сколько объектов обрабатывается');
......
......@@ -9,8 +9,8 @@ use App\Service\Contract\APIRequest;
use App\Service\Requests\DirectRequest;
use App\Service\StrReplaceByVariables;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Ramsey\Collection\Collection;
class AddKeywords extends DirectRequest
{
......@@ -78,6 +78,7 @@ class AddKeywords extends DirectRequest
$goalKeyword->update([
'external_id' => $external_id,
'external_upload_at' => Carbon::now(),
'reserve_create_at' => null,
]);
}
......@@ -93,6 +94,14 @@ class AddKeywords extends DirectRequest
$this->goalKeywords = $params['goalKeywords'];
}
public function failed()
{
GoalKeyword::whereIn('id', $this->goalKeywords->pluck('id')->toArray())
->update([
'reserve_create_at' => null,
]);
}
private function requestPrepare($params)
{
$this->setService('Keywords');
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddGoalKeywordsReserveCreateAtColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('goal_keywords', function (Blueprint $table) {
$table->timestamp('reserve_create_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!