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 ed83aacf
authored
Sep 20, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Оптимизация изменения удаления
1 parent
b94659bc
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
420 additions
and
392 deletions
app/Console/Commands/BidModifiersAdd.php
app/Service/DirectResponseHelper.php
app/Service/Requests/Direct/DeleteAdGroups.php
app/Service/Requests/Direct/DeleteAds.php
app/Service/Requests/Direct/DeleteAudienceTarget.php
app/Service/Requests/Direct/DeleteVCards.php
app/Service/Requests/Direct/SetBidModifiers.php
app/Service/Requests/Direct/UpdateAdGroups.php
app/Service/Requests/Direct/UpdateAds.php
app/Service/Requests/Direct/UpdateCampaigns.php
app/Service/Requests/Direct/UpdateKeywords.php
app/Service/Requests/Direct/UpdateNegativeKeywordSharedSets.php
app/Service/Requests/Direct/UpdateRetargetinglists.php
app/Console/Commands/BidModifiersAdd.php
View file @
ed83aac
...
@@ -69,11 +69,13 @@ class BidModifiersAdd extends Command
...
@@ -69,11 +69,13 @@ class BidModifiersAdd extends Command
->
groupBy
([
->
groupBy
([
'goal_bid_modifiers.dictionary_campaign_external_id'
,
'goal_bid_modifiers.dictionary_campaign_external_id'
,
'goal_bid_modifiers.goal_ad_group_external_id'
,
'goal_bid_modifiers.goal_ad_group_external_id'
,
'dictionaries.region_id'
,
'dictionaries.token_id'
,
'bid_modifiers.mobile_adjustment'
,
'bid_modifiers.mobile_adjustment'
,
'bid_modifiers.desktop_adjustment'
,
'bid_modifiers.desktop_adjustment'
,
'bid_modifiers.video_adjustment'
,
'bid_modifiers.video_adjustment'
,
'dictionaries.region_id'
,
DB
::
raw
(
'bid_modifiers.demographics_adjustment IS NOT NULL'
)
,
'dictionaries.token_id'
,
DB
::
raw
(
'bid_modifiers.retargeting_adjustment IS NOT NULL'
)
,
])
])
->
select
([
->
select
([
DB
::
raw
(
'json_arrayagg(goal_bid_modifiers.id) as ids'
),
DB
::
raw
(
'json_arrayagg(goal_bid_modifiers.id) as ids'
),
...
...
app/Service/DirectResponseHelper.php
0 → 100644
View file @
ed83aac
<?php
namespace
App\Service
;
class
DirectResponseHelper
{
static
function
getExternalIdsChunkByResult
(
$data
)
{
return
array_chunk
(
array_column
(
array_filter
(
$data
,
function
(
$result
)
{
return
isset
(
$result
[
'Id'
]);
},
ARRAY_FILTER_USE_BOTH
),
'Id'
),
1000
);
}
}
app/Service/Requests/Direct/DeleteAdGroups.php
View file @
ed83aac
...
@@ -5,7 +5,9 @@ namespace App\Service\Requests\Direct;
...
@@ -5,7 +5,9 @@ namespace App\Service\Requests\Direct;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
DeleteAdGroups
extends
DirectRequest
class
DeleteAdGroups
extends
DirectRequest
...
@@ -37,43 +39,43 @@ class DeleteAdGroups extends DirectRequest
...
@@ -37,43 +39,43 @@ class DeleteAdGroups extends DirectRequest
return
;
return
;
}
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
GoalAdGroup
::
whereIn
(
'external_id'
,
$external_ids
)
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
->
delete
();
}
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
if
(
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
)
{
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteAdGroups, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
->
update
([
'reserve_delete_at'
=>
null
,
]);
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
continue
;
}
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
if
(
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
)
{
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteAdGroups, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
delete
();
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
}
}
...
...
app/Service/Requests/Direct/DeleteAds.php
View file @
ed83aac
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Advertisement
;
use
App\Models\Advertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
...
@@ -38,75 +39,73 @@ class DeleteAds extends DirectRequest
...
@@ -38,75 +39,73 @@ class DeleteAds extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
else
{
GoalAdvertisement
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
}
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
if
(
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
&&
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
)
{
if
(
if
(
$this
->
getToken
()
->
isMain
())
{
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
Advertisement
::
where
(
'external_id'
,
$external_id
)
&&
->
delete
();
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
}
else
{
)
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
if
(
$this
->
getToken
()
->
isMain
())
{
continue
;
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
else
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$goalAd
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$goalAd
)
{
$goalAd
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
$goalAd
->
update
([
'reserve_delete_at'
=>
null
,
]);
continue
;
continue
;
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
$goalAd
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$goalAd
)
{
$goalAd
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
$goalAd
->
update
([
'reserve_delete_at'
=>
null
,
]);
continue
;
}
}
}
}
else
{
Log
::
debug
(
"DeleteAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
"DeleteAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
Log
::
debug
(
$external_id
);
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
continue
;
}
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
where
(
'external_id'
,
$external_id
)
Advertisement
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
}
else
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
}
}
...
...
app/Service/Requests/Direct/DeleteAudienceTarget.php
View file @
ed83aac
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\AudienceTarget
;
use
App\Models\AudienceTarget
;
use
App\Models\Pivots\GoalAudienceTarget
;
use
App\Models\Pivots\GoalAudienceTarget
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
...
@@ -38,59 +39,58 @@ class DeleteAudienceTarget extends DirectRequest
...
@@ -38,59 +39,58 @@ class DeleteAudienceTarget extends DirectRequest
return
;
return
;
}
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
AudienceTarget
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
else
{
GoalAudienceTarget
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
}
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
continue
;
$model
=
AudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
}
else
{
$model
=
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
if
(
$model
)
{
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
if
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
Log
::
debug
(
"DeleteAudienceTargets, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
AudienceTarget
::
whereExternalId
(
$external_id
)
$model
=
AudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
}
else
{
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
$model
=
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
continue
;
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteAudienceTargets, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
AudienceTarget
::
whereExternalId
(
$external_id
)
AudienceTarget
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
}
else
{
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
}
}
...
...
app/Service/Requests/Direct/DeleteVCards.php
View file @
ed83aac
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalVCard
;
use
App\Models\Pivots\GoalVCard
;
use
App\Models\VCard
;
use
App\Models\VCard
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
...
@@ -38,72 +39,70 @@ class DeleteVCards extends DirectRequest
...
@@ -38,72 +39,70 @@ class DeleteVCards extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
VCard
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
else
{
GoalVCard
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
if
(
}
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
&&
if
(
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
)
{
&&
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
if
(
$this
->
getToken
()
->
isMain
())
{
)
{
VCard
::
whereExternalId
(
$external_id
)
->
delete
();
}
else
{
GoalVCard
::
whereExternalId
(
$external_id
)
->
delete
();
}
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
$model
=
VCard
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
$model
=
GoalVCard
::
whereExternalId
(
$external_id
)
->
first
();
}
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteVCards, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
VCard
::
whereExternalId
(
$external_id
)
VCard
::
whereExternalId
(
$external_id
)
->
update
([
->
delete
();
'reserve_delete_at'
=>
null
,
]);
}
else
{
}
else
{
GoalVCard
::
whereExternalId
(
$external_id
)
GoalVCard
::
whereExternalId
(
$external_id
)
->
update
([
->
delete
();
'reserve_delete_at'
=>
null
,
]);
}
}
continue
;
}
elseif
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
$model
=
VCard
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
$model
=
GoalVCard
::
whereExternalId
(
$external_id
)
->
first
();
}
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"DeleteVCards, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
}
$external_id
=
(
string
)
$delete_result
[
'Id'
];
if
(
$this
->
getToken
()
->
isMain
())
{
if
(
$this
->
getToken
()
->
isMain
())
{
VCard
::
whereExternalId
(
$external_id
)
VCard
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
}
else
{
GoalVCard
::
whereExternalId
(
$external_id
)
GoalVCard
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
}
}
...
...
app/Service/Requests/Direct/SetBidModifiers.php
View file @
ed83aac
...
@@ -5,7 +5,9 @@ namespace App\Service\Requests\Direct;
...
@@ -5,7 +5,9 @@ namespace App\Service\Requests\Direct;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalBidModifier
;
use
App\Models\Pivots\GoalBidModifier
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
SetBidModifiers
extends
DirectRequest
class
SetBidModifiers
extends
DirectRequest
...
@@ -37,50 +39,53 @@ class SetBidModifiers extends DirectRequest
...
@@ -37,50 +39,53 @@ class SetBidModifiers extends DirectRequest
return
;
return
;
}
}
foreach
(
$response
[
'result'
][
'SetResults'
]
as
$key
=>
$set_result
)
{
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'SetResults'
])
as
$external_ids
)
{
GoalBidModifier
::
whereIn
(
'external_id'
,
$external_ids
)
if
(
!
isset
(
$set_result
[
'Id'
]))
{
->
update
([
'updated_need'
=>
null
,
$data
=
$this
->
getParams
()[
'BidModifiers'
][
$key
];
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
$external_id
=
$data
[
'Id'
];
]);
}
if
(
isset
(
$set_result
[
'Errors'
][
0
][
'Message'
])
&&
$set_result
[
'Errors'
][
0
][
'Message'
]
===
'Object not found'
)
{
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
delete
();
}
elseif
(
isset
(
$set_result
[
'Errors'
])
&&
count
(
$set_result
[
'Errors'
]))
{
$model
=
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$set_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"UpdateBidModifier, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$set_result
);
Log
::
debug
(
$data
);
}
GoalBidModifier
::
whereExternalId
(
$external_id
)
foreach
(
$response
[
'result'
][
'SetResults'
]
as
$key
=>
$set_result
)
{
->
update
([
'reserve_update_at'
=>
null
,
]);
if
(
isset
(
$set_result
[
'Id'
]))
{
continue
;
continue
;
}
}
$
external_id
=
(
string
)
$set_result
[
'Id'
];
$
data
=
$this
->
getParams
()[
'BidModifiers'
][
$key
];
GoalBidModifier
::
where
(
'external_id'
,
$external_id
)
$external_id
=
$data
[
'Id'
];
if
(
isset
(
$set_result
[
'Errors'
][
0
][
'Message'
])
&&
$set_result
[
'Errors'
][
0
][
'Message'
]
===
'Object not found'
)
{
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
delete
();
}
elseif
(
isset
(
$set_result
[
'Errors'
])
&&
count
(
$set_result
[
'Errors'
]))
{
$model
=
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$set_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"UpdateBidModifier, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$set_result
);
Log
::
debug
(
$data
);
}
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
}
}
}
}
...
...
app/Service/Requests/Direct/UpdateAdGroups.php
View file @
ed83aac
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
...
@@ -40,44 +41,44 @@ class UpdateAdGroups extends DirectRequest
...
@@ -40,44 +41,44 @@ class UpdateAdGroups extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
GoalAdGroup
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
}
$data
=
$this
->
getParams
()[
'AdGroups'
][
$key
];
$data
=
$this
->
getParams
()[
'AdGroups'
][
$key
];
$external_id
=
$data
[
'Id'
];
$external_id
=
$data
[
'Id'
];
if
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
if
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
forceDelete
();
$model
->
forceDelete
();
}
}
else
{
Log
::
debug
(
"UpdateAdGroup, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
}
}
else
{
GoalAdGroup
::
withTrashed
()
->
whereExternalId
(
$this
->
getParams
()[
'AdGroups'
][
$key
][
'Id'
])
Log
::
debug
(
"UpdateAdGroup, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
->
update
([
Log
::
debug
(
$update_result
);
'reserve_update_at'
=>
null
,
Log
::
debug
(
$data
);
]);
continue
;
}
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdGroup
::
withTrashed
()
->
whereExternalId
(
$this
->
getParams
()[
'AdGroups'
][
$key
][
'Id'
])
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
...
...
app/Service/Requests/Direct/UpdateAds.php
View file @
ed83aac
...
@@ -7,6 +7,7 @@ use App\Models\Advertisement;
...
@@ -7,6 +7,7 @@ use App\Models\Advertisement;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
...
@@ -41,57 +42,57 @@ class UpdateAds extends DirectRequest
...
@@ -41,57 +42,57 @@ class UpdateAds extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
GoalAdvertisement
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
$data
=
$this
->
getParams
()[
'Ads'
][
$key
];
}
$external_id
=
$data
[
'Id'
];
$data
=
$this
->
getParams
()[
'Ads'
][
$key
];
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'You cannot update an archived ad'
)
{
$external_id
=
$data
[
'Id'
];
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
continue
;
}
elseif
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'Ad not found'
)
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
delete
();
continue
;
}
elseif
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$model
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"UpdateAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
GoalAdvertisement
::
withTrashed
()
->
whereExternalId
(
$external_id
)
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'You cannot update an archived ad'
)
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
->
update
([
'reserve_update_at'
=>
null
,
'deleted_need'
=>
Carbon
::
now
(),
'archived_need'
=>
null
,
'reserve_archive_at'
=>
null
,
]);
]);
continue
;
continue
;
}
elseif
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'Ad not found'
)
{
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
delete
();
continue
;
}
elseif
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$model
=
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"UpdateAds, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdvertisement
::
withTrashed
()
->
whereExternalId
(
$external_id
)
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
...
...
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
ed83aac
...
@@ -8,6 +8,7 @@ use App\Models\Pivots\DictionaryCampaign;
...
@@ -8,6 +8,7 @@ use App\Models\Pivots\DictionaryCampaign;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Carbon\Carbon
;
...
@@ -42,48 +43,49 @@ class UpdateCampaigns extends DirectRequest
...
@@ -42,48 +43,49 @@ class UpdateCampaigns extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
DictionaryCampaign
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
}
$data
=
$this
->
getParams
()[
'Campaigns'
][
$key
];
$data
=
$this
->
getParams
()[
'Campaigns'
][
$key
];
$external_id
=
$data
[
'Id'
];
$external_id
=
$data
[
'Id'
];
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'It is forbidden to change an archived campaign'
)
{
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'It is forbidden to change an archived campaign'
)
{
DictionaryCampaign
::
whereExternalId
(
$external_id
)
->
delete
();
DictionaryCampaign
::
whereExternalId
(
$external_id
)
->
delete
();
}
elseif
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
}
elseif
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
delete
();
$model
->
delete
();
}
}
else
{
Log
::
debug
(
"UpdateCampaigns, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
}
}
else
{
DictionaryCampaign
::
withTrashed
()
->
whereExternalId
(
$external_id
)
Log
::
debug
(
"UpdateCampaigns, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
->
update
([
Log
::
debug
(
$update_result
);
'reserve_update_at'
=>
null
,
Log
::
debug
(
$data
);
]);
continue
;
}
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
DictionaryCampaign
::
withTrashed
()
->
whereExternalId
(
$external_id
)
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
}
}
$this
->
getToken
()
->
update
([
$this
->
getToken
()
->
update
([
...
...
app/Service/Requests/Direct/UpdateKeywords.php
View file @
ed83aac
...
@@ -7,8 +7,10 @@ use App\Models\Keyword;
...
@@ -7,8 +7,10 @@ use App\Models\Keyword;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
UpdateKeywords
extends
DirectRequest
class
UpdateKeywords
extends
DirectRequest
...
@@ -40,49 +42,49 @@ class UpdateKeywords extends DirectRequest
...
@@ -40,49 +42,49 @@ class UpdateKeywords extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
GoalKeyword
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
}
$data
=
$this
->
getParams
()[
'Keywords'
][
$key
];
$data
=
$this
->
getParams
()[
'Keywords'
][
$key
];
$external_id
=
$data
[
'Id'
];
$external_id
=
$data
[
'Id'
];
if
(
isset
(
$data
[
'Errors'
][
0
][
'Details'
])
&&
$data
[
'Errors'
][
0
][
'Details'
]
===
'Keyword not found'
)
{
if
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
GoalKeyword
::
whereExternalId
(
$external_id
)
->
delete
();
$goalKeyword
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$goalKeyword
)
{
}
elseif
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$goalKeyword
->
errors
()
->
create
([
$goalKeyword
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
$goalKeyword
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
}
else
{
Log
::
debug
(
"UpdateKeywords, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
GoalKeyword
::
whereExternalId
(
$external_id
)
if
(
$goalKeyword
)
{
->
update
([
$goalKeyword
->
errors
()
->
create
([
'reserve_update_at'
=>
null
,
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
]);
}
continue
;
}
else
{
Log
::
debug
(
"UpdateKeywords, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalKeyword
::
whereExternalId
(
$external_id
)
GoalKeyword
::
where
(
'external_id'
,
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
...
...
app/Service/Requests/Direct/UpdateNegativeKeywordSharedSets.php
View file @
ed83aac
...
@@ -7,8 +7,10 @@ use App\Models\NegativeKeywordSharedSet;
...
@@ -7,8 +7,10 @@ use App\Models\NegativeKeywordSharedSet;
use
App\Models\Pivots\GoalNegativeKeywordSharedSet
;
use
App\Models\Pivots\GoalNegativeKeywordSharedSet
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
...
@@ -53,41 +55,41 @@ class UpdateNegativeKeywordSharedSets extends DirectRequest
...
@@ -53,41 +55,41 @@ class UpdateNegativeKeywordSharedSets extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
GoalNegativeKeywordSharedSet
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
$goalNegativeKeywordSharedSet
=
$this
->
goalNegativeKeywordSharedSets
->
get
(
$key
);
$goalNegativeKeywordSharedSet
=
$this
->
goalNegativeKeywordSharedSets
->
get
(
$key
);
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
$data
=
$this
->
getParams
()[
'NegativeKeywordSharedSets'
][
$key
];
if
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$goalNegativeKeywordSharedSet
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
}
else
{
Log
::
debug
(
"UpdateNegativeKeywordSharedSet, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
GoalNegativeKeywordSharedSet
::
where
(
'id'
,
$goalNegativeKeywordSharedSet
->
getKey
())
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
continue
;
}
}
$
external_id
=
(
string
)
$update_result
[
'Id'
];
$
data
=
$this
->
getParams
()[
'NegativeKeywordSharedSets'
][
$key
];
GoalNegativeKeywordSharedSet
::
where
(
'external_id'
,
$external_id
)
if
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$goalNegativeKeywordSharedSet
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
}
else
{
Log
::
debug
(
"UpdateNegativeKeywordSharedSet, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
GoalNegativeKeywordSharedSet
::
where
(
'id'
,
$goalNegativeKeywordSharedSet
->
getKey
())
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
...
...
app/Service/Requests/Direct/UpdateRetargetinglists.php
View file @
ed83aac
...
@@ -6,8 +6,10 @@ use App\Jobs\ProcessCallLimitedAPI;
...
@@ -6,8 +6,10 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalRetargetinglist
;
use
App\Models\Pivots\GoalRetargetinglist
;
use
App\Models\Variable
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
use
Illuminate\Support\Facades\Log
;
class
UpdateRetargetinglists
extends
DirectRequest
class
UpdateRetargetinglists
extends
DirectRequest
...
@@ -41,47 +43,43 @@ class UpdateRetargetinglists extends DirectRequest
...
@@ -41,47 +43,43 @@ class UpdateRetargetinglists extends DirectRequest
return
;
return
;
}
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'UpdateResults'
])
as
$external_ids
)
{
GoalRetargetinglist
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
foreach
(
$response
[
'result'
][
'UpdateResults'
]
as
$key
=>
$update_result
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
$data
=
$this
->
getParams
()[
'RetargetingLists'
][
$key
];
}
if
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$data
=
$this
->
getParams
()[
'RetargetingLists'
][
$key
];
$goalRetargetinglist
=
GoalRetargetinglist
::
whereExternalId
(
$data
[
'Id'
])
->
first
();
if
(
$goalRetargetinglist
)
{
$goalRetargetinglist
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
$goalRetargetinglist
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
}
if
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$goalRetargetinglist
=
GoalRetargetinglist
::
whereExternalId
(
$data
[
'Id'
])
->
first
();
if
(
$goalRetargetinglist
)
{
$goalRetargetinglist
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$data
,
'errors'
=>
$update_result
[
'Errors'
],
]);
}
}
else
{
Log
::
debug
(
"AddRetargetinglist, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
"AddRetargetinglist, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
Log
::
debug
(
$data
);
GoalRetargetinglist
::
where
(
'external_id'
,
$data
[
'Id'
])
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalRetargetinglist
::
where
(
'external_id'
,
$data
[
'Id'
])
GoalRetargetinglist
::
where
(
'external_id'
,
$external_id
)
->
update
([
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'reserve_update_at'
=>
null
,
]);
]);
...
...
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