update rm deadcode

This commit is contained in:
baodev0
2026-09-27 11:42:40 +07:00
parent 82a71244ca
commit 3af59bd9c5
129 changed files with 5194 additions and 2698 deletions
@@ -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();
}
}