update rm deadcode
This commit is contained in:
@@ -5,7 +5,6 @@ namespace App\Integrations\Whmcs\Support;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/** Slugifies a candidate and appends -N until it's unique in the given column, excluding the row's own legacy_id. */
|
||||
class SlugUniquifier
|
||||
{
|
||||
public function unique(string $table, string $column, string $candidate, int $legacyId): string
|
||||
@@ -14,10 +13,27 @@ class SlugUniquifier
|
||||
$slug = $base;
|
||||
$suffix = 1;
|
||||
|
||||
while (DB::table($table)->where($column, $slug)->where('legacy_id', '!=', $legacyId)->exists()) {
|
||||
while ($this->ownedByAnotherRow($table, $column, $slug, $legacyId)) {
|
||||
$slug = "{$base}-" . ++$suffix;
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
public function adoptableId(string $table, string $column, string $candidate): ?int
|
||||
{
|
||||
$slug = Str::slug($candidate) ?: 'item';
|
||||
|
||||
return DB::table($table)->where($column, $slug)->whereNull('legacy_id')->value('id');
|
||||
}
|
||||
|
||||
private function ownedByAnotherRow(string $table, string $column, string $slug, int $legacyId): bool
|
||||
{
|
||||
return DB::table($table)
|
||||
->where($column, $slug)
|
||||
->where(function ($query) use ($legacyId) {
|
||||
$query->whereNull('legacy_id')->orWhere('legacy_id', '!=', $legacyId);
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user