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 8a52ff1b
authored
Jun 17, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20304 Проблемы на epl3
1 parent
2373d96a
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
153 additions
and
16 deletions
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Console/Commands/KeywordsDelete.php
app/Models/Keyword.php
app/Models/Pivots/DictionaryCampaign.php
app/Models/Pivots/GoalKeyword.php
app/Models/Pivots/GoalKeywordDelete.php
app/Models/Tokens.php
app/Service/Requests/Direct/DeleteKeywords.php
database/migrations/2021_06_17_121424_create_goal_keywords_unique.php
database/migrations/2021_06_17_152240_create_goal_keywords_delete_table.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
8a52ff1
...
@@ -61,18 +61,14 @@ class DictionaryCampaignsSyncByCampaign extends Command
...
@@ -61,18 +61,14 @@ class DictionaryCampaignsSyncByCampaign extends Command
GoalKeyword
::
upsert
(
$data_keywords
,
[
GoalKeyword
::
upsert
(
$data_keywords
,
[
'dictionary_campaign_id'
,
'dictionary_campaign_id'
,
'dictionary_campaign_external_id'
,
'goal_ad_group_id'
,
'goal_ad_group_id'
,
'goal_ad_group_external_id'
,
'keyword_id'
,
'keyword_id'
,
'deleted_at'
,
],
[
],
[
'dictionary_campaign_id'
,
'dictionary_campaign_id'
,
'dictionary_campaign_external_id'
,
'dictionary_campaign_external_id'
,
'goal_ad_group_id'
,
'goal_ad_group_id'
,
'goal_ad_group_external_id'
,
'goal_ad_group_external_id'
,
'keyword_id'
,
'keyword_id'
,
'deleted_at'
,
]);
]);
$goalKeywordQuery
=
GoalKeyword
::
where
(
'dictionary_campaign_id'
,
$dictionaryCampaign
->
getKey
())
$goalKeywordQuery
=
GoalKeyword
::
where
(
'dictionary_campaign_id'
,
$dictionaryCampaign
->
getKey
())
...
...
app/Console/Commands/KeywordsDelete.php
View file @
8a52ff1
...
@@ -40,9 +40,9 @@ class KeywordsDelete extends Command
...
@@ -40,9 +40,9 @@ class KeywordsDelete extends Command
*/
*/
public
function
handle
()
public
function
handle
()
{
{
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsForExternalWithTrashed.goalKeywords
ForExternalOnlyTrashed
'
)
$tokens
=
Tokens
::
whereHas
(
'dictionaryCampaignsForExternalWithTrashed.goalKeywords
Delete
'
)
->
with
([
->
with
([
'dictionaryCampaignsForExternalWithTrashed.goalKeywords
ForExternalOnlyTrashed
'
,
'dictionaryCampaignsForExternalWithTrashed.goalKeywords
Delete
'
,
])
])
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
where
(
'type'
,
'!='
,
Tokens
::
MAIN
)
->
get
();
->
get
();
...
@@ -53,7 +53,7 @@ class KeywordsDelete extends Command
...
@@ -53,7 +53,7 @@ class KeywordsDelete extends Command
$factory
->
getRequest
(
'Keywords'
,
'delete'
)
$factory
->
getRequest
(
'Keywords'
,
'delete'
)
->
call
([
->
call
([
'ids'
=>
$token
->
dictionaryCampaignsForExternalWithTrashed
->
pluck
(
'goalKeywords
ForExternalOnlyTrashed
'
)
'ids'
=>
$token
->
dictionaryCampaignsForExternalWithTrashed
->
pluck
(
'goalKeywords
Delete
'
)
->
collapse
()
->
collapse
()
->
pluck
(
'external_id'
)
->
pluck
(
'external_id'
)
->
toArray
(),
->
toArray
(),
...
...
app/Models/Keyword.php
View file @
8a52ff1
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
App\Models
;
namespace
App\Models
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Pivots\GoalKeywordDelete
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
use
Illuminate\Database\Eloquent\SoftDeletes
;
...
@@ -111,11 +112,19 @@ class Keyword extends Model
...
@@ -111,11 +112,19 @@ class Keyword extends Model
parent
::
boot
();
parent
::
boot
();
static
::
deleted
(
function
(
Keyword
$keyword
)
{
static
::
deleted
(
function
(
Keyword
$keyword
)
{
if
(
!
$keyword
->
isForceDeleting
())
{
if
(
!
$keyword
->
isForceDeleting
())
{
$keyword
->
goalKeywords
->
each
(
function
(
GoalKeyword
$goalKeyword
)
{
$keyword
->
goalKeywords
->
each
(
function
(
GoalKeyword
$goalKeyword
)
{
GoalKeywordDelete
::
updateOrCreateByMain
(
$goalKeyword
);
$goalKeyword
->
delete
();
$goalKeyword
->
delete
();
});
});
}
}
});
});
}
}
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
8a52ff1
...
@@ -82,6 +82,8 @@ use Illuminate\Support\Collection;
...
@@ -82,6 +82,8 @@ use Illuminate\Support\Collection;
* @method static Builder|DictionaryCampaign whereUpdatedSelf($value)
* @method static Builder|DictionaryCampaign whereUpdatedSelf($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalKeyword[] $goalKeywords
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalKeyword[] $goalKeywords
* @property-read int|null $goal_keywords_count
* @property-read int|null $goal_keywords_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Pivots\GoalKeywordDelete[] $goalKeywordsDelete
* @property-read int|null $goal_keywords_delete_count
*/
*/
class
DictionaryCampaign
extends
Pivot
class
DictionaryCampaign
extends
Pivot
{
{
...
@@ -426,9 +428,9 @@ class DictionaryCampaign extends Pivot
...
@@ -426,9 +428,9 @@ class DictionaryCampaign extends Pivot
return
$this
->
goalKeywords
()
->
needUpdated
();
return
$this
->
goalKeywords
()
->
needUpdated
();
}
}
public
function
goalKeywords
ForExternalOnlyTrashed
()
public
function
goalKeywords
Delete
()
{
{
return
$this
->
goalKeywords
()
->
forExternal
()
->
onlyTrashed
(
);
return
$this
->
hasMany
(
GoalKeywordDelete
::
class
,
'dictionary_campaign_id'
);
}
}
}
}
app/Models/Pivots/GoalKeyword.php
View file @
8a52ff1
...
@@ -47,8 +47,6 @@ use Illuminate\Support\Collection;
...
@@ -47,8 +47,6 @@ use Illuminate\Support\Collection;
class
GoalKeyword
extends
Pivot
class
GoalKeyword
extends
Pivot
{
{
use
SoftDeletes
;
protected
$table
=
'goal_keywords'
;
protected
$table
=
'goal_keywords'
;
protected
$fillable
=
[
protected
$fillable
=
[
...
@@ -130,7 +128,6 @@ class GoalKeyword extends Pivot
...
@@ -130,7 +128,6 @@ class GoalKeyword extends Pivot
'goal_ad_group_id'
=>
$goalAdGroup
->
getKey
(),
'goal_ad_group_id'
=>
$goalAdGroup
->
getKey
(),
'goal_ad_group_external_id'
=>
$goalAdGroup
->
external_id
,
'goal_ad_group_external_id'
=>
$goalAdGroup
->
external_id
,
'keyword_id'
=>
$keyword
->
getKey
(),
'keyword_id'
=>
$keyword
->
getKey
(),
'deleted_at'
=>
null
,
];
];
}
}
...
...
app/Models/Pivots/GoalKeywordDelete.php
0 → 100644
View file @
8a52ff1
<?php
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
;
/**
* App\Models\Pivots\GoalKeywordDelete
*
* @property int $id
* @property int $external_id
* @property int $dictionary_campaign_external_id
* @property int $goal_ad_group_external_id
* @property int $dictionary_campaign_id
* @property int $goal_ad_group_id
* @property int $keyword_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read Keyword $keyword
* @method static Builder|GoalKeyword newModelQuery()
* @method static Builder|GoalKeyword newQuery()
* @method static Builder|GoalKeyword query()
* @method static Builder|GoalKeyword whereCreatedAt($value)
* @method static Builder|GoalKeyword whereDictionaryCampaignExternalId($value)
* @method static Builder|GoalKeyword whereDictionaryCampaignId($value)
* @method static Builder|GoalKeyword whereExternalId($value)
* @method static Builder|GoalKeyword whereExternalUpdatedAt($value)
* @method static Builder|GoalKeyword whereExternalUploadAt($value)
* @method static Builder|GoalKeyword whereGoalAdGroupExternalId($value)
* @method static Builder|GoalKeyword whereGoalAdGroupId($value)
* @method static Builder|GoalKeyword whereId($value)
* @method static Builder|GoalKeyword whereKeywordId($value)
* @method static Builder|GoalKeyword whereUpdatedAt($value)
* @method static Builder|GoalKeyword whereUpdatedNeed($value)
* @mixin \Eloquent
*/
class
GoalKeywordDelete
extends
Pivot
{
protected
$table
=
'goal_keywords_delete'
;
protected
$fillable
=
[
'external_id'
,
'goal_ad_group_external_id'
,
'dictionary_campaign_external_id'
,
'goal_ad_group_id'
,
'dictionary_campaign_id'
,
'keyword_id'
,
];
public
$incrementing
=
true
;
static
public
function
updateOrCreateByMain
(
GoalKeyword
$goalKeyword
)
{
if
(
!
$goalKeyword
->
external_id
||
!
$goalKeyword
->
goal_ad_group_external_id
||
!
$goalKeyword
->
dictionary_campaign_external_id
)
{
return
null
;
}
return
GoalKeywordDelete
::
updateOrCreate
([
'external_id'
=>
$goalKeyword
->
external_id
,
'goal_ad_group_external_id'
=>
$goalKeyword
->
goal_ad_group_external_id
,
'dictionary_campaign_external_id'
=>
$goalKeyword
->
dictionary_campaign_external_id
,
'goal_ad_group_id'
=>
$goalKeyword
->
goal_ad_group_id
,
'dictionary_campaign_id'
=>
$goalKeyword
->
dictionary_campaign_id
,
'keyword_id'
=>
$goalKeyword
->
keyword_id
,
]);
}
public
function
keyword
()
{
return
$this
->
belongsTo
(
Keyword
::
class
,
'keyword_id'
);
}
public
function
dictionaryCampaign
()
{
return
$this
->
belongsTo
(
DictionaryCampaign
::
class
,
'dictionary_campaign_id'
);
}
}
app/Models/Tokens.php
View file @
8a52ff1
...
@@ -39,6 +39,7 @@ use Illuminate\Database\Eloquent\Model;
...
@@ -39,6 +39,7 @@ use Illuminate\Database\Eloquent\Model;
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaigns
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaigns
* @property-read int|null $dictionary_campaigns_count
* @property-read int|null $dictionary_campaigns_count
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsForExternalWithTrashed
* @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[] $dictionaryCampaignsEnabledForExternal
* @property-read \Illuminate\Database\Eloquent\Collection|DictionaryCampaign[] $dictionaryCampaignsEnabledForExternal
...
...
app/Service/Requests/Direct/DeleteKeywords.php
View file @
8a52ff1
...
@@ -7,6 +7,7 @@ use App\Models\Campaigns;
...
@@ -7,6 +7,7 @@ use App\Models\Campaigns;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\DictionaryCampaign
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Pivots\GoalKeywordDelete
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
...
@@ -60,7 +61,7 @@ class DeleteKeywords extends DirectRequest
...
@@ -60,7 +61,7 @@ class DeleteKeywords extends DirectRequest
$external_id
=
(
string
)
$delete_result
[
'Id'
];
$external_id
=
(
string
)
$delete_result
[
'Id'
];
GoalKeyword
::
onlyTrashed
()
->
where
(
'external_id'
,
$external_id
)
->
forceD
elete
();
GoalKeyword
Delete
::
where
(
'external_id'
,
$external_id
)
->
d
elete
();
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
...
...
database/migrations/2021_06_17_121424_create_goal_keywords_unique.php
View file @
8a52ff1
...
@@ -16,12 +16,10 @@ class CreateGoalKeywordsUnique extends Migration
...
@@ -16,12 +16,10 @@ class CreateGoalKeywordsUnique extends Migration
Schema
::
table
(
'goal_keywords'
,
function
(
Blueprint
$table
)
{
Schema
::
table
(
'goal_keywords'
,
function
(
Blueprint
$table
)
{
$table
->
unique
([
$table
->
unique
([
'dictionary_campaign_id'
,
'dictionary_campaign_id'
,
'dictionary_campaign_external_id'
,
'goal_ad_group_id'
,
'goal_ad_group_id'
,
'goal_ad_group_external_id'
,
'keyword_id'
,
'keyword_id'
,
'deleted_at'
,
],
'goal_keywords_unique'
);
],
'goal_keywords_unique'
);
$table
->
dropSoftDeletes
();
});
});
}
}
...
...
database/migrations/2021_06_17_152240_create_goal_keywords_delete_table.php
0 → 100644
View file @
8a52ff1
<?php
use
Illuminate\Database\Migrations\Migration
;
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Support\Facades\Schema
;
class
CreateGoalKeywordsDeleteTable
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
Schema
::
create
(
'goal_keywords_delete'
,
function
(
Blueprint
$table
)
{
$table
->
id
();
$table
->
bigInteger
(
'external_id'
)
->
nullable
();
$table
->
bigInteger
(
'dictionary_campaign_external_id'
)
->
nullable
();
$table
->
bigInteger
(
'goal_ad_group_external_id'
)
->
nullable
();
$table
->
bigInteger
(
'dictionary_campaign_id'
)
->
unsigned
();
$table
->
bigInteger
(
'goal_ad_group_id'
)
->
unsigned
();
$table
->
bigInteger
(
'keyword_id'
)
->
unsigned
();
$table
->
timestamps
();
$table
->
foreign
(
'dictionary_campaign_id'
)
->
references
(
'id'
)
->
on
(
'dictionary_campaigns'
)
->
cascadeOnDelete
();
$table
->
foreign
(
'goal_ad_group_id'
)
->
references
(
'id'
)
->
on
(
'goal_ad_groups'
)
->
cascadeOnDelete
();
$table
->
foreign
(
'keyword_id'
)
->
references
(
'id'
)
->
on
(
'keywords'
)
->
cascadeOnDelete
();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
dropIfExists
(
'goal_keywords_delete'
);
}
}
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