Commit d48d8445 by Vladislav

Исправлена связь моделей с токеном

1 parent 09ba06bc
...@@ -26,6 +26,7 @@ class AdExtension extends Model ...@@ -26,6 +26,7 @@ class AdExtension extends Model
protected $fillable = [ protected $fillable = [
'token_id',
'external_id', 'external_id',
'callout_text', 'callout_text',
'associated', 'associated',
......
...@@ -32,6 +32,7 @@ class AdImage extends Model ...@@ -32,6 +32,7 @@ class AdImage extends Model
protected $fillable = [ protected $fillable = [
'token_id',
'hash', 'hash',
'name', 'name',
'type', 'type',
......
...@@ -17,6 +17,7 @@ class Retargetinglist extends Model ...@@ -17,6 +17,7 @@ class Retargetinglist extends Model
protected $table = 'retargetinglists'; protected $table = 'retargetinglists';
protected $fillable = [ protected $fillable = [
'token_id',
'external_id', 'external_id',
'type', 'type',
'name', 'name',
......
...@@ -14,6 +14,7 @@ class Sitelink extends Model ...@@ -14,6 +14,7 @@ class Sitelink extends Model
protected $table = 'sitelinks'; protected $table = 'sitelinks';
protected $fillable = [ protected $fillable = [
'token_id',
'external_id', 'external_id',
'links', 'links',
]; ];
......
...@@ -50,6 +50,7 @@ class GetAdExtensions extends DirectRequest ...@@ -50,6 +50,7 @@ class GetAdExtensions extends DirectRequest
if ($this->getToken()->isMain()) { if ($this->getToken()->isMain()) {
$data = [ $data = [
'token_id' => $this->getToken()->getKey(),
'external_id' => $external_id, 'external_id' => $external_id,
'callout_text' => $ad_extension['Callout']['CalloutText'], 'callout_text' => $ad_extension['Callout']['CalloutText'],
'associated' => $ad_extension['Associated'] === 'YES', 'associated' => $ad_extension['Associated'] === 'YES',
...@@ -58,7 +59,8 @@ class GetAdExtensions extends DirectRequest ...@@ -58,7 +59,8 @@ class GetAdExtensions extends DirectRequest
]; ];
$adExtension = AdExtension::updateOrCreate([ $adExtension = AdExtension::updateOrCreate([
'external_id' => $external_id 'token_id' => $this->getToken()->getKey(),
'external_id' => $external_id,
], $data); ], $data);
if ($adExtension->wasChanged($adExtension::getPropertiesWatch()->toArray())) { if ($adExtension->wasChanged($adExtension::getPropertiesWatch()->toArray())) {
......
...@@ -57,6 +57,7 @@ class GetAdImages extends DirectRequest ...@@ -57,6 +57,7 @@ class GetAdImages extends DirectRequest
} }
$data = [ $data = [
'token_id' => $this->getToken()->getKey(),
'hash' => $hash, 'hash' => $hash,
'name' => $ad_image['Name'], 'name' => $ad_image['Name'],
'type' => $ad_image['Type'], 'type' => $ad_image['Type'],
...@@ -66,7 +67,8 @@ class GetAdImages extends DirectRequest ...@@ -66,7 +67,8 @@ class GetAdImages extends DirectRequest
]; ];
$adImage = AdImage::updateOrCreate([ $adImage = AdImage::updateOrCreate([
'hash' => $hash 'token_id' => $this->getToken()->getKey(),
'hash' => $hash,
], $data); ], $data);
} else { } else {
......
...@@ -50,6 +50,7 @@ class GetRetargetinglists extends DirectRequest ...@@ -50,6 +50,7 @@ class GetRetargetinglists extends DirectRequest
if ($this->getToken()->isMain()) { if ($this->getToken()->isMain()) {
$data = [ $data = [
'token_id' => $this->getToken()->getKey(),
'external_id' => $external_id, 'external_id' => $external_id,
'type' => $retargeting_list['Type'], 'type' => $retargeting_list['Type'],
'name' => $retargeting_list['Name'], 'name' => $retargeting_list['Name'],
...@@ -58,7 +59,8 @@ class GetRetargetinglists extends DirectRequest ...@@ -58,7 +59,8 @@ class GetRetargetinglists extends DirectRequest
]; ];
$retargetinglist = Retargetinglist::updateOrCreate([ $retargetinglist = Retargetinglist::updateOrCreate([
'external_id' => $external_id 'external_id' => $external_id,
'token_id' => $this->getToken()->getKey(),
], $data); ], $data);
if (!$retargetinglist->wasRecentlyCreated && $retargetinglist->wasChanged($retargetinglist::getPropertiesWatch()->toArray())) { if (!$retargetinglist->wasRecentlyCreated && $retargetinglist->wasChanged($retargetinglist::getPropertiesWatch()->toArray())) {
......
...@@ -50,12 +50,14 @@ class GetSitelinks extends DirectRequest ...@@ -50,12 +50,14 @@ class GetSitelinks extends DirectRequest
if ($this->getToken()->isMain()) { if ($this->getToken()->isMain()) {
$data = [ $data = [
'token_id' => $this->getToken()->getKey(),
'external_id' => $external_id, 'external_id' => $external_id,
'links' => $sitelinks_sets['Sitelinks'], 'links' => $sitelinks_sets['Sitelinks'],
]; ];
$sitelink = Sitelink::updateOrCreate([ $sitelink = Sitelink::updateOrCreate([
'external_id' => $external_id 'external_id' => $external_id,
'token_id' => $this->getToken()->getKey(),
], $data); ], $data);
if (!$sitelink->wasRecentlyCreated && $sitelink->wasChanged($sitelink::getPropertiesWatch()->toArray())) { if (!$sitelink->wasRecentlyCreated && $sitelink->wasChanged($sitelink::getPropertiesWatch()->toArray())) {
......
...@@ -17,6 +17,7 @@ class CreateAdExtensionsTable extends Migration ...@@ -17,6 +17,7 @@ class CreateAdExtensionsTable extends Migration
Schema::create('ad_extensions', function (Blueprint $table) { Schema::create('ad_extensions', function (Blueprint $table) {
$table->id(); $table->id();
$table->bigInteger('token_id')->nullable()->unsigned();
$table->bigInteger('external_id'); $table->bigInteger('external_id');
$table->string('callout_text'); $table->string('callout_text');
$table->boolean('associated'); $table->boolean('associated');
...@@ -38,6 +39,9 @@ class CreateAdExtensionsTable extends Migration ...@@ -38,6 +39,9 @@ class CreateAdExtensionsTable extends Migration
]); ]);
$table->string('status_clarification'); $table->string('status_clarification');
$table->foreign('token_id')->references('id')->on('tokens')
->cascadeOnDelete();
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -16,9 +16,13 @@ class CreateSitelinksTable extends Migration ...@@ -16,9 +16,13 @@ class CreateSitelinksTable extends Migration
Schema::create('sitelinks', function (Blueprint $table) { Schema::create('sitelinks', function (Blueprint $table) {
$table->id(); $table->id();
$table->bigInteger('token_id')->nullable()->unsigned();
$table->bigInteger('external_id'); $table->bigInteger('external_id');
$table->json('links')->nullable(); $table->json('links')->nullable();
$table->foreign('token_id')->references('id')->on('tokens')
->cascadeOnDelete();
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -17,6 +17,7 @@ class CreateRetargetinglistsTable extends Migration ...@@ -17,6 +17,7 @@ class CreateRetargetinglistsTable extends Migration
Schema::create('retargetinglists', function (Blueprint $table) { Schema::create('retargetinglists', function (Blueprint $table) {
$table->id(); $table->id();
$table->bigInteger('token_id')->nullable()->unsigned();
$table->enum('type', [ $table->enum('type', [
Retargetinglist::TYPE_RETARGETING, Retargetinglist::TYPE_RETARGETING,
Retargetinglist::TYPE_AUDIENCE, Retargetinglist::TYPE_AUDIENCE,
...@@ -25,6 +26,9 @@ class CreateRetargetinglistsTable extends Migration ...@@ -25,6 +26,9 @@ class CreateRetargetinglistsTable extends Migration
$table->string('description')->nullable(); $table->string('description')->nullable();
$table->json('rules')->nullable(); $table->json('rules')->nullable();
$table->foreign('token_id')->references('id')->on('tokens')
->cascadeOnDelete();
$table->softDeletes(); $table->softDeletes();
$table->timestamps(); $table->timestamps();
}); });
......
...@@ -17,6 +17,7 @@ class CreateAdImagesTable extends Migration ...@@ -17,6 +17,7 @@ class CreateAdImagesTable extends Migration
Schema::create('ad_images', function (Blueprint $table) { Schema::create('ad_images', function (Blueprint $table) {
$table->id(); $table->id();
$table->bigInteger('token_id')->nullable()->unsigned();
$table->string('hash'); $table->string('hash');
$table->string('name'); $table->string('name');
$table->enum('type', [ $table->enum('type', [
...@@ -43,6 +44,9 @@ class CreateAdImagesTable extends Migration ...@@ -43,6 +44,9 @@ class CreateAdImagesTable extends Migration
$table->text('original_url'); $table->text('original_url');
$table->text('preview_url'); $table->text('preview_url');
$table->foreign('token_id')->references('id')->on('tokens')
->cascadeOnDelete();
$table->timestamps(); $table->timestamps();
}); });
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!