Commit bd4953fb by Vladislav

#19465 Реализация синхронизации данных по РК. (исрпавление)

1 parent b9c066d8
......@@ -42,10 +42,10 @@ class AdGroupsAdd extends Command
*/
public function handle()
{
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternal.groupsForNotExternal')
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternal')
->with([
'dictionaryCampaignsEnabledForExternal.groupsForNotExternal.dictionaryCampaign',
'dictionaryCampaignsEnabledForExternal.groupsForNotExternal.group',
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternal.dictionaryCampaign',
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForNotExternal.group',
])
->where('type', '!=', Tokens::MAIN)
->get();
......@@ -57,7 +57,7 @@ class AdGroupsAdd extends Command
$factory->getRequest('AdGroups', 'add')
->call([
'goalAdGroups' => $token->dictionaryCampaignsEnabledForExternal->pluck('groupsForNotExternal')
'goalAdGroups' => $token->dictionaryCampaignsEnabledForExternal->pluck('dictionaryCampaignsEnabledForExternalSynchronized')
->collapse(),
]);
}
......
......@@ -42,10 +42,10 @@ class AdGroupsUpdate extends Command
*/
public function handle()
{
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated')
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForNeedUpdated')
->with([
'dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated.dictionaryCampaign',
'dictionaryCampaignsEnabledForExternal.groupsForExternalForNeedUpdated.group',
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForNeedUpdated.dictionaryCampaign',
'dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForNeedUpdated.group',
])
->where('type', '!=', Tokens::MAIN)
->get();
......@@ -57,7 +57,7 @@ class AdGroupsUpdate extends Command
$factory->getRequest('AdGroup', 'update')
->call([
'goalAdGroups' => $token->dictionaryCampaignsEnabledForExternal->pluck('groupsForExternalForNeedUpdated')
'goalAdGroups' => $token->dictionaryCampaignsEnabledForExternal->pluck('dictionaryCampaignsEnabledForExternalSynchronized')
->collapse(),
]);
}
......
......@@ -67,6 +67,8 @@ class CampaignsSuspend extends Command
$factory = APIRequest::getInstance(API::YANDEX);
$factory->setToken($token);
dd($token->dictionaryCampaignsNotEnabledForExternalNotDisabled);
$factory->getRequest('Campaigns', 'suspend')
->call([
'ids' => $token->dictionaryCampaignsNotEnabledForExternalNotDisabled->pluck('external_id')->all(),
......
......@@ -42,8 +42,8 @@ class CampaignsUpdate extends Command
*/
public function handle()
{
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalNeedUpdated')
->with('dictionaryCampaignsEnabledForExternalNeedUpdated.campaign')
$tokens = Tokens::whereHas('dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated')
->with('dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated.campaign')
->where('type', '!=', Tokens::MAIN)
->get();
......@@ -53,7 +53,7 @@ class CampaignsUpdate extends Command
$factory->getRequest('Campaigns', 'update')
->call([
'dictionaryCampaigns' => $token->dictionaryCampaignsEnabledForExternalNeedUpdated,
'dictionaryCampaigns' => $token->dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated,
]);
}
......
......@@ -193,6 +193,7 @@ class CampaignVariablesController extends Controller
}
if ($dictionary_campaign->external_id) {
$dictionary_campaign->update([
'updated_need' => Carbon::now(),
]);
......@@ -200,6 +201,7 @@ class CampaignVariablesController extends Controller
$dictionary_campaign->groups()->update([
'updated_need' => Carbon::now(),
]);
}
}
......
......@@ -164,7 +164,7 @@ class AdGroup extends Model
if (self::getPropertiesWatch()->first(function ($property_name) use ($ad_group) {
return $ad_group->{$property_name} !== $ad_group->getOriginal($property_name);
})) {
$ad_group->goalGroups()->update([
$ad_group->goalGroups()->forExternal()->update([
'updated_need' => Carbon::now(),
]);
}
......
......@@ -194,7 +194,7 @@ class Campaigns extends Model
if (DictionaryCampaign::getPropertiesCopyWithPivot()->first(function ($property_name) use ($campaign) {
return $campaign->{$property_name} !== $campaign->getOriginal($property_name);
})) {
$campaign->dictionaryCampaigns()->enabled()->synchronized()->update(
$campaign->dictionaryCampaigns()->enabled()->updated()->update(
DictionaryCampaign::copyPropertyFromMain($campaign)
);
}
......@@ -202,7 +202,7 @@ class Campaigns extends Model
if (self::getPropertiesWatch()->first(function ($property_name) use ($campaign) {
return $campaign->{$property_name} !== $campaign->getOriginal($property_name);
})) {
$campaign->dictionaryCampaigns()->enabled()->synchronized()->forExternal()->update([
$campaign->dictionaryCampaigns()->forExternal()->update([
'updated_need' => Carbon::now(),
]);
}
......
......@@ -217,12 +217,7 @@ class DictionaryCampaign extends Pivot
public function scopeSynchronized(Builder $query)
{
return $query->synced()
->where(function (Builder $query) {
$query->updated()->orWhere(function (Builder $query) {
$query->updated(false)->forNotExternal();
});
});
return $query->synced()->updated();
}
public function scopeForUpdatedSelf(Builder $query)
......
......@@ -40,8 +40,8 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForNotExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsNotEnabledForExternalNotDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalDisabled
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronized
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Dictionary[] $campaignsForManaged
......@@ -203,14 +203,14 @@ class Tokens extends Model
return $this->dictionaryCampaignsForExternal()->enabled()->disabled();
}
public function dictionaryCampaignsEnabledForExternalNeedUpdated()
public function dictionaryCampaignsEnabledForExternalSynchronized()
{
return $this->dictionaryCampaignsForExternal()->enabled()->needUpdated();
return $this->dictionaryCampaignsForExternal()->enabled()->synchronized();
}
public function dictionaryCampaignsEnabledForExternalSynchronized()
public function dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated()
{
return $this->dictionaryCampaignsForExternal()->enabled()->synchronized();
return $this->dictionaryCampaignsEnabledForExternalSynchronized()->enabled()->needUpdated();
}
public function dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf()
......
......@@ -169,7 +169,7 @@ class CheckCampaignsTest extends TestCase
$campaign->pivot->update([
'synced' => false,
'updated' => false,
]);
$campaign->update([
......
......@@ -139,7 +139,15 @@ class CheckChangesAdGroupsTest extends TestCase
$this->assertEquals(0, AdGroup::forUpdatedSelf()->count());
$this->assertEquals(1, Campaigns::forUpdatedChildren()->count());
$this->assertEquals($this->ad_group->name, GoalAdGroup::first()->name);
$goalAdGroup = GoalAdGroup::first();
$goalAdGroup->update([
'external_id' => 1,
]);
$goalAdGroup->refresh();
$this->assertEquals($this->ad_group->name, $goalAdGroup->name);
$this->request_main->setParams($this->request_main_params);
......@@ -168,13 +176,10 @@ class CheckChangesAdGroupsTest extends TestCase
$this->assertEquals(0, AdGroup::forUpdatedSelf()->count());
$this->assertEquals($this->ad_group_data['result']['AdGroups'][0]['Name'], $this->ad_group->name);
$this->assertEquals($this->ad_group_data['result']['AdGroups'][0]['Name'], GoalAdGroup::first()->name);
$this->assertEquals(1, GoalAdGroup::needUpdated()->count());
$goalAdGroup = GoalAdGroup::needUpdated()->first();
$this->assertEquals(1, GoalAdGroup::needUpdated()->count());
$goalAdGroup->update([
'external_id' => 1,
]);
$goalAdGroup->refresh();
$this->request_main = APIRequest::getInstance(API::YANDEX)
->setToken($this->token_main)
......
......@@ -166,7 +166,7 @@ class LimitsTest extends TestCase
$requestCmpgn = $request->getRequest('Campaigns', 'update');
$this->token->limit = 191;
$requestCmpgn->call([
'dictionaryCampaigns' => $this->token->dictionaryCampaignsEnabledForExternalNeedUpdated
'dictionaryCampaigns' => $this->token->dictionaryCampaignsEnabledForExternalSynchronizedNeedUpdated
]);
$objects = $this->limitService->countObjectsLimit($requestCmpgn);
$this->assertEquals($objects, 0);
......
......@@ -67,6 +67,12 @@ class ReplaceByVariablesTest extends TestCase
$this->dictionaryCampaign = DictionaryCampaign::first();
$this->dictionaryCampaign->update([
'external_id' => 1,
]);
$this->dictionaryCampaign->refresh();
$this->assertNull($this->dictionaryCampaign->updated_need);
$this->actingAs($this->user)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!