Update DomainController.php

Fixing old Tags system code
This commit is contained in:
Hosteroid
2025-10-25 12:40:47 +03:00
parent 06596b8044
commit d76e9d9473

View File

@@ -222,7 +222,6 @@ class DomainController extends Controller
$id = $this->domainModel->create([ $id = $this->domainModel->create([
'domain_name' => $domainName, 'domain_name' => $domainName,
'notification_group_id' => $groupId, 'notification_group_id' => $groupId,
'tags' => $tags,
'registrar' => $whoisData['registrar'], 'registrar' => $whoisData['registrar'],
'registrar_url' => $whoisData['registrar_url'] ?? null, 'registrar_url' => $whoisData['registrar_url'] ?? null,
'expiration_date' => $whoisData['expiration_date'], 'expiration_date' => $whoisData['expiration_date'],
@@ -235,6 +234,12 @@ class DomainController extends Controller
'user_id' => $userId 'user_id' => $userId
]); ]);
// Handle tags using the new tag system
if (!empty($tags)) {
$tagModel = new \App\Models\Tag();
$tagModel->updateDomainTags($id, $tags, $userId);
}
// Log domain creation // Log domain creation
$logger = new \App\Services\Logger(); $logger = new \App\Services\Logger();
$logger->info('Domain created', [ $logger->info('Domain created', [
@@ -675,10 +680,9 @@ class DomainController extends Controller
$availableCount++; $availableCount++;
} }
$this->domainModel->create([ $domainId = $this->domainModel->create([
'domain_name' => $domainName, 'domain_name' => $domainName,
'notification_group_id' => $groupId, 'notification_group_id' => $groupId,
'tags' => $tags,
'registrar' => $whoisData['registrar'], 'registrar' => $whoisData['registrar'],
'registrar_url' => $whoisData['registrar_url'] ?? null, 'registrar_url' => $whoisData['registrar_url'] ?? null,
'expiration_date' => $whoisData['expiration_date'], 'expiration_date' => $whoisData['expiration_date'],
@@ -691,6 +695,12 @@ class DomainController extends Controller
'user_id' => \Core\Auth::id() 'user_id' => \Core\Auth::id()
]); ]);
// Handle tags using the new tag system
if (!empty($tags) && $domainId) {
$tagModel = new \App\Models\Tag();
$tagModel->updateDomainTags($domainId, $tags, $userId);
}
$added++; $added++;
} }
@@ -1021,6 +1031,28 @@ class DomainController extends Controller
$settingModel = new \App\Models\Setting(); $settingModel = new \App\Models\Setting();
$isolationMode = $settingModel->getValue('user_isolation_mode', 'shared'); $isolationMode = $settingModel->getValue('user_isolation_mode', 'shared');
// Initialize Tag model
$tagModel = new \App\Models\Tag();
// Find or create the tag
$tag = $tagModel->findByName($tagToAdd, $userId);
if (!$tag) {
// Create new tag
$tagId = $tagModel->create([
'name' => $tagToAdd,
'color' => 'bg-gray-100 text-gray-700 border-gray-300',
'description' => '',
'user_id' => $userId
]);
if (!$tagId) {
$_SESSION['error'] = 'Failed to create tag';
$this->redirect('/domains');
return;
}
} else {
$tagId = $tag['id'];
}
$updated = 0; $updated = 0;
foreach ($domainIds as $id) { foreach ($domainIds as $id) {
// Check domain access based on isolation mode // Check domain access based on isolation mode
@@ -1031,17 +1063,9 @@ class DomainController extends Controller
} }
if (!$domain) continue; if (!$domain) continue;
// Get existing tags // Add tag to domain using Tag model
$existingTags = !empty($domain['tags']) ? explode(',', $domain['tags']) : []; if ($tagModel->addToDomain($id, $tagId)) {
$updated++;
// Add new tag if it doesn't exist
if (!in_array($tagToAdd, $existingTags)) {
$existingTags[] = $tagToAdd;
$newTags = implode(',', $existingTags);
if ($this->domainModel->update($id, ['tags' => $newTags])) {
$updated++;
}
} }
} }