Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0c7e661f
authored
Jun 15, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19472 Синхронизация групп с целевыми
1 parent
cc186b99
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
47 additions
and
12 deletions
app/Console/Kernel.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdGroup.php
tests/Unit/CheckCampaignsTest.php
app/Console/Kernel.php
View file @
0c7e661
...
...
@@ -42,6 +42,7 @@ class Kernel extends ConsoleKernel
protected
function
schedule
(
Schedule
$schedule
)
{
$schedule
->
command
(
DictionaryCampaignsSyncByCampaign
::
class
)
->
everyThirtyMinutes
();
$schedule
->
command
(
RefreshLimits
::
class
)
->
hourly
();
$schedule
->
command
(
DictionariesLoad
::
class
)
->
saturdays
()
->
at
(
'05:00'
);
$schedule
->
command
(
CampaignsCheckChange
::
class
)
->
hourlyAt
(
5
);
...
...
app/Models/AdGroup.php
View file @
0c7e661
...
...
@@ -180,7 +180,7 @@ class AdGroup extends Model
$ad_group
->
campaign
->
copyGroupInGoalGroup
();
$ad_group
->
campaign
->
copyGroupInGoalKeyword
();
}
else
{
$ad_group
->
goalGroups
()
->
update
(
$ad_group
->
goalGroups
()
->
has
(
'dictionaryCampaignSynchronized'
)
->
update
(
GoalAdGroup
::
copyPropertyFromMain
(
$ad_group
)
);
}
...
...
@@ -189,7 +189,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
()
->
forExternal
()
->
update
([
$ad_group
->
goalGroups
()
->
has
(
'dictionaryCampaignSynchronized'
)
->
forExternal
()
->
update
([
'updated_need'
=>
Carbon
::
now
(),
]);
}
...
...
app/Models/Campaigns.php
View file @
0c7e661
...
...
@@ -194,6 +194,8 @@ class Campaigns extends Model
$dictionaryCampaign
->
delete
();
});
}
}
elseif
(
$campaign
->
manage
)
{
$campaign
->
copyInGoalCampaign
();
}
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
...
...
@@ -222,7 +224,7 @@ class Campaigns extends Model
{
$campaign
=
$this
;
$campaign
->
dictionaryCampaign
s
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$campaign
->
dictionaryCampaign
Synchronized
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$campaign
->
groups
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
...
...
@@ -238,7 +240,7 @@ class Campaigns extends Model
$campaign
=
$this
;
$campaign
->
dictionaryCampaign
s
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$campaign
->
dictionaryCampaign
Synchronized
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$dictionaryCampaign
->
groups
->
each
(
function
(
GoalAdGroup
$goalAdGroup
)
use
(
$campaign
,
$dictionaryCampaign
)
{
...
...
@@ -344,6 +346,11 @@ class Campaigns extends Model
return
$this
->
hasMany
(
DictionaryCampaign
::
class
,
'campaign_id'
);
}
public
function
dictionaryCampaignSynchronized
()
{
return
$this
->
dictionaryCampaigns
()
->
synchronized
();
}
public
function
dictionaryCampaignVariables
()
{
return
$this
->
hasManyThrough
(
DictionaryCampaignVariable
::
class
,
DictionaryCampaign
::
class
,
'campaign_id'
,
'dictionary_campaign_id'
);
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
0c7e661
...
...
@@ -190,14 +190,35 @@ class DictionaryCampaign extends Pivot
$data
[
'synced_need'
]
=
Carbon
::
now
();
}
return
DictionaryCampaign
::
updateOrCreate
([
'dictionary_id'
=>
$dictionary
->
getKey
(),
'campaign_id'
=>
$campaign
->
getKey
(),
'deleted_at'
=>
null
,
],
array_merge
(
$data
=
array_merge
(
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
),
$data
));
);
$dictionaryCampaign
=
DictionaryCampaign
::
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
whereNull
(
'deleted_at'
)
->
first
();
if
(
$dictionaryCampaign
)
{
if
(
$dictionaryCampaign
->
synced
)
{
$dictionaryCampaign
->
update
(
$data
);
return
$dictionaryCampaign
;
}
}
else
{
$dictionaryCampaign
=
DictionaryCampaign
::
create
(
array_merge
(
$data
,
[
'dictionary_id'
=>
$dictionary
->
getKey
(),
'campaign_id'
=>
$campaign
->
getKey
(),
]
)
);
return
$dictionaryCampaign
;
}
return
null
;
}
public
static
function
boot
()
...
...
app/Models/Pivots/GoalAdGroup.php
View file @
0c7e661
...
...
@@ -190,6 +190,11 @@ class GoalAdGroup extends Pivot
return
$this
->
belongsTo
(
DictionaryCampaign
::
class
,
'dictionary_campaign_id'
);
}
public
function
dictionaryCampaignSynchronized
()
{
return
$this
->
dictionaryCampaign
()
->
synchronized
();
}
public
function
goalKeywords
()
{
return
$this
->
hasMany
(
GoalKeyword
::
class
,
'goal_ad_group_id'
);
...
...
tests/Unit/CheckCampaignsTest.php
View file @
0c7e661
...
...
@@ -2,6 +2,7 @@
namespace
Tests\Unit
;
use
App\Console\Commands\DictionaryCampaignsSyncByCampaign
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Account
;
use
App\Models\Campaigns
;
...
...
@@ -184,7 +185,7 @@ class CheckCampaignsTest extends TestCase
$this
->
assertNull
(
$campaign
->
pivot
->
updated_need
);
$campaign
->
pivot
->
update
([
'
updat
ed'
=>
true
,
'
sync
ed'
=>
true
,
]);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
...
...
@@ -208,7 +209,7 @@ class CheckCampaignsTest extends TestCase
$campaign
->
pivot
->
update
([
'
updat
ed'
=>
false
,
'
sync
ed'
=>
false
,
]);
$campaign
->
update
([
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment