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 cc186b99
authored
Jun 11, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19474 Синхронизация фраз
1 parent
a0734f0e
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
547 additions
and
92 deletions
app/Console/Commands/AdGroupsLoadKeywords.php
app/Console/Commands/AdGroupsLoadUpdated.php
app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php
app/Console/Commands/CampaignsLoadGroups.php
app/Console/Commands/CampaignsLoadUpdated.php
app/Console/Commands/CampaignsResume.php
app/Console/Commands/CampaignsSuspend.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Commands/KeywordsAdd.php
app/Console/Commands/KeywordsDelete.php
app/Console/Commands/KeywordsUpdate.php
app/Console/Kernel.php
app/Http/Controllers/TokensController.php
app/Models/AdGroup.php
app/Models/Campaigns.php
app/Models/Keyword.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalAdGroup.php
app/Models/Pivots/GoalKeyword.php
app/Models/Tokens.php
app/Service/Requests/Direct/AddKeywords.php
app/Service/Requests/Direct/DeleteKeywords.php
app/Service/Requests/Direct/GetKeywords.php
app/Service/Requests/Direct/UpdateKeywords.php
database/migrations/2021_06_11_103110_add_keywords_and_goal_keywords_column_deleted_at.php
database/migrations/2021_06_11_105315_add_dictionary_campaigns_column_synced_need_and_deleted_at.php
database/migrations/2021_06_11_113017_add_ad_groups_and_goal_ad_groups_column_deleted_at.php
app/Console/Commands/AdGroupsLoadKeywords.php
View file @
cc186b9
...
...
@@ -58,7 +58,7 @@ class AdGroupsLoadKeywords extends Command
$ad_group_ids
=
$campaigns
->
pluck
(
'groupsForKeywordsLoadable'
)
->
collapse
()
->
pluck
(
'external_id'
)
->
all
();
->
toArray
();
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
...
...
app/Console/Commands/AdGroupsLoadUpdated.php
View file @
cc186b9
...
...
@@ -7,6 +7,7 @@ use App\Models\Tokens;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
use
Illuminate\Database\Eloquent\Builder
;
class
AdGroupsLoadUpdated
extends
Command
{
...
...
@@ -41,7 +42,13 @@ class AdGroupsLoadUpdated extends Command
*/
public
function
handle
()
{
$adGroups
=
AdGroup
::
has
(
'campaignForEnabledForManaged'
)
->
forUpdatedSelf
()
->
get
();
$adGroups
=
AdGroup
::
where
(
function
(
Builder
$query
)
{
$query
->
where
(
function
(
Builder
$query
)
{
$query
->
has
(
'campaignForEnabledForManaged'
);
})
->
orWhere
(
function
(
Builder
$query
)
{
$query
->
whereNull
(
'campaign_id'
);
});
})
->
forUpdatedSelf
()
->
get
();
if
(
$adGroups
->
count
())
{
...
...
@@ -50,7 +57,7 @@ class AdGroupsLoadUpdated extends Command
throw
new
\Exception
(
'Не найден токен блин'
);
}
$ids
=
$adGroups
->
pluck
(
'external_id'
)
->
all
();
$ids
=
$adGroups
->
pluck
(
'external_id'
)
->
toArray
();
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
...
...
@@ -68,6 +75,7 @@ class AdGroupsLoadUpdated extends Command
}
/*
$tokens = Tokens::has('dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf')
->with('dictionaryCampaignsEnabledForExternalSynchronized.groupsForExternalForUpdatedSelf')
->where('type', '!=', Tokens::MAIN)
...
...
@@ -80,7 +88,7 @@ class AdGroupsLoadUpdated extends Command
$ids = $token->dictionaryCampaignsEnabledForExternalSynchronized->pluck('groupsForExternalForUpdatedSelf')
->collapse()
->pluck('external_id')
->
all
();
->
toArray
();
$factory->getRequest('AdGroups', 'get')->call([
'Ids' => $ids,
...
...
@@ -93,6 +101,7 @@ class AdGroupsLoadUpdated extends Command
'AdGroupIds' => $ids,
]);
}
*/
return
0
;
}
...
...
app/Console/Commands/CampaignsCheckUpdatedChildrenAdGroups.php
View file @
cc186b9
...
...
@@ -52,7 +52,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Changes'
,
'check'
)
->
call
([
'CampaignIds'
=>
Campaigns
::
forUpdatedChildren
()
->
pluck
(
'external_id'
)
->
all
(),
'CampaignIds'
=>
Campaigns
::
forUpdatedChildren
()
->
pluck
(
'external_id'
)
->
toArray
(),
'FieldNames'
=>
[
'AdGroupIds'
,
],
...
...
@@ -61,6 +61,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
}
$tokens
=
Tokens
::
has
(
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren'
)
->
with
(
'dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren'
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
...
...
@@ -72,7 +73,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
$factory
->
getRequest
(
'Changes'
,
'check'
)
->
call
([
'CampaignIds'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
->
pluck
(
'external_id'
)
->
all
(),
->
pluck
(
'external_id'
)
->
toArray
(),
'FieldNames'
=>
[
'AdGroupIds'
,
],
...
...
@@ -80,6 +81,7 @@ class CampaignsCheckUpdatedChildrenAdGroups extends Command
]);
}
return
0
;
}
}
app/Console/Commands/CampaignsLoadGroups.php
View file @
cc186b9
...
...
@@ -56,7 +56,7 @@ class CampaignsLoadGroups extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$campaign_ids
=
$campaigns
->
pluck
(
'external_id'
)
->
all
();
$campaign_ids
=
$campaigns
->
pluck
(
'external_id'
)
->
toArray
();
$factory
->
getRequest
(
'AdGroups'
,
'get'
)
->
call
([
...
...
app/Console/Commands/CampaignsLoadUpdated.php
View file @
cc186b9
...
...
@@ -56,7 +56,7 @@ class CampaignsLoadUpdated extends Command
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Campaigns'
,
'get'
)
->
call
([
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$campaigns
->
pluck
(
'external_id'
)
->
toArray
(),
]);
}
...
...
@@ -72,7 +72,7 @@ class CampaignsLoadUpdated extends Command
$factory
->
getRequest
(
'Campaigns'
,
'get'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
->
pluck
(
'external_id'
)
->
all
(),
->
pluck
(
'external_id'
)
->
toArray
(),
]);
}
...
...
app/Console/Commands/CampaignsResume.php
View file @
cc186b9
...
...
@@ -51,7 +51,7 @@ class CampaignsResume extends Command
$factory->getRequest('campaigns', 'resume')
->call([
'ids' => $token_main->campaignsEnabledDisabled->pluck('external_id')->
all
(),
'ids' => $token_main->campaignsEnabledDisabled->pluck('external_id')->
toArray
(),
]);
}
*/
...
...
@@ -67,7 +67,7 @@ class CampaignsResume extends Command
$factory
->
getRequest
(
'Campaigns'
,
'resume'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalDisabled
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$token
->
dictionaryCampaignsEnabledForExternalDisabled
->
pluck
(
'external_id'
)
->
toArray
(),
]);
}
...
...
app/Console/Commands/CampaignsSuspend.php
View file @
cc186b9
...
...
@@ -51,7 +51,7 @@ class CampaignsSuspend extends Command
$factory->getRequest('campaigns', 'suspend')
->call([
'ids' => $token_main->campaignsNotEnabledNotDisabled->pluck('external_id')->
all
(),
'ids' => $token_main->campaignsNotEnabledNotDisabled->pluck('external_id')->
toArrayv
(),
]);
}
*/
...
...
@@ -67,7 +67,7 @@ class CampaignsSuspend extends Command
$factory
->
getRequest
(
'Campaigns'
,
'suspend'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsNotEnabledForExternalNotDisabled
->
pluck
(
'external_id'
)
->
all
(),
'ids'
=>
$token
->
dictionaryCampaignsNotEnabledForExternalNotDisabled
->
pluck
(
'external_id'
)
->
toArray
(),
]);
}
...
...
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
0 → 100644
View file @
cc186b9
<?php
namespace
App\Console\Commands
;
use
App\Models\AdGroup
;
use
App\Models\Keyword
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalKeyword
;
use
Illuminate\Console\Command
;
class
DictionaryCampaignsSyncByCampaign
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'dictionarycampaigns:sync'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Синхроннизиировать связанные данные основныйх РК с целевыми рк'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
*/
public
function
handle
()
{
DictionaryCampaign
::
with
([
'campaign.groups'
,
])
->
synced
()
->
needSynced
()
->
get
()
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
$dictionaryCampaign
->
campaign
->
groups
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
$goalAdGroup
=
GoalAdGroup
::
updateOrCreateByMain
(
$adGroup
,
$dictionaryCampaign
);
$adGroup
->
keywords
->
each
(
function
(
Keyword
$keyword
)
use
(
$goalAdGroup
,
$dictionaryCampaign
)
{
GoalKeyword
::
updateOrCreateByMain
(
$keyword
,
$goalAdGroup
,
$dictionaryCampaign
);
});
});
$dictionaryCampaign
->
update
([
'synced_need'
=>
null
,
]);
});
return
0
;
}
}
app/Console/Commands/KeywordsAdd.php
View file @
cc186b9
...
...
@@ -51,7 +51,7 @@ class KeywordsAdd extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Keyword'
,
'add'
)
$factory
->
getRequest
(
'Keyword
s
'
,
'add'
)
->
call
([
'goalKeywords'
=>
$token
->
dictionaryCampaignsEnabledForExternalSynchronized
->
pluck
(
'goalKeywordsForNotExternal'
)
->
collapse
(),
...
...
app/Console/Commands/KeywordsDelete.php
0 → 100644
View file @
cc186b9
<?php
namespace
App\Console\Commands
;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Illuminate\Console\Command
;
class
KeywordsDelete
extends
Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected
$signature
=
'keywords:delete'
;
/**
* The console command description.
*
* @var string
*/
protected
$description
=
'Удаление фраз с целевого аккаунта'
;
/**
* Create a new command instance.
*
* @return void
*/
public
function
__construct
()
{
parent
::
__construct
();
}
/**
* Execute the console command.
*
* @return int
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsForExternalWithTrashed.goalKeywordsForExternalOnlyTrashed'
)
->
with
([
'dictionaryCampaignsForExternalWithTrashed.goalKeywordsForExternalOnlyTrashed'
,
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
foreach
(
$tokens
as
$token
)
{
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Keywords'
,
'delete'
)
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsForExternalWithTrashed
->
pluck
(
'goalKeywordsForExternalOnlyTrashed'
)
->
collapse
()
->
pluck
(
'external_id'
)
->
toArray
(),
]);
}
return
0
;
}
}
app/Console/Commands/KeywordsUpdate.php
View file @
cc186b9
...
...
@@ -40,9 +40,9 @@ class KeywordsUpdate extends Command
*/
public
function
handle
()
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Synchroniz
ed.goalKeywordsForNeedUpdated'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsEnabledForExternal
Updat
ed.goalKeywordsForNeedUpdated'
)
->
with
([
'dictionaryCampaignsEnabledForExternal
Synchroniz
ed.goalKeywordsForNeedUpdated.keyword'
,
'dictionaryCampaignsEnabledForExternal
Updat
ed.goalKeywordsForNeedUpdated.keyword'
,
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
...
...
@@ -51,9 +51,9 @@ class KeywordsUpdate extends Command
$factory
=
APIRequest
::
getInstance
(
API
::
YANDEX
);
$factory
->
setToken
(
$token
);
$factory
->
getRequest
(
'Keyword'
,
'update'
)
$factory
->
getRequest
(
'Keyword
s
'
,
'update'
)
->
call
([
'goalKeywords'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Synchroniz
ed
->
pluck
(
'goalKeywordsForNeedUpdated'
)
'goalKeywords'
=>
$token
->
dictionaryCampaignsEnabledForExternal
Updat
ed
->
pluck
(
'goalKeywordsForNeedUpdated'
)
->
collapse
(),
]);
}
...
...
app/Console/Kernel.php
View file @
cc186b9
...
...
@@ -15,6 +15,7 @@ use App\Console\Commands\CampaignsSuspend;
use
App\Console\Commands\CampaignsUpdate
;
use
App\Console\Commands\DictionariesLoad
;
use
App\Console\Commands\CampaignsLoadUpdated
;
use
App\Console\Commands\DictionaryCampaignsSyncByCampaign
;
use
App\Console\Commands\KeywordsAdd
;
use
App\Console\Commands\KeywordsUpdate
;
use
App\Console\Commands\RefreshLimits
;
...
...
@@ -40,6 +41,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
);
...
...
@@ -53,7 +55,7 @@ class Kernel extends ConsoleKernel
$schedule
->
command
(
AdGroupsLoadUpdated
::
class
)
->
hourlyAt
(
20
);
$schedule
->
command
(
AdGroupsLoadKeywords
::
class
)
->
hourlyAt
(
2
0
);
$schedule
->
command
(
AdGroupsLoadKeywords
::
class
)
->
hourlyAt
(
3
0
);
//Это разовая загрука групп. В расписании она не нужна, по расипсниаю будем грузить уже только те, в которых были изменения
// через AdGroupsLoadUpdated
...
...
app/Http/Controllers/TokensController.php
View file @
cc186b9
...
...
@@ -8,6 +8,7 @@ use App\Models\Pivots\DictionaryCampaign;
use
App\Models\Tokens
;
use
App\Service\API\API
;
use
App\Service\Requests\APIRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Redirect
;
...
...
@@ -189,23 +190,29 @@ class TokensController extends Controller
$token
->
cities
()
->
save
(
$dictionary
);
if
(
$token_main
->
campaignsForManaged
->
count
())
{
$dictionary
->
campaigns
()
->
syncWithoutDetaching
(
$token_main
->
campaignsForManaged
->
keyBy
(
Campaigns
::
getModel
()
->
getKeyName
())
->
transform
(
function
(
Campaigns
$campaign
)
{
return
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
);
})
->
all
()
);
$dictionary
->
campaigns
()
->
get
()
->
each
(
function
(
Campaigns
$campaign
)
{
$campaign
->
copyGroupInGoalGroup
();
$token_main
->
campaignsForManaged
->
each
(
function
(
Campaigns
$campaign
)
use
(
$dictionary
)
{
DictionaryCampaign
::
updateOrCreateByMain
(
$campaign
,
$dictionary
,
true
);
});
}
DictionaryCampaign
::
where
(
'dictionary_id'
,
$dictionary
->
getKey
())
->
whereNotIn
(
'campaign_id'
,
$token_main
->
campaignsForManaged
->
pluck
(
'id'
))
->
get
()
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
$dictionaryCampaign
->
delete
();
});
DB
::
commit
();
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City added.'
);
}
catch
(
\Exception
$e
)
{
DB
::
rollBack
();
clock
(
$e
);
return
Redirect
::
back
()
->
withErrors
(
$e
->
getMessage
());
}
}
...
...
@@ -274,6 +281,9 @@ class TokensController extends Controller
}
$dictionary
->
token
()
->
dissociate
();
$dictionary
->
dictionaryCampaigns
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
$dictionaryCampaign
->
delete
();
});
$dictionary
->
save
();
return
Redirect
::
route
(
'token.edit'
,
$token
->
getKey
())
->
with
(
'success'
,
'City deleted.'
);
...
...
app/Models/AdGroup.php
View file @
cc186b9
...
...
@@ -6,6 +6,7 @@ use App\Models\Pivots\GoalAdGroup;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
/**
...
...
@@ -74,6 +75,8 @@ use Illuminate\Support\Collection;
*/
class
AdGroup
extends
Model
{
use
SoftDeletes
;
const
STATUS_ACCEPTED
=
'ACCEPTED'
;
const
STATUS_DRAFT
=
'DRAFT'
;
const
STATUS_MODERATION
=
'MODERATION'
;
...
...
@@ -164,6 +167,7 @@ class AdGroup extends Model
static
::
created
(
function
(
AdGroup
$ad_group
)
{
if
(
$ad_group
->
campaign
)
{
$ad_group
->
campaign
->
copyGroupInGoalGroup
();
$ad_group
->
campaign
->
copyGroupInGoalKeyword
();
}
});
...
...
@@ -174,6 +178,7 @@ class AdGroup extends Model
}))
{
if
(
!
is_null
(
$ad_group
->
campaign_id
)
&&
is_null
(
$ad_group
->
getOriginal
(
'campaign_id'
)))
{
$ad_group
->
campaign
->
copyGroupInGoalGroup
();
$ad_group
->
campaign
->
copyGroupInGoalKeyword
();
}
else
{
$ad_group
->
goalGroups
()
->
update
(
GoalAdGroup
::
copyPropertyFromMain
(
$ad_group
)
...
...
app/Models/Campaigns.php
View file @
cc186b9
...
...
@@ -181,8 +181,6 @@ class Campaigns extends Model
static
::
created
(
function
(
Campaigns
$campaign
)
{
if
(
$campaign
->
manage
)
{
$campaign
->
copyInGoalCampaign
();
$campaign
->
copyGroupInGoalGroup
();
$campaign
->
copyGroupInGoalKeyword
();
}
});
...
...
@@ -191,21 +189,13 @@ class Campaigns extends Model
if
(
$campaign
->
manage
!==
$campaign
->
getOriginal
(
'manage'
))
{
if
(
$campaign
->
manage
)
{
$campaign
->
copyInGoalCampaign
();
$campaign
->
copyGroupInGoalGroup
();
$campaign
->
copyGroupInGoalKeyword
();
}
else
{
$campaign
->
dictionaries
()
->
detach
();
$campaign
->
dictionaryCampaigns
()
->
get
()
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
$dictionaryCampaign
->
delete
();
});
}
}
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
$campaign
->
dictionaryCampaigns
()
->
enabled
()
->
forUpdated
()
->
update
(
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
)
);
}
if
(
self
::
getPropertiesWatch
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
...
...
@@ -217,15 +207,13 @@ class Campaigns extends Model
});
}
p
rivate
function
copyInGoalCampaign
()
p
ublic
function
copyInGoalCampaign
()
{
$campaign
=
$this
;
Dictionary
::
whereNotNull
(
'token_id'
)
->
get
()
->
each
(
function
(
Dictionary
$dictionary
)
use
(
$campaign
)
{
$campaign
->
dictionaries
()
->
syncWithoutDetaching
([
$dictionary
->
getKey
()
=>
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
),
]);
DictionaryCampaign
::
updateOrCreateByMain
(
$campaign
,
$dictionary
,
true
);
});
}
...
...
@@ -234,15 +222,11 @@ class Campaigns extends Model
{
$campaign
=
$this
;
$campaign
->
dictionaryCampaigns
()
->
get
()
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$campaign
->
dictionaryCampaigns
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$campaign
->
groups
()
->
get
()
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
$campaign
->
groups
->
each
(
function
(
AdGroup
$adGroup
)
use
(
$dictionaryCampaign
)
{
GoalAdGroup
::
updateOrCreate
([
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'ad_group_id'
=>
$adGroup
->
getKey
(),
],
GoalAdGroup
::
copyPropertyFromMain
(
$adGroup
));
GoalAdGroup
::
updateOrCreateByMain
(
$adGroup
,
$dictionaryCampaign
);
});
...
...
@@ -253,19 +237,14 @@ class Campaigns extends Model
{
$campaign
=
$this
;
$campaign
->
dictionaryCampaigns
()
->
get
()
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$dictionaryCampaign
->
groups
()
->
get
()
->
each
(
function
(
GoalAdGroup
$goalAdGroup
)
use
(
$campaign
,
$dictionaryCampaign
)
{
$campaign
->
dictionaryCampaigns
->
each
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
use
(
$campaign
)
{
$dictionaryCampaign
->
groups
->
each
(
function
(
GoalAdGroup
$goalAdGroup
)
use
(
$campaign
,
$dictionaryCampaign
)
{
$goalAdGroup
->
group
->
keywords
()
->
where
(
'campaign_id'
,
$campaign
->
getKey
())
->
get
()
->
each
(
function
(
Keyword
$keyword
)
use
(
$dictionaryCampaign
,
$goalAdGroup
)
{
GoalKeyword
::
updateOrCreate
([
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'goal_ad_group_id'
=>
$goalAdGroup
->
getKey
(),
'goal_ad_group_external_id'
=>
$goalAdGroup
->
external_id
,
'keyword_id'
=>
$keyword
->
getKey
(),
],
GoalKeyword
::
copyPropertyFromMain
(
$keyword
));
GoalKeyword
::
updateOrCreateByMain
(
$keyword
,
$goalAdGroup
,
$dictionaryCampaign
);
});
...
...
app/Models/Keyword.php
View file @
cc186b9
...
...
@@ -5,6 +5,7 @@ namespace App\Models;
use
App\Models\Pivots\GoalKeyword
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
/**
...
...
@@ -54,6 +55,8 @@ use Illuminate\Support\Collection;
*/
class
Keyword
extends
Model
{
use
SoftDeletes
;
const
STRATEGY_PRIORITY_LOW
=
'LOW'
;
const
STRATEGY_PRIORITY_NORMAL
=
'NORMAL'
;
const
STRATEGY_PRIORITY_HIGH
=
'HIGH'
;
...
...
@@ -139,6 +142,14 @@ class Keyword extends Model
}
});
static
::
deleted
(
function
(
Keyword
$keyword
)
{
if
(
!
$keyword
->
isForceDeleting
())
{
$keyword
->
goalKeywords
->
each
(
function
(
GoalKeyword
$goalKeyword
)
{
$goalKeyword
->
delete
();
});
}
});
}
public
function
goalKeywords
()
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
cc186b9
...
...
@@ -5,8 +5,10 @@ namespace App\Models\Pivots;
use
App\Models\Campaigns
;
use
App\Models\Dictionary
;
use
App\Models\Variable
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
/**
...
...
@@ -16,10 +18,10 @@ use Illuminate\Support\Collection;
* @property-read Dictionary $dictionary
* @property-read DictionaryCampaignVariable[] $dictionaryCampaignVariables
* @property-read Variable[] $variables
* @property-read GoalAdGroup[] $groups
* @property-read GoalAdGroup[] $groupsForNotExternal
* @property-read GoalAdGroup[] $groupsForExternalForUpdatedSelf
* @property-read GoalAdGroup[] $groupsForExternalForNeedUpdated
* @property-read
\Illuminate\Database\Eloquent\Collection|
GoalAdGroup[] $groups
* @property-read
\Illuminate\Database\Eloquent\Collection|
GoalAdGroup[] $groupsForNotExternal
* @property-read
\Illuminate\Database\Eloquent\Collection|
GoalAdGroup[] $groupsForExternalForUpdatedSelf
* @property-read
\Illuminate\Database\Eloquent\Collection|
GoalAdGroup[] $groupsForExternalForNeedUpdated
* @mixin \Eloquent
* @property int $id
* @property int|null $external_id
...
...
@@ -44,6 +46,8 @@ use Illuminate\Support\Collection;
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needUpdated()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign enabled($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdated($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign needSynced()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign notNeedSynced()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synced($value = true)
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign synchronized()
* @method static \Illuminate\Database\Eloquent\Builder|DictionaryCampaign forUpdatedSelf()
...
...
@@ -81,6 +85,7 @@ use Illuminate\Support\Collection;
*/
class
DictionaryCampaign
extends
Pivot
{
use
SoftDeletes
;
protected
$table
=
'dictionary_campaigns'
;
...
...
@@ -100,6 +105,8 @@ class DictionaryCampaign extends Pivot
'updated'
,
'synced'
,
'disabled_at'
,
'deleted_at'
,
'synced_need'
,
];
protected
$casts
=
[
...
...
@@ -114,6 +121,7 @@ class DictionaryCampaign extends Pivot
'updated'
=>
'boolean'
,
'synced'
=>
'boolean'
,
'disabled_at'
=>
'datetime'
,
'synced_need'
=>
'datetime'
,
];
static
public
function
getWithPivot
()
...
...
@@ -133,6 +141,7 @@ class DictionaryCampaign extends Pivot
'updated'
,
'synced'
,
'disabled_at'
,
'synced_need'
,
];
}
...
...
@@ -173,6 +182,38 @@ class DictionaryCampaign extends Pivot
})
->
all
();
}
static
public
function
updateOrCreateByMain
(
Campaigns
$campaign
,
Dictionary
$dictionary
,
$syncedNeed
=
false
)
{
$data
=
[];
if
(
$syncedNeed
)
{
$data
[
'synced_need'
]
=
Carbon
::
now
();
}
return
DictionaryCampaign
::
updateOrCreate
([
'dictionary_id'
=>
$dictionary
->
getKey
(),
'campaign_id'
=>
$campaign
->
getKey
(),
'deleted_at'
=>
null
,
],
array_merge
(
DictionaryCampaign
::
copyPropertyFromMain
(
$campaign
),
$data
));
}
public
static
function
boot
()
{
parent
::
boot
();
static
::
deleted
(
function
(
DictionaryCampaign
$dictionaryCampaign
)
{
if
(
!
$dictionaryCampaign
->
forceDeleting
)
{
$dictionaryCampaign
->
groups
()
->
delete
();
$dictionaryCampaign
->
goalKeywords
()
->
delete
();
}
});
}
/**
* @param Builder $query
* @return Builder
...
...
@@ -233,6 +274,24 @@ class DictionaryCampaign extends Pivot
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedSynced
(
$query
)
{
return
$query
->
whereNotNull
(
'synced_need'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNotNeedSynced
(
$query
)
{
return
$query
->
whereNull
(
'synced_need'
);
}
/**
* @param Builder $query
* @return Builder
*/
public
function
scopeNeedUpdated
(
$query
)
{
return
$query
->
whereNotNull
(
'updated_need'
);
...
...
@@ -344,4 +403,9 @@ class DictionaryCampaign extends Pivot
return
$this
->
goalKeywords
()
->
needUpdated
();
}
public
function
goalKeywordsForExternalOnlyTrashed
()
{
return
$this
->
goalKeywords
()
->
forExternal
()
->
onlyTrashed
();
}
}
app/Models/Pivots/GoalAdGroup.php
View file @
cc186b9
...
...
@@ -6,6 +6,7 @@ use App\Models\AdGroup;
use
App\Models\Variable
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
/**
...
...
@@ -38,7 +39,7 @@ use Illuminate\Support\Collection;
* @method static Builder|GoalAdGroup newQuery()
* @method static Builder|GoalAdGroup query()
* @method static Builder|GoalAdGroup whereAdGroupId($value)
* @method static Builder|GoalAdGroup whereCampaignExternalId($value)
* @method static Builder|GoalAdGroup where
Dictionary
CampaignExternalId($value)
* @method static Builder|GoalAdGroup whereCreatedAt($value)
* @method static Builder|GoalAdGroup whereDictionaryCampaignId($value)
* @method static Builder|GoalAdGroup whereExternalId($value)
...
...
@@ -51,11 +52,10 @@ use Illuminate\Support\Collection;
* @method static Builder|GoalAdGroup whereUpdatedNeed($value)
* @method static Builder|GoalAdGroup whereUpdatedSelf($value)
* @mixin \Eloquent
* @property-read \App\Models\Pivots\GoalKeyword $goalKeywords
* @method static Builder|GoalAdGroup whereDictionaryCampaignExternalId($value)
*/
class
GoalAdGroup
extends
Pivot
{
use
SoftDeletes
;
protected
$table
=
'goal_ad_groups'
;
...
...
@@ -108,6 +108,16 @@ class GoalAdGroup extends Pivot
]);
}
static
public
function
updateOrCreateByMain
(
AdGroup
$adGroup
,
DictionaryCampaign
$dictionaryCampaign
)
{
return
GoalAdGroup
::
updateOrCreate
([
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'ad_group_id'
=>
$adGroup
->
getKey
(),
'deleted_at'
=>
null
,
],
GoalAdGroup
::
copyPropertyFromMain
(
$adGroup
));
}
/**
* @param AdGroup|array $ad_group
*
...
...
@@ -182,7 +192,7 @@ class GoalAdGroup extends Pivot
public
function
goalKeywords
()
{
return
$this
->
belongsTo
(
GoalKeyword
::
class
,
'goal_ad_group_id'
);
return
$this
->
hasMany
(
GoalKeyword
::
class
,
'goal_ad_group_id'
);
}
}
app/Models/Pivots/GoalKeyword.php
View file @
cc186b9
...
...
@@ -5,6 +5,7 @@ namespace App\Models\Pivots;
use
App\Models\Keyword
;
use
Illuminate\Database\Eloquent\Builder
;
use
Illuminate\Database\Eloquent\Relations\Pivot
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Support\Collection
;
/**
...
...
@@ -46,6 +47,8 @@ use Illuminate\Support\Collection;
class
GoalKeyword
extends
Pivot
{
use
SoftDeletes
;
protected
$table
=
'goal_keywords'
;
protected
$fillable
=
[
...
...
@@ -117,6 +120,18 @@ class GoalKeyword extends Pivot
->
all
();
}
static
public
function
updateOrCreateByMain
(
Keyword
$keyword
,
GoalAdGroup
$goalAdGroup
,
DictionaryCampaign
$dictionaryCampaign
)
{
return
GoalKeyword
::
updateOrCreate
([
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
'goal_ad_group_id'
=>
$goalAdGroup
->
getKey
(),
'goal_ad_group_external_id'
=>
$goalAdGroup
->
external_id
,
'keyword_id'
=>
$keyword
->
getKey
(),
'deleted_at'
=>
null
,
],
GoalKeyword
::
copyPropertyFromMain
(
$keyword
));
}
/**
* @param Builder $query
* @return Builder
...
...
app/Models/Tokens.php
View file @
cc186b9
...
...
@@ -192,6 +192,11 @@ class Tokens extends Model
return
$this
->
dictionaryCampaigns
()
->
forExternal
();
}
public
function
dictionaryCampaignsForExternalWithTrashed
()
{
return
$this
->
dictionaryCampaigns
()
->
forExternal
()
->
withTrashed
();
}
public
function
dictionaryCampaignsEnabledForExternal
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
();
...
...
@@ -224,7 +229,7 @@ class Tokens extends Model
public
function
dictionaryCampaignsEnabledForExternalSynchronized
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
synchronized
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
notNeedSynced
()
->
synchronized
();
}
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedSelf
()
...
...
@@ -234,7 +239,7 @@ class Tokens extends Model
public
function
dictionaryCampaignsEnabledForExternalSynchronizedUpdatedChildren
()
{
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
synchronized
()
->
forUpdatedChildren
();
return
$this
->
dictionaryCampaigns
()
->
enabled
()
->
forExternal
()
->
notNeedSynced
()
->
synchronized
()
->
forUpdatedChildren
();
}
public
function
campaignsForManaged
()
...
...
app/Service/Requests/Direct/AddKeywords.php
View file @
cc186b9
...
...
@@ -4,8 +4,10 @@ namespace App\Service\Requests\Direct;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -48,6 +50,7 @@ class AddKeywords extends DirectRequest
public
function
handle
(
$response
)
{
try
{
Log
::
debug
(
$response
);
if
(
!
isset
(
$response
[
'result'
][
'AddResults'
]))
{
Log
::
debug
(
$response
);
Log
::
debug
(
$this
->
getParams
());
...
...
@@ -94,13 +97,17 @@ class AddKeywords extends DirectRequest
$this
->
putParams
(
$params
);
$variables
=
Variable
::
all
();
$this
->
setParams
([
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
{
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
use
(
$variables
)
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionaryCampaign
,
$variables
);
$keyword
=
$goalKeyword
->
keyword
;
$data
=
[
'Keyword'
=>
$keyword
,
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$keyword
->
keyword
,
$list
)
->
get
()
,
'AdGroupId'
=>
$goalKeyword
->
goal_ad_group_external_id
,
];
...
...
@@ -116,14 +123,6 @@ class AddKeywords extends DirectRequest
$data
[
'StrategyPriority'
]
=
$keyword
->
strategy_priority
;
}
if
(
$keyword
->
state
)
{
$data
[
'State'
]
=
$keyword
->
state
;
}
if
(
$keyword
->
state
)
{
$data
[
'Status'
]
=
$keyword
->
state
;
}
if
(
$keyword
->
user_param_1
)
{
$data
[
'UserParam1'
]
=
$keyword
->
user_param_1
;
}
...
...
app/Service/Requests/Direct/DeleteKeywords.php
0 → 100644
View file @
cc186b9
<?php
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
class
DeleteKeywords
extends
DirectRequest
{
protected
$max_count
=
10000
;
protected
$timestamp
;
public
function
call
(
$params
=
null
)
{
$this
->
requestPrepare
(
$params
);
$process
=
new
ProcessCallLimitedAPI
(
$this
);
dispatch
(
$process
)
->
onQueue
(
'limits'
);
}
public
function
getObjectsCount
()
{
return
count
(
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
]);
}
public
function
slice
(
$maxObjects
)
:
?
APIRequest
{
return
$this
->
sliceByKey
(
$maxObjects
,
[
'SelectionCriteria'
,
'Ids'
]);
}
public
function
handle
(
$response
)
{
try
{
if
(
!
isset
(
$response
[
'result'
][
'DeleteResults'
]))
{
Log
::
debug
(
$response
);
Log
::
debug
(
$this
->
getParams
());
}
if
(
isset
(
$response
[
'result'
][
'Errors'
]))
{
Log
::
debug
(
$response
[
'Errors'
]);
Log
::
debug
(
$this
->
getParams
());
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
Log
::
debug
(
"DeleteKeywords, empty Id"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$this
->
getParams
());
continue
;
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
GoalKeyword
::
onlyTrashed
()
->
where
(
'external_id'
,
$external_id
)
->
forceDelete
();
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
throw
$e
;
}
}
private
function
requestPrepare
(
$params
)
{
$this
->
setService
(
'Keywords'
);
$this
->
setMethod
(
'delete'
);
$params
=
[
'SelectionCriteria'
=>
[
'Ids'
=>
$params
[
'ids'
],
],
];
$this
->
setParams
(
$params
);
}
}
app/Service/Requests/Direct/GetKeywords.php
View file @
cc186b9
...
...
@@ -90,9 +90,11 @@ class GetKeywords extends DirectRequest
->
keyBy
(
'external_id'
);
}
$ids
=
[];
foreach
(
$response
[
'result'
][
'Keywords'
]
as
$keyword
)
{
$ad_group
=
$ad_groups
->
firstWhere
(
'external_id'
,
$keyword
[
'AdGroupId'
]);
$ad_group
=
$ad_groups
->
get
((
string
)
$keyword
[
'AdGroupId'
]);
if
(
!
$ad_group
)
continue
;
...
...
@@ -109,20 +111,22 @@ class GetKeywords extends DirectRequest
'ad_group_id'
=>
$ad_group
->
getKey
(),
'campaign_id'
=>
$ad_group
->
campaign
->
getKey
(),
'keyword'
=>
$keyword
[
'Keyword'
],
'user_param_1'
=>
$keyword
[
'UserParam1'
],
'user_param_2'
=>
$keyword
[
'UserParam2'
],
'user_param_1'
=>
$keyword
[
'UserParam1'
]
??
null
,
'user_param_2'
=>
$keyword
[
'UserParam2'
]
??
null
,
'bid'
=>
$keyword
[
'Bid'
],
'context_bid'
=>
$keyword
[
'ContextBid'
],
'strategy_priority'
=>
$keyword
[
'StrategyPriority'
],
'strategy_priority'
=>
$keyword
[
'StrategyPriority'
]
??
null
,
'state'
=>
$keyword
[
'State'
],
'status'
=>
$keyword
[
'Status'
],
'serving_status'
=>
$keyword
[
'ServingStatus'
],
];
Keyword
::
updateOrCreate
([
$keyword
=
Keyword
::
updateOrCreate
([
'external_id'
=>
$external_id
],
$data
);
$ids
[]
=
$keyword
->
getKey
();
$ad_group
->
update
([
'keywords_loaded_at'
=>
Carbon
::
now
(),
]);
...
...
@@ -133,6 +137,8 @@ class GetKeywords extends DirectRequest
if
(
!
$goalKeyword
)
continue
;
$ids
[]
=
$goalKeyword
->
getKey
();
$data
=
[
'external_updated_at'
=>
Carbon
::
now
(),
];
...
...
@@ -147,6 +153,29 @@ class GetKeywords extends DirectRequest
}
if
(
$this
->
getToken
()
->
isMain
())
{
$keywordQuery
=
Keyword
::
query
();
if
(
isset
(
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds'
]))
{
$keywordQuery
->
whereIn
(
'ad_group_external_id'
,
$this
->
getParams
()[
'SelectionCriteria'
][
'AdGroupIds'
]);
}
else
{
$keywordQuery
->
whereIn
(
'ad_group_id'
,
$ad_groups
->
pluck
(
'id'
));
}
}
else
{
$keywordQuery
=
GoalKeyword
::
query
()
->
whereIn
(
'goal_ad_group_id'
,
$ad_groups
->
pluck
(
'id'
));
}
if
(
count
(
$ids
))
{
$keywordQuery
->
whereNotIn
(
'id'
,
$ids
);
}
$keywordQuery
->
get
()
->
each
(
function
(
$goalKeyword
)
{
/* @var $goalKeyword GoalKeyword|Keyword */
$goalKeyword
->
delete
();
});
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
throw
$e
;
...
...
app/Service/Requests/Direct/UpdateKeywords.php
View file @
cc186b9
...
...
@@ -3,15 +3,11 @@
namespace
App\Service\Requests\Direct
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Campaigns
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -55,7 +51,7 @@ class UpdateKeywords extends DirectRequest
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
Log
::
debug
(
"Update
AdGroup
, empty Id"
);
Log
::
debug
(
"Update
Keywords
, empty Id"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$this
->
getParams
());
continue
;
...
...
@@ -81,14 +77,18 @@ class UpdateKeywords extends DirectRequest
$this
->
setService
(
'Keywords'
);
$this
->
setMethod
(
'update'
);
$variables
=
Variable
::
all
();
$this
->
setParams
([
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
{
'Keywords'
=>
$this
->
goalKeywords
->
map
(
function
(
GoalKeyword
$goalKeyword
)
use
(
$variables
)
{
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$goalKeyword
->
dictionaryCampaign
,
$variables
);
$keyword
=
$goalKeyword
->
keyword
;
$data
=
[
'Id'
=>
$goalKeyword
->
external_id
,
'Keyword'
=>
$keyword
->
keyword
,
'Keyword'
=>
StrReplaceByVariables
::
getInstance
(
$keyword
->
keyword
,
$list
)
->
get
()
,
];
if
(
$keyword
->
user_param_1
)
{
...
...
database/migrations/2021_06_11_103110_add_keywords_and_goal_keywords_column_deleted_at.php
0 → 100644
View file @
cc186b9
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddKeywordsAndGoalKeywordsColumnDeletedAt
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'keywords'
,
function
(
Blueprint
$table
)
{
$table
->
softDeletes
();
});
Schema
::
table
(
'goal_keywords'
,
function
(
Blueprint
$table
)
{
$table
->
softDeletes
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
//
}
}
database/migrations/2021_06_11_105315_add_dictionary_campaigns_column_synced_need_and_deleted_at.php
0 → 100644
View file @
cc186b9
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddDictionaryCampaignsColumnSyncedNeedAndDeletedAt
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'dictionary_campaigns'
,
function
(
Blueprint
$table
)
{
$table
->
timestamp
(
'synced_need'
)
->
nullable
();
$table
->
softDeletes
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
//
}
}
database/migrations/2021_06_11_113017_add_ad_groups_and_goal_ad_groups_column_deleted_at.php
0 → 100644
View file @
cc186b9
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
AddAdGroupsAndGoalAdGroupsColumnDeletedAt
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
table
(
'ad_groups'
,
function
(
Blueprint
$table
)
{
$table
->
softDeletes
();
});
Schema
::
table
(
'goal_ad_groups'
,
function
(
Blueprint
$table
)
{
$table
->
softDeletes
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
//
}
}
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