-
Notifications
You must be signed in to change notification settings - Fork 40
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
[BC] Migrate to DBAL 3 #55
Conversation
/** @var int */ | ||
protected $defaultFetchMode = FetchMode::ASSOCIATIVE; | ||
|
||
public function __construct( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Costructor is (finally!) moved from the trait into the class, and simplified.
public function setGoneAwayDetector(GoneAwayDetector $goneAwayDetector): void | ||
{ | ||
$this->goneAwayDetector = $goneAwayDetector; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we need this setter... Maybe it's required if we make this class final
.
public function canTryAgain(\Throwable $throwable, int $attempt, string $sql = null, bool $ignoreTransactionLevel = false): bool | ||
{ | ||
if ($attempt >= $this->reconnectAttempts) { | ||
return false; | ||
} | ||
|
||
if (! $ignoreTransactionLevel && $this->getTransactionNestingLevel() > 0) { | ||
return false; | ||
} | ||
|
||
return $this->goneAwayDetector->isGoneAwayException($throwable, $sql); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method now centralizes all the retry logic, alongside with the GoneAwayDetector
|
||
namespace Facile\DoctrineMySQLComeBack\Doctrine\DBAL\Detector; | ||
|
||
class MySQLGoneAwayDetector implements GoneAwayDetector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nearly the same as the old ServerGoneAwayExceptionsAwareTrait
src/Statement.php
Outdated
return $this->executeWithRetry(__METHOD__, $params); | ||
} | ||
|
||
private function executeWithRetry(string $methodName, ...$params) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method allows the retry in a flexible fashion. Maybe we can refactor this out or move it inside the connection?
We should absolutely take into account doctrine/dbal#4119, since it could mean that we can intercept all disconnections at the wrapper level, simplifying the work a lot. |
Big breakthrough: with a4a70f0 I discovered that the While for PDO I don't know how it works, but the test is green... |
// public function execute($params = null): Result | ||
// { | ||
// return $this->executeWithRetry([parent::class, 'execute'], $params); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm leaving this here because we will need to re-add this method lather. I will probably try to split it into a child class, so that it could be enabled when needed, because it will trigger deprecations.
This is the first attempt at a new major version, jumping directly on supporting DBAL 3.
THIS IS STILL A WIP.There are so many BCs and various changes that I'm trying to take the chance to profoundly refactor this lib.
These are the major points:
final
and cannot be extended anymore; also, DBAL 3 does not allow anymore to identify platforms by names ofinstaceof
of the driver, but withPlatform
; this allows to change the approach of this lib and require only the wrapper connection, no more driver substitutionConnection
classServerGoneAwayExceptionsAwareTrait
is now moved behind a dedicatedGoneAwayDetector
interface, that allows a basicMySQLGoneAwayDetector
and the possibility to swap that out if necessaryOther comments will follow inline with the code.