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 25dd333e
authored
May 20, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19464 Скрипт загрузки данных по шаблонным РК в кеш.
1 parent
e7710efc
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
37 deletions
app/Console/Commands/LoadUpdatedCampaigns.php
app/Models/Campaigns.php
app/Service/Requests/Direct/CheckCampaignsChange.php
app/Service/Requests/Direct/GetCampaigns.php
database/migrations/2021_05_11_084828_create_campaigns_table.php
tests/Unit/CheckCampaignsTest.php
tests/Unit/GetCampaignsTest.php
app/Console/Commands/LoadUpdatedCampaigns.php
View file @
25dd333
...
@@ -45,7 +45,7 @@ class LoadUpdatedCampaigns extends Command
...
@@ -45,7 +45,7 @@ class LoadUpdatedCampaigns extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$campaigns
=
Campaigns
::
forUpdated
()
->
get
();
$campaigns
=
Campaigns
::
forUpdated
Self
()
->
get
();
if
(
!
$campaigns
->
count
()){
if
(
!
$campaigns
->
count
()){
return
;
return
;
}
}
...
...
app/Models/Campaigns.php
View file @
25dd333
...
@@ -27,7 +27,9 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -27,7 +27,9 @@ use Illuminate\Database\Eloquent\Model;
* @property int|null $relevant_keywords_setting_optimize_goal_id
* @property int|null $relevant_keywords_setting_optimize_goal_id
* @property string|null $attribution_model
* @property string|null $attribution_model
* @property string|null $priority_goals
* @property string|null $priority_goals
* @property string|null $updated
* @property array $updated
* @property string|null $updated_self
* @property string|null $updated_children
* @property bool $manage
* @property bool $manage
* @property bool $enabled
* @property bool $enabled
* @property \Illuminate\Support\Carbon|null $groups_loaded_at
* @property \Illuminate\Support\Carbon|null $groups_loaded_at
...
@@ -44,7 +46,8 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -44,7 +46,8 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forGroupsLoadable()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forManaged()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdatedSelf()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns forUpdatedChildren()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns notForEnabled()
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns notForEnabled()
...
@@ -71,7 +74,8 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -71,7 +74,8 @@ use Illuminate\Database\Eloquent\Model;
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTextCampaignStrategySearch($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTextCampaignStrategySearch($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTimeTargeting($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereTimeTargeting($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereToken($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdated($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdatedSelf($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdatedChildren($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Campaigns whereUpdatedAt($value)
* @mixin \Eloquent
* @mixin \Eloquent
*/
*/
...
@@ -95,7 +99,8 @@ class Campaigns extends Model
...
@@ -95,7 +99,8 @@ class Campaigns extends Model
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords_setting_optimize_goal_id'
,
'relevant_keywords_setting_optimize_goal_id'
,
'attribution_model'
,
'attribution_model'
,
'updated'
,
'updated_self'
,
'updated_children'
,
'manage'
,
'manage'
,
'enabled'
,
'enabled'
,
];
];
...
@@ -105,6 +110,8 @@ class Campaigns extends Model
...
@@ -105,6 +110,8 @@ class Campaigns extends Model
'manage'
=>
'boolean'
,
'manage'
=>
'boolean'
,
'enabled'
=>
'boolean'
,
'enabled'
=>
'boolean'
,
'groups_loaded_at'
=>
'datetime'
,
'groups_loaded_at'
=>
'datetime'
,
'updated_self'
=>
'datetime'
,
'updated_children'
=>
'datetime'
,
];
];
public
static
function
boot
()
public
static
function
boot
()
...
@@ -174,9 +181,14 @@ class Campaigns extends Model
...
@@ -174,9 +181,14 @@ class Campaigns extends Model
->
withTimestamps
();
->
withTimestamps
();
}
}
public
function
scopeForUpdated
(
$query
)
public
function
scopeForUpdated
Self
(
$query
)
{
{
$query
->
whereNotNull
(
'updated'
);
$query
->
whereNotNull
(
'updated_self'
);
}
public
function
scopeForUpdatedChildren
(
$query
)
{
$query
->
whereNotNull
(
'updated_children'
);
}
}
public
function
scopeForGroupsLoadable
(
$query
)
public
function
scopeForGroupsLoadable
(
$query
)
...
...
app/Service/Requests/Direct/CheckCampaignsChange.php
View file @
25dd333
<?php
<?php
namespace
App\Service\Requests\Direct
;
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
...
@@ -6,41 +7,54 @@ use App\Models\Campaigns;
...
@@ -6,41 +7,54 @@ use App\Models\Campaigns;
use
App\Service\API\API
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
class
CheckCampaignsChange
extends
DirectRequest
{
class
CheckCampaignsChange
extends
DirectRequest
{
CONST
SELF
=
'SELF'
;
CONST
SELF
=
'SELF'
;
CONST
CHILDREN
=
'CHILDREN'
;
CONST
CHILDREN
=
'CHILDREN'
;
CONST
STAT
=
'STAT'
;
CONST
STAT
=
'STAT'
;
protected
$next
;
protected
$next
;
function
call
(
$params
=
null
){
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
}
function
handle
(
$response
){
function
handle
(
$response
)
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign
){
{
if
(
$campaign
[
'ChangesIn'
]
==
self
::
SELF
||
$campaign
[
'ChangesIn'
]
==
self
::
CHILDREN
){
foreach
(
$response
[
'result'
][
'Campaigns'
]
as
$campaign
)
{
if
(
in_array
(
self
::
SELF
,
$campaign
[
'ChangesIn'
])
||
in_array
(
self
::
CHILDREN
,
$campaign
[
'ChangesIn'
]))
{
$data
=
[
'token'
=>
$this
->
getToken
()
->
id
,
];
if
(
in_array
(
self
::
SELF
,
$campaign
[
'ChangesIn'
]))
{
$data
[
'updated_self'
]
=
Carbon
::
now
();
}
if
(
in_array
(
self
::
CHILDREN
,
$campaign
[
'ChangesIn'
]))
{
$data
[
'updated_children'
]
=
Carbon
::
now
();
}
Campaigns
::
firstOrCreate
([
Campaigns
::
firstOrCreate
([
'external_id'
=>
$campaign
[
'CampaignId'
]
'external_id'
=>
$campaign
[
'CampaignId'
]
],
],
$data
);
[
'updated'
=>
$campaign
[
'ChangesIn'
],
'token'
=>
$this
->
getToken
()
->
id
]);
}
}
}
}
$this
->
getToken
()
->
timestamp
=
$response
[
'result'
][
'Timestamp'
];
$this
->
getToken
()
->
timestamp
=
$response
[
'result'
][
'Timestamp'
];
$this
->
getToken
()
->
save
();
$this
->
getToken
()
->
save
();
}
}
private
function
requestPrepare
(
$params
){
private
function
requestPrepare
(
$params
)
{
$this
->
setService
(
'changes'
);
$this
->
setService
(
'changes'
);
$this
->
setMethod
(
'checkDictionaries'
);
$this
->
setMethod
(
'checkDictionaries'
);
$this
->
setParams
([
$this
->
setParams
([
"Timestamp"
=>
$this
->
getToken
()
->
timestamp
"Timestamp"
=>
$this
->
getToken
()
->
timestamp
]);
]);
}
}
}
}
app/Service/Requests/Direct/GetCampaigns.php
View file @
25dd333
...
@@ -36,7 +36,6 @@ class GetCampaigns extends DirectRequest{
...
@@ -36,7 +36,6 @@ class GetCampaigns extends DirectRequest{
'relevant_keywords_setting_optimize_goal_id'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
],
'relevant_keywords_setting_optimize_goal_id'
=>
$campaign
[
'TextCampaign'
][
'RelevantKeywords'
][
'OptimizeGoalId'
],
'attribution_model'
=>
$campaign
[
'TextCampaign'
][
'AttributionModel'
],
'attribution_model'
=>
$campaign
[
'TextCampaign'
][
'AttributionModel'
],
'priority_goals'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'PriorityGoals'
]),
'priority_goals'
=>
json_encode
(
$campaign
[
'TextCampaign'
][
'PriorityGoals'
]),
'updated'
=>
null
];
];
}
}
Campaigns
::
upsert
(
$data
,
[
Campaigns
::
upsert
(
$data
,
[
...
@@ -56,7 +55,6 @@ class GetCampaigns extends DirectRequest{
...
@@ -56,7 +55,6 @@ class GetCampaigns extends DirectRequest{
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords_setting_budget_percent'
,
'relevant_keywords_setting_optimize_goal_id'
,
'relevant_keywords_setting_optimize_goal_id'
,
'attribution_model'
,
'attribution_model'
,
'updated'
]);
]);
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
Log
::
debug
(
$e
);
...
...
database/migrations/2021_05_11_084828_create_campaigns_table.php
View file @
25dd333
...
@@ -31,11 +31,8 @@ class CreateCampaignsTable extends Migration
...
@@ -31,11 +31,8 @@ class CreateCampaignsTable extends Migration
$table
->
bigInteger
(
'relevant_keywords_setting_optimize_goal_id'
)
->
nullable
();
$table
->
bigInteger
(
'relevant_keywords_setting_optimize_goal_id'
)
->
nullable
();
$table
->
string
(
'attribution_model'
,
4
)
->
nullable
();
$table
->
string
(
'attribution_model'
,
4
)
->
nullable
();
$table
->
json
(
'priority_goals'
)
->
nullable
();
$table
->
json
(
'priority_goals'
)
->
nullable
();
$table
->
enum
(
'updated'
,
[
$table
->
timestamp
(
'updated_self'
)
->
nullable
();
\App\Service\Requests\Direct\CheckCampaignsChange
::
CHILDREN
,
$table
->
timestamp
(
'updated_children'
)
->
nullable
();
\App\Service\Requests\Direct\CheckCampaignsChange
::
SELF
,
\App\Service\Requests\Direct\CheckCampaignsChange
::
STAT
,
])
->
nullable
();
$table
->
boolean
(
'manage'
)
->
default
(
0
);
$table
->
boolean
(
'manage'
)
->
default
(
0
);
$table
->
boolean
(
'enabled'
)
->
default
(
1
);
$table
->
boolean
(
'enabled'
)
->
default
(
1
);
$table
->
timestamp
(
'groups_loaded_at'
)
->
nullable
();
$table
->
timestamp
(
'groups_loaded_at'
)
->
nullable
();
...
...
tests/Unit/CheckCampaignsTest.php
View file @
25dd333
...
@@ -53,16 +53,19 @@ class CheckCampaignsTest extends TestCase
...
@@ -53,16 +53,19 @@ class CheckCampaignsTest extends TestCase
}
}
public
function
testHandleApi
(){
public
function
testHandleApi
(){
$this
->
assertEquals
(
0
,
Campaigns
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
0
,
Campaigns
::
forUpdatedChildren
()
->
count
());
$this
->
request
->
handle
([
$this
->
request
->
handle
([
'result'
=>
[
'result'
=>
[
'Timestamp'
=>
'test time'
,
'Timestamp'
=>
'test time'
,
'Campaigns'
=>
[
'Campaigns'
=>
[
[
[
'ChangesIn'
=>
'SELF'
,
'ChangesIn'
=>
[
'SELF'
]
,
'CampaignId'
=>
1
'CampaignId'
=>
1
],
],
[
[
'ChangesIn'
=>
'CHILDREN'
,
'ChangesIn'
=>
[
'CHILDREN'
]
,
'CampaignId'
=>
2
'CampaignId'
=>
2
]
]
]
]
...
@@ -70,13 +73,7 @@ class CheckCampaignsTest extends TestCase
...
@@ -70,13 +73,7 @@ class CheckCampaignsTest extends TestCase
]);
]);
$this
->
assertEquals
(
$this
->
request
->
getToken
()
->
timestamp
,
'test time'
);
$this
->
assertEquals
(
$this
->
request
->
getToken
()
->
timestamp
,
'test time'
);
$this
->
assertEquals
(
2
,
Campaigns
::
forUpdated
()
->
count
());
$this
->
assertEquals
(
1
,
Campaigns
::
forUpdatedSelf
()
->
count
());
foreach
(
Campaigns
::
forUpdated
()
->
get
()
as
$c
){
$this
->
assertEquals
(
1
,
Campaigns
::
forUpdatedChildren
()
->
count
());
if
(
$c
->
external_id
==
1
){
$this
->
assertEquals
(
'SELF'
,
$c
->
updated
);
}
else
{
$this
->
assertEquals
(
'CHILDREN'
,
$c
->
updated
);
}
}
}
}
}
}
tests/Unit/GetCampaignsTest.php
View file @
25dd333
...
@@ -105,6 +105,7 @@ class GetCampaignsTest extends TestCase
...
@@ -105,6 +105,7 @@ class GetCampaignsTest extends TestCase
$this
->
assertEquals
(
$campaign
->
relevant_keywords_setting_optimize_goal_id
,
2
);
$this
->
assertEquals
(
$campaign
->
relevant_keywords_setting_optimize_goal_id
,
2
);
$this
->
assertEquals
(
$campaign
->
attribution_model
,
'AL'
);
$this
->
assertEquals
(
$campaign
->
attribution_model
,
'AL'
);
$this
->
assertEquals
(
$campaign
->
priority_goals
,
json_encode
([
34234
,
2435567
,
23423
]));
$this
->
assertEquals
(
$campaign
->
priority_goals
,
json_encode
([
34234
,
2435567
,
23423
]));
$this
->
assertEquals
(
$campaign
->
updated
,
null
);
$this
->
assertEquals
(
$campaign
->
updated_self
,
null
);
$this
->
assertEquals
(
$campaign
->
updated_children
,
null
);
}
}
}
}
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