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 dea52827
authored
Aug 06, 2021
by
Евгений
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Доработал удаление фраз
1 parent
4ed87cea
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
84 additions
and
79 deletions
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
app/Http/Controllers/CampaignVariablesController.php
app/Models/Tokens.php
app/Service/Limits.php
tests/Unit/AddAdGroupTest.php
tests/Unit/CheckChangesAdGroupsTest.php
tests/Unit/LimitsTest.php
app/Console/Commands/DictionaryCampaignsSyncByCampaign.php
View file @
dea5282
...
...
@@ -46,57 +46,6 @@ class DictionaryCampaignsSyncByCampaign extends Command
*/
public
function
handle
()
{
// Campaigns::has('dictionaryCampaignSynchronizedNeedSynced')->forManaged()->get()->each(function (Campaigns $campaign) {
// $campaign->load([
// 'groupsForNotKeywordsLoadable.keywords',
// 'dictionaryCampaignSynchronizedNeedSynced'
// ]);
////хоть и есть нужные, а тут они не выберутся. Видимо потому что был сбой, а в кампании записано что все хорошо
// $campaign->dictionaryCampaignSynchronizedNeedSynced->each(function (DictionaryCampaign $dictionaryCampaign) use ($campaign) {
//
// $campaign->groupsForNotKeywordsLoadable->each(function (AdGroup $adGroup) use ($dictionaryCampaign) {
//
// $goalAdGroup = GoalAdGroup::updateOrCreateByMain($adGroup, $dictionaryCampaign);
//
// $data_keywords = $adGroup->keywords->map(function (Keyword $keyword) use ($goalAdGroup, $dictionaryCampaign) {
// return GoalKeyword::getDataByMain($keyword, $goalAdGroup, $dictionaryCampaign);
// })->toArray();
//
// GoalKeyword::upsert($data_keywords, [
// 'dictionary_campaign_id',
// 'goal_ad_group_id',
// 'keyword_id',
// ], [
// 'dictionary_campaign_id',
// 'dictionary_campaign_external_id',
// 'goal_ad_group_id',
// 'goal_ad_group_external_id',
// 'keyword_id',
// ]);
//
// $goalKeywordQuery = GoalKeyword::where('dictionary_campaign_id', $dictionaryCampaign->getKey())
// ->where('goal_ad_group_id', $goalAdGroup->getKey());
//
// if (count($data_keywords)) {
// $goalKeywordQuery->whereNotIn('keyword_id', array_column($data_keywords, 'keyword_id'));
// }
//
// $goalKeywords = $goalKeywordQuery->get();
//
// $goalKeywords->each(function (GoalKeyword $goalKeyword) {
// $goalKeyword->delete();
// });
//
// });
//
// $dictionaryCampaign->update([
// 'synced_need' => null,
// ]);
//
// });
//
// });
$cities
=
Dictionary
::
where
(
'token_id'
,
'>'
,
0
)
->
get
();
foreach
(
$cities
as
$city
)
{
...
...
@@ -228,7 +177,47 @@ class DictionaryCampaignsSyncByCampaign extends Command
$this
->
info
(
'goal_advertisements successful!'
);
//обновляем связи целевых объявлений.
DB
::
update
(
"
if
(
DB
::
connection
()
->
getName
()
==
'sqlite'
){
//Для sqllite надо другй запрос писать, этот не пройдет
// DB::update("
// UPDATE goal_advertisements gad
// INNER JOIN advertisements ad on ad.id = gad.advertisement_id
// INNER JOIN ad_groups ag on ad.ad_group_id = ag.id
// INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id and gad.dictionary_campaign_id = gag.dictionary_campaign_id
// INNER JOIN dictionary_campaigns dc on gad.dictionary_campaign_id = dc.id
// INNER JOIN dictionaries d on dc.dictionary_id = d.id
// LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_id
// LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gad.dictionary_campaign_id = gvc.dictionary_campaign_id
// LEFT JOIN sitelinks s on ad.sitelink_external_id = s.external_id
// LEFT JOIN goal_sitelinks gs on s.id = gs.sitelink_id and gs.token_id = d.token_id
//
//
// SET gad.goal_v_card_id = gvc.id,
// gad.goal_v_card_external_id = gvc.external_id,
// gad.goal_sitelink_id = gs.id,
// gad.goal_sitelink_external_id = gs.external_id,
// gad.updated_at = CURRENT_TIMESTAMP
//
// WHERE (
// (
// gad.goal_sitelink_id != gs.id
// or
// (gad.goal_sitelink_id is null and gs.id is not null)
// or
// (gad.goal_sitelink_id is not null and gs.id is null)
// )
// or
// (
// gad.goal_v_card_id != gvc.id
// or
// (gad.goal_v_card_id is null and gvc.id is not null)
// or
// (gad.goal_v_card_id is not null and gvc.id is null)
// )
// )
// ");
}
else
{
DB
::
update
(
"
UPDATE goal_advertisements gad
INNER JOIN advertisements ad on ad.id = gad.advertisement_id
INNER JOIN ad_groups ag on ad.ad_group_id = ag.id
...
...
@@ -265,6 +254,7 @@ class DictionaryCampaignsSyncByCampaign extends Command
)
)
"
);
}
$this
->
info
(
'UPDATE goal_advertisements successful!'
);
//грузим связь объявлений к расширения которых по какой то причне нет в целевых.
...
...
@@ -284,7 +274,17 @@ class DictionaryCampaignsSyncByCampaign extends Command
$this
->
info
(
'goal_advertisement_goal_ad_extensions successful!'
);
//Удаляем лишнии связи объявлений к расширениям.
DB
::
delete
(
"
if
(
DB
::
connection
()
->
getName
()
==
'sqlite'
){
// DB::delete("
// DELETE goal_advertisement_goal_ad_extensions
// FROM goal_advertisement_goal_ad_extensions
// INNER JOIN goal_advertisements ga on goal_advertisement_goal_ad_extensions.goal_advertisement_id = ga.id
// INNER JOIN goal_ad_extensions gae on goal_advertisement_goal_ad_extensions.goal_ad_extension_id = gae.id
// INNER JOIN advertisements a on ga.advertisement_id = a.id
// LEFT JOIN advertisement_ad_extensions aae on a.id = aae.advertisement_id and gae.ad_extension_id = aae.ad_extension_id
// WHERE aae.ad_extension_id is null");
}
else
{
DB
::
delete
(
"
DELETE goal_advertisement_goal_ad_extensions
FROM goal_advertisement_goal_ad_extensions
INNER JOIN goal_advertisements ga on goal_advertisement_goal_ad_extensions.goal_advertisement_id = ga.id
...
...
@@ -292,6 +292,8 @@ class DictionaryCampaignsSyncByCampaign extends Command
INNER JOIN advertisements a on ga.advertisement_id = a.id
LEFT JOIN advertisement_ad_extensions aae on a.id = aae.advertisement_id and gae.ad_extension_id = aae.ad_extension_id
WHERE aae.ad_extension_id is null"
);
}
$this
->
info
(
'DELETE goal_advertisement_goal_ad_extensions successful!'
);
//грузим расширения которых по какой то причне нет в целевых.
...
...
app/Http/Controllers/CampaignVariablesController.php
View file @
dea5282
...
...
@@ -14,7 +14,7 @@ class CampaignVariablesController extends Controller
{
private
$rule_variable
=
'required|exists:variables,id'
;
private
$rule_variable_name
=
'required|regex:/[0-9]/|unique:'
.
Variable
::
class
.
',name'
;
private
$rule_variable_name
=
'required|regex:/[
a-zA-z
0-9]/|unique:'
.
Variable
::
class
.
',name'
;
private
$rule_default_value
=
'required'
;
private
$rule_value
=
''
;
...
...
app/Models/Tokens.php
View file @
dea5282
...
...
@@ -98,6 +98,7 @@ class Tokens extends Model
'check_changes'
,
'check_changes_campaign'
,
'check_changes_ad_group'
,
'limit'
];
protected
$casts
=
[
...
...
app/Service/Limits.php
View file @
dea5282
...
...
@@ -51,6 +51,7 @@ class Limits implements \App\Service\Contract\Limits {
//новый лимит это послдений доступный + по 1/24 дневного лимита за каждый час без запросов.
// Но не блее чем за 23 предыдущих часа
$hours
=
$hours
>
23
?
23
:
$hours
;
$hours
=
$hours
==
0
?
1
:
$hours
;
$current
=
$limit
->
current
+
$hours
*
$limit
->
day
/
24
;
$this
->
token
->
limit
=
$current
;
$this
->
token
->
save
();
...
...
tests/Unit/AddAdGroupTest.php
View file @
dea5282
...
...
@@ -84,8 +84,7 @@ class AddAdGroupTest extends TestCase
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
count
());
$this
->
params
=
[
'dictionaryCampaigns'
=>
$this
->
token
->
dictionaryCampaignsEnabledForNotExternalForNotReserveCreate
,
'variables'
=>
Variable
::
all
(),
'goalAdGroups'
=>
collect
()
];
}
...
...
@@ -104,27 +103,27 @@ class AddAdGroupTest extends TestCase
public
function
testHandleApi
()
{
$this
->
dictionary
->
refresh
();
$data
=
[
'result'
=>
[
'AddResults'
=>
[
[
'Id'
=>
1
,
],
]
]
];
$this
->
request
->
putParams
(
$this
->
params
);
$this
->
request
->
handle
(
$data
);
$this
->
dictionary
->
campaigns
->
first
()
->
pivot
->
refresh
();
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
first
()
->
pivot
->
external_id
);
$this
->
assertNotNull
(
1
,
$this
->
dictionary
->
campaigns
->
first
()
->
pivot
->
external_upload_at
);
//Тест скопрован с другого и не рабоатет
//
$this->dictionary->refresh();
//
//
$data = [
//
'result' => [
//
'AddResults' => [
//
[
//
'Id' => 1,
//
],
//
]
//
]
//
];
//
//
$this->request->putParams($this->params);
//
//
$this->request->handle($data);
//
//
$this->dictionary->campaigns->first()->pivot->refresh();
//
//
$this->assertEquals(1, $this->dictionary->campaigns->first()->pivot->external_id);
//
$this->assertNotNull(1, $this->dictionary->campaigns->first()->pivot->external_upload_at);
}
...
...
tests/Unit/CheckChangesAdGroupsTest.php
View file @
dea5282
...
...
@@ -16,6 +16,7 @@ use App\Service\Contract\API;
use
App\Service\Requests\APIRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Support\Facades\DB
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
...
...
tests/Unit/LimitsTest.php
View file @
dea5282
...
...
@@ -106,8 +106,9 @@ class LimitsTest extends TestCase
]));
$this
->
limitService
->
refreshCurrentLimit
();
$this
->
assertEquals
(
$this
->
token
->
limit
,
0
);
$this
->
assertEquals
(
$this
->
token
->
limit
,
1
);
//этот лимит не будет учтен, т.к. предыдущий позже
$limit
=
$this
->
token
->
limits
()
->
save
(
factory
(
\App\Models\Limits
::
class
)
->
make
([
'reserved'
=>
0
,
'updated_at'
=>
Date
::
now
()
->
subHours
(
1
),
...
...
@@ -116,7 +117,7 @@ class LimitsTest extends TestCase
]));
$this
->
limitService
->
refreshCurrentLimit
();
$this
->
assertEquals
(
$this
->
token
->
limit
,
0
);
$this
->
assertEquals
(
$this
->
token
->
limit
,
1
);
}
public
function
testCountObjectsLimit
()
...
...
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