Commit bd4953fb by Vladislav

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

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