Skip to content

Commit

Permalink
Worked on PR review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ketan-canyon committed Oct 30, 2024
1 parent 4410cfc commit 381c626
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class () extends Migration {
public function up(): void
{
Schema::table('knowledge_base_categories', function (Blueprint $table) {
$table->string('slug')->nullable(false)->change();
});
}

public function down(): void
{
Schema::table('knowledge_base_categories', function (Blueprint $table) {
$table->string('slug')->nullable()->change();
});
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use Illuminate\Support\Str;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Database\QueryException;
use Illuminate\Database\Migrations\Migration;
use AidingApp\KnowledgeBase\Models\KnowledgeBaseCategory;
use Illuminate\Database\UniqueConstraintViolationException;

return new class () extends Migration {
public function up(): void
Expand All @@ -27,20 +26,15 @@ public function up(): void
DB::commit();

break;
} catch (QueryException $e) {
} catch (UniqueConstraintViolationException $e) {
DB::rollBack();

if ($e->errorInfo[1] === 7) {
$attempts++;
$slug = $baseSlug . '-' . $attempts;
} else {
throw $e;
}
$attempts++;
$slug = $baseSlug . '-' . $attempts;
}
}

if ($attempts == 15) {
Log::info("Failed to generate a unique slug after 15 attempts for category ID {$category->name}\n");
throw new Exception("Failed to generate a unique slug after 15 attempts for category ID {$category->name}\n");
}
}
}
Expand Down

0 comments on commit 381c626

Please sign in to comment.