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 ae81013d
authored
Jun 16, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#20290 Изменить замену переменных
1 parent
f66a2b18
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
16 deletions
app/Models/Pivots/GoalKeyword.php
app/Models/Variable.php
app/Service/Requests/Direct/GetAdGroups.php
app/Service/StrReplaceByVariables.php
tests/Unit/CheckChangesAdGroupsTest.php
app/Models/Pivots/GoalKeyword.php
View file @
ae81013
...
...
@@ -124,8 +124,6 @@ class GoalKeyword extends Pivot
static
public
function
updateOrCreateByMain
(
Keyword
$keyword
,
GoalAdGroup
$goalAdGroup
,
DictionaryCampaign
$dictionaryCampaign
)
{
if
(
!
$goalAdGroup
->
getKey
())
\Log
::
debug
(
$goalAdGroup
);
return
GoalKeyword
::
updateOrCreate
([
'dictionary_campaign_id'
=>
$dictionaryCampaign
->
getKey
(),
'dictionary_campaign_external_id'
=>
$dictionaryCampaign
->
external_id
,
...
...
app/Models/Variable.php
View file @
ae81013
...
...
@@ -38,7 +38,10 @@ class Variable extends Model
public
static
function
getListVariablesByDictionaryCampaign
(
DictionaryCampaign
$dictionaryCampaign
,
$variables
=
null
)
{
$variable_list
=
[];
$variable_list
=
[
'vars'
=>
[],
'values'
=>
[],
];
if
(
!
$variables
)
{
$variables
=
Variable
::
all
();
...
...
@@ -53,7 +56,8 @@ class Variable extends Model
:
$variable
->
default_value
);
$variable_list
[
$variable
->
name
]
=
$value
;
$variable_list
[
'vars'
][]
=
$variable
->
name
;
$variable_list
[
'values'
][]
=
$value
;
}
return
$variable_list
;
...
...
app/Service/Requests/Direct/GetAdGroups.php
View file @
ae81013
...
...
@@ -56,8 +56,6 @@ class GetAdGroups extends DirectRequest
try
{
$external_ids
=
[];
\Log
::
debug
(
$response
);
if
(
!
isset
(
$response
[
'result'
][
'AdGroups'
]))
{
return
;
}
...
...
@@ -85,8 +83,6 @@ class GetAdGroups extends DirectRequest
->
keyBy
(
'external_id'
);
}
\Log
::
debug
(
$campaigns
);
foreach
(
$response
[
'result'
][
'AdGroups'
]
as
$ad_group
)
{
$external_id
=
(
string
)
$ad_group
[
'CampaignId'
];
...
...
@@ -94,8 +90,6 @@ class GetAdGroups extends DirectRequest
$campaign
=
$campaigns
->
firstWhere
(
'external_id'
,
$external_id
);
if
(
!
$campaign
)
{
\Log
::
debug
(
'Not Fround campaign for external_id'
);
\Log
::
debug
(
$external_id
);
continue
;
}
...
...
app/Service/StrReplaceByVariables.php
View file @
ae81013
...
...
@@ -8,7 +8,6 @@ use App\Models\Variable;
class
StrReplaceByVariables
{
private
$delimer
=
'%'
;
private
$str
;
private
$list
;
...
...
@@ -23,10 +22,8 @@ class StrReplaceByVariables
$list
=
Variable
::
getListVariablesByDictionaryCampaign
(
$dictionaryCampaign
);
}
foreach
(
$list
as
$key
=>
$variable
)
{
// $list["{$this->delimer}{$key}{$this->delimer}"] = $variable;
// unset($list[$key]);
$list
[
$key
]
=
$variable
;
foreach
(
$list
[
'vars'
]
as
$key
=>
$var
)
{
$list
[
'vars'
][
$key
]
=
"/\b
{
$var
}
\b/"
;
}
$this
->
str
=
$str
;
...
...
@@ -43,7 +40,7 @@ class StrReplaceByVariables
*/
public
function
get
()
{
return
strtr
(
$this
->
str
,
$this
->
list
);
return
preg_replace
(
$this
->
list
[
'vars'
],
$this
->
list
[
'values'
],
$this
->
str
);
}
}
tests/Unit/CheckChangesAdGroupsTest.php
View file @
ae81013
...
...
@@ -2,6 +2,7 @@
namespace
Tests\Unit
;
use
App\Console\Commands\DictionaryCampaignsSyncByCampaign
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Account
;
use
App\Models\AdGroup
;
...
...
@@ -14,6 +15,7 @@ use App\Models\User;
use
App\Service\Contract\API
;
use
App\Service\Requests\APIRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Artisan
;
use
Illuminate\Support\Facades\Queue
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
...
...
@@ -72,6 +74,8 @@ class CheckChangesAdGroupsTest extends TestCase
'campaign_id'
=>
$this
->
campaign
->
getKey
(),
]);
Artisan
::
call
(
DictionaryCampaignsSyncByCampaign
::
class
);
$this
->
request_main
=
APIRequest
::
getInstance
(
API
::
YANDEX
)
->
setToken
(
$this
->
token_main
)
->
getRequest
(
'Changes'
,
'check'
);
...
...
@@ -173,6 +177,8 @@ class CheckChangesAdGroupsTest extends TestCase
$this
->
ad_group
->
refresh
();
Artisan
::
call
(
DictionaryCampaignsSyncByCampaign
::
class
);
$this
->
assertEquals
(
0
,
AdGroup
::
forUpdatedSelf
()
->
count
());
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
$this
->
ad_group
->
name
);
$this
->
assertEquals
(
$this
->
ad_group_data
[
'result'
][
'AdGroups'
][
0
][
'Name'
],
GoalAdGroup
::
first
()
->
name
);
...
...
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