diff --git a/app/Constants/RandomID.php b/app/Constants/RandomID.php index f999c7dcc8d..406f4cef753 100644 --- a/app/Constants/RandomID.php +++ b/app/Constants/RandomID.php @@ -27,6 +27,4 @@ class RandomID */ public const ID_LENGTH = 24; public const ID_TYPE = 'string'; - public const LEGACY_ID_NAME = 'legacy_id'; - public const LEGACY_ID_TYPE = 'integer'; } \ No newline at end of file diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 282585da180..3927c20a9fa 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -14,7 +14,6 @@ use App\Exceptions\Handlers\AccessDBDenied; use App\Exceptions\Handlers\AdminSetterHandler; use App\Exceptions\Handlers\InstallationHandler; -use App\Exceptions\Handlers\LegacyIdExceptionHandler; use App\Exceptions\Handlers\MigrationHandler; use App\Exceptions\Handlers\NoEncryptionKey; use App\Exceptions\Handlers\ViteManifestNotFoundHandler; @@ -115,7 +114,6 @@ class Handler extends ExceptionHandler AdminSetterHandler::class, MigrationHandler::class, ViteManifestNotFoundHandler::class, - LegacyIdExceptionHandler::class, ]; /** @var array> */ diff --git a/app/Exceptions/Handlers/LegacyIdExceptionHandler.php b/app/Exceptions/Handlers/LegacyIdExceptionHandler.php deleted file mode 100644 index 0af67bfba06..00000000000 --- a/app/Exceptions/Handlers/LegacyIdExceptionHandler.php +++ /dev/null @@ -1,54 +0,0 @@ -getMessage(), 'Numeric value out of range: 1264') - ) { - return true; - } - $e = $e->getPrevious(); - } while ($e !== null); - - return false; - } - - /** - * {@inheritDoc} - */ - public function renderHttpException(SymfonyResponse $default_response, HttpException $e): SymfonyResponse - { - return response()->view('error.error', [ - 'code' => $e->getStatusCode(), - 'type' => class_basename($e), - 'message' => 'SQLSTATE: Numeric value out of range: 1264 for column \'legacy_id\'. To fix, please set `force_32bit_ids` to `1` in your Settings => More.', - ], $e->getStatusCode(), $e->getHeaders()); - } -} \ No newline at end of file diff --git a/app/Models/BaseAlbumImpl.php b/app/Models/BaseAlbumImpl.php index 21e7564dbcc..5a022ed53e1 100644 --- a/app/Models/BaseAlbumImpl.php +++ b/app/Models/BaseAlbumImpl.php @@ -97,7 +97,6 @@ * implementation of it) and we need this class to be instantiable. * * @property string $id - * @property int $legacy_id * @property Carbon $created_at * @property Carbon $updated_at * @property string $title @@ -176,7 +175,6 @@ class BaseAlbumImpl extends Model implements HasRandomID */ protected $attributes = [ 'id' => null, - RandomID::LEGACY_ID_NAME => null, 'created_at' => null, 'updated_at' => null, 'title' => null, // Sic! `title` is actually non-nullable, but using `null` here forces the caller to actually set a title before saving. @@ -196,7 +194,6 @@ class BaseAlbumImpl extends Model implements HasRandomID */ protected $casts = [ 'id' => RandomID::ID_TYPE, - RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE, 'created_at' => 'datetime', 'updated_at' => 'datetime', 'is_nsfw' => 'boolean', diff --git a/app/Models/Extensions/BaseAlbum.php b/app/Models/Extensions/BaseAlbum.php index 337d7dfeb3e..da4c3737164 100644 --- a/app/Models/Extensions/BaseAlbum.php +++ b/app/Models/Extensions/BaseAlbum.php @@ -36,7 +36,6 @@ * * @property string $id * @property string $title - * @property int $legacy_id * @property Carbon $created_at * @property Carbon $updated_at * @property string|null $description diff --git a/app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php b/app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php index b80a2601e79..ecf687bbd46 100644 --- a/app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php +++ b/app/Models/Extensions/HasRandomIDAndLegacyTimeBasedID.php @@ -12,7 +12,6 @@ use App\Exceptions\InsufficientEntropyException; use App\Exceptions\Internal\NotImplementedException; use App\Exceptions\Internal\TimeBasedIdException; -use App\Models\Configs; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\InvalidCastException; use Illuminate\Database\Eloquent\JsonEncodingException; @@ -64,9 +63,6 @@ public function setAttribute($key, $value): mixed if ($key === $this->getKeyName()) { throw new NotImplementedException('must not set primary key explicitly, primary key will be set on first insert'); } - if ($key === RandomID::LEGACY_ID_NAME) { - throw new NotImplementedException('must not set legacy key explicitly, legacy key will be set on first insert'); - } return parent::setAttribute($key, $value); } @@ -170,27 +166,6 @@ private function generateKey(): void } catch (\Exception $e) { throw new InsufficientEntropyException($e); } - // @codeCoverageIgnoreEnd - if ( - PHP_INT_MAX === 2147483647 || - Configs::getValueAsBool('force_32bit_ids') - ) { - // For 32-bit installations, we can only afford to store the - // full seconds in id. The calling code needs to be able to - // handle duplicate ids. Note that this also exposes us to - // the year 2038 problem. - // @codeCoverageIgnoreStart - $legacy_id = sprintf('%010d', microtime(true)); - // @codeCoverageIgnoreEnd - } else { - // Ensure 4 digits after the decimal point, 15 characters - // total (including the decimal point), 0-padded on the - // left if needed (shouldn't be needed unless we move back in - // time :-) ) - $legacy_id = sprintf('%015.4f', microtime(true)); - $legacy_id = str_replace('.', '', $legacy_id); - } $this->attributes[$this->getKeyName()] = $id; - $this->attributes[RandomID::LEGACY_ID_NAME] = intval($legacy_id); } } diff --git a/app/Models/Photo.php b/app/Models/Photo.php index 47c50ad1f99..caabc2206e2 100644 --- a/app/Models/Photo.php +++ b/app/Models/Photo.php @@ -12,7 +12,6 @@ use App\Casts\ArrayCast; use App\Casts\DateTimeWithTimezoneCast; use App\Casts\MustNotSetCast; -use App\Constants\RandomID; use App\Contracts\Models\HasUTCBasedTimes; use App\Enum\LicenseType; use App\Enum\StorageDiskType; @@ -43,7 +42,6 @@ * App\Models\Photo. * * @property string $id - * @property int $legacy_id * @property string $title * @property string|null $description * @property string[] $tags @@ -151,7 +149,6 @@ class Photo extends Model implements HasUTCBasedTimes public $incrementing = false; protected $casts = [ - RandomID::LEGACY_ID_NAME => RandomID::LEGACY_ID_TYPE, 'created_at' => 'datetime', 'updated_at' => 'datetime', 'taken_at' => DateTimeWithTimezoneCast::class, @@ -172,7 +169,6 @@ class Photo extends Model implements HasUTCBasedTimes * relation but shall not be serialized to JSON */ protected $hidden = [ - RandomID::LEGACY_ID_NAME, 'album', // do not serialize relation in order to avoid infinite loops 'owner', // do not serialize relation 'owner_id', diff --git a/database/migrations/2025_05_27_081037_drop_legacy_id.php b/database/migrations/2025_05_27_081037_drop_legacy_id.php new file mode 100644 index 00000000000..2c2829db1e1 --- /dev/null +++ b/database/migrations/2025_05_27_081037_drop_legacy_id.php @@ -0,0 +1,70 @@ +dropUnique('photos_legacy_id_unique'); + }); + Schema::table('base_albums', function (Blueprint $table) { + $table->dropUnique('base_albums_legacy_id_unique'); + }); + } catch (\Throwable $e) { + // Do nothing + } + + Schema::table('photos', function (Blueprint $table) { + $table->dropColumn(self::LEGACY_ID_NAME); + }); + Schema::table('base_albums', function (Blueprint $table) { + $table->dropColumn(self::LEGACY_ID_NAME); + }); + + DB::table('configs') + ->where('key', '=', 'legacy_id_redirection') + ->delete(); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('base_albums', function (Blueprint $table) { + $table->unsignedBigInteger('legacy_id')->after('id')->nullable(false); + }); + + Schema::table('photos', function (Blueprint $table) { + $table->unsignedBigInteger('legacy_id')->after('id')->nullable(false); + }); + + DB::table('configs') + ->insert([ + 'key' => 'legacy_id_redirection', + 'value' => '1', + 'cat' => 'Admin', + 'type_range' => '0|1', + 'is_secret' => 0, + 'description' => 'Enables/disables the redirection support for legacy IDs', + 'level' => 0, + 'not_on_docker' => 0, + 'is_expert' => 1, + 'order' => 6, + ]); + } +};