Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If LegacyIdException is thrown provide proper solution #2291

Merged
merged 3 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -108,6 +109,7 @@ class Handler extends ExceptionHandler
AdminSetterHandler::class,
MigrationHandler::class,
ViteManifestNotFoundHandler::class,
LegacyIdExceptionHandler::class,
];

/** @var array<int,class-string<\Throwable>> */
Expand Down
47 changes: 47 additions & 0 deletions app/Exceptions/Handlers/LegacyIdExceptionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Exceptions\Handlers;

use App\Contracts\Exceptions\Handlers\HttpExceptionHandler;
use App\Exceptions\ModelDBException;
use Illuminate\Database\QueryException;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as HttpException;

/**
* Class LegacyIdExceptionHandler.
*
* If SQLSTATE: Numeric value out of range: 1264 is throw it means we are interacting with 32 bit DB.
* Advise to set config parameter.
*/
class LegacyIdExceptionHandler implements HttpExceptionHandler
{
/**
* {@inheritDoc}
*/
public function check(HttpException $e): bool
{
do {
if (
($e instanceof QueryException || $e instanceof ModelDBException) &&
str_contains($e->getMessage(), 'Numeric value out of range: 1264')
) {
return true;
}
} while ($e = $e->getPrevious());

return false;
}

/**
* {@inheritDoc}
*/
public function renderHttpException(SymfonyResponse $defaultResponse, 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());
}
}
Loading