update rm deadcode
This commit is contained in:
@@ -16,17 +16,33 @@ class DnsDomainWriter
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::table('dns_manager_domain')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'domain_name' => $data->domainName,
|
||||
'dns_manager_server_id' => $data->dnsManagerServerId,
|
||||
'is_created' => $data->isCreated,
|
||||
'plesk_id' => $data->pleskId,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
]
|
||||
);
|
||||
$attributes = [
|
||||
'legacy_id' => $data->legacyId,
|
||||
'domain_name' => $data->domainName,
|
||||
'dns_manager_server_id' => $data->dnsManagerServerId,
|
||||
'is_created' => $data->isCreated,
|
||||
'plesk_id' => $data->pleskId,
|
||||
'created_at' => $data->createdAt,
|
||||
'updated_at' => $data->updatedAt,
|
||||
];
|
||||
|
||||
$existingId = DB::table('dns_manager_domain')->where('legacy_id', $data->legacyId)->value('id');
|
||||
|
||||
// A WHMCS-created placeholder (DnsDomainLinker) has legacy_id NULL and the same
|
||||
// domain_name — adopt it instead of inserting a duplicate row that would strand
|
||||
// dns_domain_user pointing at the empty placeholder while NS records attach here.
|
||||
if (! $existingId && $data->domainName !== null) {
|
||||
$existingId = DB::table('dns_manager_domain')
|
||||
->whereNull('legacy_id')
|
||||
->whereRaw('LOWER(domain_name) = ?', [mb_strtolower($data->domainName)])
|
||||
->value('id');
|
||||
}
|
||||
|
||||
if ($existingId) {
|
||||
DB::table('dns_manager_domain')->where('id', $existingId)->update($attributes);
|
||||
} else {
|
||||
DB::table('dns_manager_domain')->insert($attributes);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class ProductCategoryData
|
||||
{
|
||||
public function __construct(
|
||||
public readonly int $legacyId,
|
||||
public readonly ?int $adoptId,
|
||||
public readonly string $name,
|
||||
public readonly string $slug,
|
||||
public readonly ?string $type,
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,17 @@ class ProductCategoryTransformer
|
||||
$row = (array) $row;
|
||||
$legacyId = (int) $row['id'];
|
||||
$name = $row['name'] ?: "WHMCS Group {$legacyId}";
|
||||
$candidate = $row['slug'] ?: $name;
|
||||
|
||||
$adoptId = $this->slugs->adoptableId('product_categories', 'slug', $candidate);
|
||||
|
||||
return new ProductCategoryData(
|
||||
legacyId: $legacyId,
|
||||
adoptId: $adoptId,
|
||||
name: $name,
|
||||
slug: $this->slugs->unique('product_categories', 'slug', $row['slug'] ?: $name, $legacyId),
|
||||
slug: $adoptId
|
||||
? (Str::slug($candidate) ?: 'item')
|
||||
: $this->slugs->unique('product_categories', 'slug', $candidate, $legacyId),
|
||||
type: $this->guessType($name),
|
||||
isActive: ! $row['hidden'],
|
||||
sortOrder: (int) $row['order'],
|
||||
|
||||
@@ -10,8 +10,9 @@ class ProductCategoryWriter
|
||||
public function write(ProductCategoryData $data): void
|
||||
{
|
||||
DB::table('product_categories')->updateOrInsert(
|
||||
['legacy_id' => $data->legacyId],
|
||||
$data->adoptId ? ['id' => $data->adoptId] : ['legacy_id' => $data->legacyId],
|
||||
[
|
||||
'legacy_id' => $data->legacyId,
|
||||
'name' => $data->name,
|
||||
'slug' => $data->slug,
|
||||
'type' => $data->type,
|
||||
|
||||
Reference in New Issue
Block a user