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 3f1ebeaf
authored
May 24, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19456 Запрос измененных РК и сохранение инфы об этом
1 parent
5f316da6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
14 deletions
app/Models/Campaigns.php
app/Models/Pivots/DictionaryCampaign.php
app/Service/Requests/Direct/AddCampaigns.php
app/Service/Requests/Direct/GetCampaigns.php
tests/Unit/CheckCampaignsTest.php
app/Models/Campaigns.php
View file @
3f1ebea
...
...
@@ -147,6 +147,9 @@ class Campaigns extends Model
$campaign
->
dictionaries
()
->
detach
();
}
}
// if ($campaign->name === 'change name')
// dd($campaign->dictionaryCampaigns()->synchronized()->get());
if
(
DictionaryCampaign
::
getPropertiesCopyWithPivot
()
->
first
(
function
(
$property_name
)
use
(
$campaign
)
{
return
$campaign
->
{
$property_name
}
!==
$campaign
->
getOriginal
(
$property_name
);
}))
{
...
...
app/Models/Pivots/DictionaryCampaign.php
View file @
3f1ebea
...
...
@@ -93,6 +93,8 @@ class DictionaryCampaign extends Pivot
static
public
function
getWithPivot
()
{
return
[
'id'
,
'external_id'
,
'name'
,
'negative_keywords'
,
'excluded_sites'
,
...
...
app/Service/Requests/Direct/AddCampaigns.php
View file @
3f1ebea
...
...
@@ -40,7 +40,6 @@ class AddCampaigns extends DirectRequest
$this
->
dictionaryCampaigns
->
get
(
$key
)
->
update
([
'external_id'
=>
$id
,
'external_upload_at'
=>
Carbon
::
now
(),
]);
}
}
catch
(
\Exception
$e
)
{
...
...
app/Service/Requests/Direct/GetCampaigns.php
View file @
3f1ebea
...
...
@@ -47,18 +47,6 @@ class GetCampaigns extends DirectRequest
$campaigns_data
[]
=
$data
;
}
if
(
$this
->
getToken
()
->
isMain
())
{
foreach
(
$campaigns_data
as
$campaign_data
)
{
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
->
find
(
$campaign_data
[
'external_id'
]);
if
(
!
$dictionaryCampaign
)
continue
;
$dictionaryCampaign
->
update
(
$dictionaryCampaign
::
copyPropertyInCampaign
(
$campaign_data
)
);
}
Campaigns
::
upsert
(
$campaigns_data
,
[
'external_id'
],
[
...
...
@@ -81,7 +69,17 @@ class GetCampaigns extends DirectRequest
'updated_children'
,
]);
}
else
{
foreach
(
$campaigns_data
as
$campaign_data
)
{
$dictionaryCampaign
=
DictionaryCampaign
::
synchronized
()
->
find
(
$campaign_data
[
'external_id'
]);
if
(
!
$dictionaryCampaign
)
continue
;
$dictionaryCampaign
->
update
(
$dictionaryCampaign
::
copyPropertyInCampaign
(
$campaign_data
)
);
}
}
}
catch
(
\Exception
$e
)
{
Log
::
debug
(
$e
);
...
...
tests/Unit/CheckCampaignsTest.php
View file @
3f1ebea
...
...
@@ -23,6 +23,7 @@ class CheckCampaignsTest extends TestCase
private
$token_main
;
private
$token
;
private
$dictionary
;
private
$request_main
;
protected
function
setUp
()
:
void
{
...
...
@@ -126,7 +127,9 @@ class CheckCampaignsTest extends TestCase
]))
->
assertStatus
(
302
);
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
()
->
count
());
$this
->
dictionary
->
load
(
'campaigns'
);
$this
->
assertEquals
(
1
,
$this
->
dictionary
->
campaigns
->
count
());
$this
->
request
->
handle
([
'result'
=>
[
...
...
@@ -148,5 +151,35 @@ class CheckCampaignsTest extends TestCase
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_self
);
$this
->
assertNotNull
(
$campaign
->
pivot
->
updated_children
);
$campaign
->
pivot
->
update
([
'external_id'
=>
1
,
'external_updated_at'
=>
null
,
]);
$campaign
->
update
([
'name'
=>
'change name'
,
]);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
1
,
$campaign
->
pivot
->
external_id
);
$this
->
assertEquals
(
'change name'
,
$campaign
->
name
);
$this
->
assertEquals
(
'change name'
,
$campaign
->
pivot
->
name
);
$campaign
->
pivot
->
update
([
'synced'
=>
false
,
]);
$campaign
->
update
([
'name'
=>
'edit name'
,
]);
$campaign
=
$this
->
dictionary
->
campaigns
()
->
first
();
$this
->
assertEquals
(
'edit name'
,
$campaign
->
name
);
$this
->
assertEquals
(
'change name'
,
$campaign
->
pivot
->
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