mirror of
https://github.com/Cybrarist/Discount-Bandit.git
synced 2026-11-24 19:49:54 +01:00
51 lines
1.1 KiB
PHP
51 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\Link;
|
|
use App\Models\LinkHistory;
|
|
use App\Models\NotificationSetting;
|
|
use Illuminate\Console\Command;
|
|
|
|
class DeleteLinksWithoutProductsCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'discount:delete-orphan-links';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = "Delete orphan links that are not linked to any products";
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
|
|
$orphan_links = Link::withoutGlobalScopes()
|
|
->whereDoesntHave(
|
|
'products',
|
|
function ($query) {
|
|
$query->withoutGlobalScopes();
|
|
}
|
|
)->pluck('id');
|
|
|
|
|
|
LinkHistory::whereIn('link_id', $orphan_links)->delete();
|
|
|
|
NotificationSetting::withoutGlobalScopes()
|
|
->whereIn('link_id', $orphan_links)
|
|
->delete();
|
|
|
|
Link::withoutGlobalScopes()
|
|
->whereIn('id', $orphan_links)->delete();
|
|
}
|
|
}
|