Commit dfcaa0da by Vladislav

#19496 Запрос измененных объявлений

1 parent b6074aac
...@@ -74,6 +74,13 @@ class AdvertisementsAdd extends Command ...@@ -74,6 +74,13 @@ class AdvertisementsAdd extends Command
->whereNotNull('goal_advertisements.goal_v_card_external_id'); ->whereNotNull('goal_advertisements.goal_v_card_external_id');
}); });
}) })
->where(function (Builder $query) {
$query->whereNull('goal_advertisements.goal_sitelink_id')
->orWhere(function (Builder $query) {
$query->whereNotNull('goal_advertisements.goal_sitelink_id')
->whereNotNull('goal_advertisements.goal_sitelink_external_id');
});
})
->whereNull('advertisements.deleted_at') ->whereNull('advertisements.deleted_at')
->whereNull('goal_advertisements.external_id') ->whereNull('goal_advertisements.external_id')
->whereNull('goal_advertisements.reserve_create_at') ->whereNull('goal_advertisements.reserve_create_at')
...@@ -92,7 +99,7 @@ class AdvertisementsAdd extends Command ...@@ -92,7 +99,7 @@ class AdvertisementsAdd extends Command
'advertisements.display_url_path as display_url_path', 'advertisements.display_url_path as display_url_path',
'goal_advertisements.goal_v_card_external_id as goal_v_card_external_id', 'goal_advertisements.goal_v_card_external_id as goal_v_card_external_id',
'advertisements.ad_image_hash as ad_image_hash', 'advertisements.ad_image_hash as ad_image_hash',
'advertisements.site_link_set_id as site_link_set_id', 'advertisements.goal_sitelink_external_id as goal_sitelink_external_id',
DB::raw('JSON_ARRAYAGG(goal_ad_extensions.external_id) as ad_extension_ids'), DB::raw('JSON_ARRAYAGG(goal_ad_extensions.external_id) as ad_extension_ids'),
'advertisements.ad_extensions as ad_extensions', 'advertisements.ad_extensions as ad_extensions',
'advertisements.video_extension as video_extension', 'advertisements.video_extension as video_extension',
......
...@@ -10,6 +10,7 @@ use Carbon\Carbon; ...@@ -10,6 +10,7 @@ use Carbon\Carbon;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough; use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
class AdvertisementsUpdate extends Command class AdvertisementsUpdate extends Command
...@@ -58,6 +59,27 @@ class AdvertisementsUpdate extends Command ...@@ -58,6 +59,27 @@ class AdvertisementsUpdate extends Command
->join('advertisements', 'goal_advertisements.advertisement_id', '=', 'advertisements.id') ->join('advertisements', 'goal_advertisements.advertisement_id', '=', 'advertisements.id')
->leftJoin('goal_advertisement_goal_ad_extensions', 'goal_advertisements.id', '=', 'goal_advertisement_goal_ad_extensions.goal_advertisement_id') ->leftJoin('goal_advertisement_goal_ad_extensions', 'goal_advertisements.id', '=', 'goal_advertisement_goal_ad_extensions.goal_advertisement_id')
->leftJoin('goal_ad_extensions', 'goal_advertisements.id', '=', 'goal_ad_extensions.goal_ad_extension_id') ->leftJoin('goal_ad_extensions', 'goal_advertisements.id', '=', 'goal_ad_extensions.goal_ad_extension_id')
->whereNotExists(function (Builder $query) {
$query->select(DB::raw(1))
->from('goal_advertisement_goal_ad_extensions')
->join('goal_ad_extensions', 'goal_advertisement_goal_ad_extensions.goal_ad_extension_id', '=', 'goal_ad_extensions.id')
->whereNull('goal_ad_extensions.external_id')
->whereColumn('goal_advertisements.id', 'goal_advertisement_goal_ad_extensions.goal_advertisement_id');
})
->where(function (Builder $query) {
$query->whereNull('goal_advertisements.goal_v_card_id')
->orWhere(function (Builder $query) {
$query->whereNotNull('goal_advertisements.goal_v_card_id')
->whereNotNull('goal_advertisements.goal_v_card_external_id');
});
})
->where(function (Builder $query) {
$query->whereNull('goal_advertisements.goal_sitelink_id')
->orWhere(function (Builder $query) {
$query->whereNotNull('goal_advertisements.goal_sitelink_id')
->whereNotNull('goal_advertisements.goal_sitelink_external_id');
});
})
->whereNull('advertisements.deleted_at') ->whereNull('advertisements.deleted_at')
->whereNull('goal_advertisements.reserve_update_at') ->whereNull('goal_advertisements.reserve_update_at')
->whereNotNull('goal_advertisements.updated_need') ->whereNotNull('goal_advertisements.updated_need')
...@@ -75,7 +97,7 @@ class AdvertisementsUpdate extends Command ...@@ -75,7 +97,7 @@ class AdvertisementsUpdate extends Command
'advertisements.display_url_path as display_url_path', 'advertisements.display_url_path as display_url_path',
'goal_advertisements.goal_v_card_external_id as goal_v_card_external_id', 'goal_advertisements.goal_v_card_external_id as goal_v_card_external_id',
'advertisements.ad_image_hash as ad_image_hash', 'advertisements.ad_image_hash as ad_image_hash',
'advertisements.site_link_set_id as site_link_set_id', 'advertisements.goal_sitelink_external_id as goal_sitelink_external_id',
DB::raw("JSON_OBJECTAGG('AdExtensionId', goal_ad_extensions.external_id, 'Operation', 'SET') as ad_extensions"), DB::raw("JSON_OBJECTAGG('AdExtensionId', goal_ad_extensions.external_id, 'Operation', 'SET') as ad_extensions"),
'advertisements.video_extension as video_extension', 'advertisements.video_extension as video_extension',
'advertisements.price_extension as price_extension', 'advertisements.price_extension as price_extension',
......
...@@ -177,14 +177,17 @@ class DictionaryCampaignsSyncByCampaign extends Command ...@@ -177,14 +177,17 @@ class DictionaryCampaignsSyncByCampaign extends Command
//грузим объявления которых по какой то причне нет в целевых. //грузим объявления которых по какой то причне нет в целевых.
DB::insert(" DB::insert("
INSERT INTO goal_advertisements(dictionary_campaign_external_id, goal_ad_group_external_id, dictionary_campaign_id, INSERT INTO goal_advertisements(dictionary_campaign_external_id, goal_ad_group_external_id, dictionary_campaign_id,
goal_ad_group_id, advertisement_id, goal_v_card_id, goal_v_card_external_id, created_at, updated_at) goal_ad_group_id, advertisement_id, goal_v_card_id, goal_v_card_external_id, goal_sitelink_id, goal_sitelink_external_id, created_at, updated_at)
SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, ad.id, gvc.id, gvc.external_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP SELECT gag.dictionary_campaign_external_id, gag.external_id, gag.dictionary_campaign_id, gag.id, ad.id, gvc.id, gvc.external_id, gs.id, gs.external_id, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP
FROM advertisements ad FROM advertisements ad
INNER JOIN ad_groups ag on ad.ad_group_id = ag.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 INNER JOIN goal_ad_groups gag on ag.id = gag.ad_group_id
INNER JOIN dictionaries d on gag.dictionary_campaign_id = d.id
LEFT JOIN goal_advertisements gad on ad.id = gad.advertisement_id AND gad.goal_ad_group_id=gag.id LEFT JOIN goal_advertisements gad on ad.id = gad.advertisement_id AND gad.goal_ad_group_id=gag.id
LEFT JOIN v_cards vc on ad.v_card_external_id = vc.external_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 gag.dictionary_campaign_id = gvc.dictionary_campaign_id LEFT JOIN goal_v_cards gvc on vc.id = gvc.v_card_id and gag.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
WHERE gad.advertisement_id is null and ad.campaign_id is not null WHERE gad.advertisement_id is null and ad.campaign_id is not null
"); ");
......
...@@ -85,7 +85,7 @@ class Advertisement extends Model ...@@ -85,7 +85,7 @@ class Advertisement extends Model
'display_url_path', 'display_url_path',
'v_card_external_id', 'v_card_external_id',
'ad_image_hash', 'ad_image_hash',
'site_link_set_id', 'sitelink_external_id',
'display_url_path_moderation', 'display_url_path_moderation',
'v_card_moderation', 'v_card_moderation',
'site_links_moderation', 'site_links_moderation',
...@@ -130,7 +130,7 @@ class Advertisement extends Model ...@@ -130,7 +130,7 @@ class Advertisement extends Model
'display_url_path', 'display_url_path',
'v_card_external_id', 'v_card_external_id',
'ad_image_hash', 'ad_image_hash',
'site_link_set_id', 'sitelink_external_id',
'ad_extensions', 'ad_extensions',
'video_extension', 'video_extension',
'price_extension', 'price_extension',
......
...@@ -154,8 +154,8 @@ class AddAds extends DirectRequest ...@@ -154,8 +154,8 @@ class AddAds extends DirectRequest
$data['TextAd']['AdImageHash'] = $goalAdvertisement->ad_image_hash; $data['TextAd']['AdImageHash'] = $goalAdvertisement->ad_image_hash;
} }
if ($goalAdvertisement->site_link_set_id) { if ($goalAdvertisement->goal_sitelink_external_id) {
$data['TextAd']['SitelinkSetId'] = $goalAdvertisement->site_link_set_id; $data['TextAd']['SitelinkSetId'] = $goalAdvertisement->goal_sitelink_external_id;
} }
if ($ad_extension_ids = array_filter(@json_decode($goalAdvertisement->ad_extension_ids, true))) { if ($ad_extension_ids = array_filter(@json_decode($goalAdvertisement->ad_extension_ids, true))) {
......
...@@ -124,7 +124,7 @@ class GetAds extends DirectRequest ...@@ -124,7 +124,7 @@ class GetAds extends DirectRequest
'display_url_path' => $ad['TextAd']['DisplayUrlPath'], 'display_url_path' => $ad['TextAd']['DisplayUrlPath'],
'v_card_external_id' => $ad['TextAd']['VCardId'], 'v_card_external_id' => $ad['TextAd']['VCardId'],
'ad_image_hash' => $ad['TextAd']['AdImageHash'], 'ad_image_hash' => $ad['TextAd']['AdImageHash'],
'site_link_set_id' => $ad['TextAd']['SitelinkSetId'], 'sitelink_external_id' => $ad['TextAd']['SitelinkSetId'],
'display_url_path_moderation' => $ad['TextAd']['DisplayUrlPathModeration'], 'display_url_path_moderation' => $ad['TextAd']['DisplayUrlPathModeration'],
'v_card_moderation' => $ad['TextAd']['VCardModeration'], 'v_card_moderation' => $ad['TextAd']['VCardModeration'],
'site_links_moderation' => $ad['TextAd']['SitelinksModeration'], 'site_links_moderation' => $ad['TextAd']['SitelinksModeration'],
......
...@@ -138,8 +138,8 @@ class UpdateAds extends DirectRequest ...@@ -138,8 +138,8 @@ class UpdateAds extends DirectRequest
$data['TextAd']['AdImageHash'] = $goalAdvertisement->ad_image_hash; $data['TextAd']['AdImageHash'] = $goalAdvertisement->ad_image_hash;
} }
if ($goalAdvertisement->site_link_set_id) { if ($goalAdvertisement->goal_sitelink_external_id) {
$data['TextAd']['SitelinkSetId'] = $goalAdvertisement->site_link_set_id; $data['TextAd']['SitelinkSetId'] = $goalAdvertisement->goal_sitelink_external_id;
} }
if ($ad_extensions = array_filter(@json_decode($goalAdvertisement->ad_extensions, true))) { if ($ad_extensions = array_filter(@json_decode($goalAdvertisement->ad_extensions, true))) {
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ChangeAdvertisementsColumnSiteLinkSetId extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('advertisements', function (Blueprint $table) {
$table->renameColumn('site_link_set_id', 'sitelink_external_id');
});
Schema::table('goal_advertisements', function (Blueprint $table) {
$table->bigInteger('goal_sitelink_id')->nullable();
$table->bigInteger('goal_sitelink_external_id')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!