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
->
groupBy
([
'goal_bid_modifiers.dictionary_campaign_external_id'
,
'goal_bid_modifiers.goal_ad_group_external_id'
,
'dictionaries.region_id'
,
'dictionaries.token_id'
,
'bid_modifiers.mobile_adjustment'
,
'bid_modifiers.desktop_adjustment'
,
'bid_modifiers.video_adjustment'
,
'dictionaries.region_id'
,
'dictionaries.token_id'
,
DB
::
raw
(
'bid_modifiers.demographics_adjustment IS NOT NULL'
)
,
DB
::
raw
(
'bid_modifiers.retargeting_adjustment IS NOT NULL'
)
,
])
->
select
([
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;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
DeleteAdGroups
extends
DirectRequest
...
...
@@ -37,43 +39,43 @@ class DeleteAdGroups extends DirectRequest
return
;
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
!
isset
(
$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
);
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
GoalAdGroup
::
whereIn
(
'external_id'
,
$external_ids
)
->
delete
();
}
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
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;
use
App\Models\Advertisement
;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -38,75 +39,73 @@ class DeleteAds extends DirectRequest
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
)
{
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
}
$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
(
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
&&
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
else
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
if
(
$this
->
getToken
()
->
isMain
())
{
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
else
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
}
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
;
}
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
(
$delete_result
);
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
())
{
Advertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
Advertisement
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
->
delete
();
GoalAdvertisement
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
}
...
...
app/Service/Requests/Direct/DeleteAudienceTarget.php
View file @
ed83aac
...
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\AudienceTarget
;
use
App\Models\Pivots\GoalAudienceTarget
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -38,59 +39,58 @@ class DeleteAudienceTarget extends DirectRequest
return
;
}
foreach
(
$response
[
'result'
][
'DeleteResults'
]
as
$key
=>
$delete_result
)
{
if
(
!
isset
(
$delete_result
[
'Id'
]))
{
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'DeleteResults'
])
as
$external_ids
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
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
(
$this
->
getToken
()
->
isMain
())
{
$model
=
AudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
$model
=
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
if
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
}
if
(
$model
)
{
$model
->
errors
()
->
create
([
'token_id'
=>
$this
->
getToken
()
->
getKey
(),
'service'
=>
$this
->
getService
(),
'method'
=>
$this
->
getMethod
(),
'params'
=>
$external_id
,
'errors'
=>
$delete_result
[
'Errors'
],
]);
}
$external_id
=
$this
->
getParams
()[
'SelectionCriteria'
][
'Ids'
][
$key
];
}
else
{
Log
::
debug
(
"DeleteAudienceTargets, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$delete_result
);
Log
::
debug
(
$external_id
);
}
if
(
isset
(
$delete_result
[
'Errors'
])
&&
count
(
$delete_result
[
'Errors'
]))
{
if
(
$this
->
getToken
()
->
isMain
())
{
AudienceTarget
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
$model
=
AudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
else
{
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
$model
=
GoalAudienceTarget
::
whereExternalId
(
$external_id
)
->
first
();
}
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
())
{
AudienceTarget
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
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;
use
App\Models\Pivots\GoalVCard
;
use
App\Models\VCard
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -38,72 +39,70 @@ class DeleteVCards extends DirectRequest
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
)
{
$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
(
$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
(
isset
(
$delete_result
[
'Id'
]))
{
continue
;
}
if
(
isset
(
$delete_result
[
'Errors'
][
0
][
'Code'
])
&&
$delete_result
[
'Errors'
][
0
][
'Code'
]
==
8800
)
{
if
(
$this
->
getToken
()
->
isMain
())
{
VCard
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
->
delete
();
}
else
{
GoalVCard
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_delete_at'
=>
null
,
]);
->
delete
();
}
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
())
{
VCard
::
whereExternalId
(
$external_id
)
->
delete
();
->
update
([
'reserve_delete_at'
=>
null
,
]);
}
else
{
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;
use
App\Jobs\ProcessCallLimitedAPI
;
use
App\Models\Pivots\GoalBidModifier
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
SetBidModifiers
extends
DirectRequest
...
...
@@ -37,50 +39,53 @@ class SetBidModifiers extends DirectRequest
return
;
}
foreach
(
$response
[
'result'
][
'SetResults'
]
as
$key
=>
$set_result
)
{
if
(
!
isset
(
$set_result
[
'Id'
]))
{
$data
=
$this
->
getParams
()[
'BidModifiers'
][
$key
];
$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
);
}
foreach
(
DirectResponseHelper
::
getExternalIdsChunkByResult
(
$response
[
'result'
][
'SetResults'
])
as
$external_ids
)
{
GoalBidModifier
::
whereIn
(
'external_id'
,
$external_ids
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
'updated_at'
=>
Carbon
::
now
(),
]);
}
GoalBidModifier
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_update_at'
=>
null
,
]);
foreach
(
$response
[
'result'
][
'SetResults'
]
as
$key
=>
$set_result
)
{
if
(
isset
(
$set_result
[
'Id'
]))
{
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
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
}
}
...
...
app/Service/Requests/Direct/UpdateAdGroups.php
View file @
ed83aac
...
...
@@ -6,6 +6,7 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
...
...
@@ -40,44 +41,44 @@ class UpdateAdGroups extends DirectRequest
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
)
{
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'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
forceDelete
();
}
}
else
{
Log
::
debug
(
"UpdateAdGroup, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
$model
->
forceDelete
();
}
GoalAdGroup
::
withTrashed
()
->
whereExternalId
(
$this
->
getParams
()[
'AdGroups'
][
$key
][
'Id'
])
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
else
{
Log
::
debug
(
"UpdateAdGroup, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdGroup
::
where
(
'external_id'
,
$external_id
)
GoalAdGroup
::
withTrashed
()
->
whereExternalId
(
$this
->
getParams
()[
'AdGroups'
][
$key
][
'Id'
])
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
...
...
app/Service/Requests/Direct/UpdateAds.php
View file @
ed83aac
...
...
@@ -7,6 +7,7 @@ use App\Models\Advertisement;
use
App\Models\Pivots\GoalAdvertisement
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
...
...
@@ -41,57 +42,57 @@ class UpdateAds extends DirectRequest
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
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
$data
=
$this
->
getParams
()[
'Ads'
][
$key
];
$external_id
=
$data
[
'Id'
];
if
(
isset
(
$update_result
[
'Errors'
][
0
][
'Details'
])
&&
$update_result
[
'Errors'
][
0
][
'Details'
]
===
'You cannot update an archived ad'
)
{
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
);
}
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
}
$data
=
$this
->
getParams
()[
'Ads'
][
$key
];
$external_id
=
$data
[
'Id'
];
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
([
'reserve_update_at'
=>
null
,
'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
);
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
GoalAdvertisement
::
where
(
'external_id'
,
$external_id
)
GoalAdvertisement
::
withTrashed
()
->
whereExternalId
(
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
...
...
app/Service/Requests/Direct/UpdateCampaigns.php
View file @
ed83aac
...
...
@@ -8,6 +8,7 @@ use App\Models\Pivots\DictionaryCampaign;
use
App\Models\Pivots\GoalAdGroup
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
...
...
@@ -42,48 +43,49 @@ class UpdateCampaigns extends DirectRequest
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
)
{
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'
)
{
DictionaryCampaign
::
whereExternalId
(
$external_id
)
->
delete
();
}
elseif
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
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
();
}
elseif
(
isset
(
$update_result
[
'Message'
])
&&
$update_result
[
'Message'
]
===
'Object not found'
)
{
$model
=
GoalAdGroup
::
whereExternalId
(
$external_id
)
->
first
();
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
if
(
$model
)
{
$model
->
goalKeywords
()
->
delete
();
$model
->
goalAdvertisements
()
->
delete
();
$model
->
goalBidModifiers
()
->
delete
();
$model
->
goalAudienceTargets
()
->
delete
();
$model
->
delete
();
}
}
else
{
Log
::
debug
(
"UpdateCampaigns, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
$model
->
delete
();
}
DictionaryCampaign
::
withTrashed
()
->
whereExternalId
(
$external_id
)
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
else
{
Log
::
debug
(
"UpdateCampaigns, empty Id, token_id
{
$this
->
getToken
()
->
getKey
()
}
"
);
Log
::
debug
(
$update_result
);
Log
::
debug
(
$data
);
}
$external_id
=
(
string
)
$update_result
[
'Id'
];
DictionaryCampaign
::
where
(
'external_id'
,
$external_id
)
DictionaryCampaign
::
withTrashed
()
->
whereExternalId
(
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
}
$this
->
getToken
()
->
update
([
...
...
app/Service/Requests/Direct/UpdateKeywords.php
View file @
ed83aac
...
...
@@ -7,8 +7,10 @@ use App\Models\Keyword;
use
App\Models\Pivots\GoalKeyword
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
UpdateKeywords
extends
DirectRequest
...
...
@@ -40,49 +42,49 @@ class UpdateKeywords extends DirectRequest
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
)
{
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
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
GoalKeyword
::
whereExternalId
(
$external_id
)
->
delete
();
if
(
$goalKeyword
)
{
$goalKeyword
->
errors
()
->
create
([
'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
);
}
}
elseif
(
isset
(
$update_result
[
'Errors'
])
&&
count
(
$update_result
[
'Errors'
]))
{
$goalKeyword
=
GoalKeyword
::
whereExternalId
(
$external_id
)
->
first
();
GoalKeyword
::
whereExternalId
(
$external_id
)
->
update
([
'reserve_update_at'
=>
null
,
if
(
$goalKeyword
)
{
$goalKeyword
->
errors
()
->
create
([
'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
::
where
(
'external_id'
,
$external_id
)
GoalKeyword
::
whereExternalId
(
$external_id
)
->
update
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
...
...
app/Service/Requests/Direct/UpdateNegativeKeywordSharedSets.php
View file @
ed83aac
...
...
@@ -7,8 +7,10 @@ use App\Models\NegativeKeywordSharedSet;
use
App\Models\Pivots\GoalNegativeKeywordSharedSet
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Collection
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -53,41 +55,41 @@ class UpdateNegativeKeywordSharedSets extends DirectRequest
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
)
{
$goalNegativeKeywordSharedSet
=
$this
->
goalNegativeKeywordSharedSets
->
get
(
$key
);
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
,
]);
if
(
isset
(
$update_result
[
'Id'
]))
{
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
([
'updated_need'
=>
null
,
'reserve_update_at'
=>
null
,
]);
...
...
app/Service/Requests/Direct/UpdateRetargetinglists.php
View file @
ed83aac
...
...
@@ -6,8 +6,10 @@ use App\Jobs\ProcessCallLimitedAPI;
use
App\Models\Pivots\GoalRetargetinglist
;
use
App\Models\Variable
;
use
App\Service\Contract\APIRequest
;
use
App\Service\DirectResponseHelper
;
use
App\Service\Requests\DirectRequest
;
use
App\Service\StrReplaceByVariables
;
use
Carbon\Carbon
;
use
Illuminate\Support\Facades\Log
;
class
UpdateRetargetinglists
extends
DirectRequest
...
...
@@ -41,47 +43,43 @@ class UpdateRetargetinglists extends DirectRequest
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
)
{
if
(
!
isset
(
$update_result
[
'Id'
]))
{
$data
=
$this
->
getParams
()[
'RetargetingLists'
][
$key
];
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'
],
]);
$goalRetargetinglist
->
update
([
'reserve_update_at'
=>
null
,
]);
continue
;
}
}
if
(
isset
(
$update_result
[
'Id'
]))
{
continue
;
}
$data
=
$this
->
getParams
()[
'RetargetingLists'
][
$key
];
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
(
$update_result
);
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'
,
$external_id
)
GoalRetargetinglist
::
where
(
'external_id'
,
$data
[
'Id'
])
->
update
([
'updated_need'
=>
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