|
@@ -10,9 +10,6 @@ use Knuckles\Scribe\Tools\DocumentationConfig;
|
|
|
|
|
|
trait DatabaseTransactionHelpers
|
|
|
{
|
|
|
- /**
|
|
|
- * @return void
|
|
|
- */
|
|
|
private function startDbTransaction()
|
|
|
{
|
|
|
$connections = array_keys(config('database.connections', []));
|
|
@@ -27,11 +24,13 @@ trait DatabaseTransactionHelpers
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if ($this->canAllowDatabasePersistence($connection)) {
|
|
|
- throw DatabaseTransactionsNotSupported::create($connection, get_class($driver));
|
|
|
+ $driverClassName = get_class($driver);
|
|
|
+
|
|
|
+ if ($this->shouldAllowDatabasePersistence($driverClassName)) {
|
|
|
+ throw DatabaseTransactionsNotSupported::create($connection, $driverClassName);
|
|
|
}
|
|
|
|
|
|
- c::warn("Database driver for the connection [{$connection}] does not support transactions. Any changes made to your database will persist.");
|
|
|
+ c::warn("Database driver [$driverClassName] for the connection [{$connection}] does not support transactions. Any changes made to your database will persist.");
|
|
|
} catch (ScribeException $e) {
|
|
|
throw $e;
|
|
|
} catch (Exception $e) {
|
|
@@ -56,20 +55,14 @@ trait DatabaseTransactionHelpers
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- c::warn("Database driver for the connection [{$connection}] does not support transactions. Any changes made to your database have been persisted.");
|
|
|
+ $driverClassName = get_class($driver);
|
|
|
+ c::warn("Database driver [$driverClassName] for the connection [{$connection}] does not support transactions. Any changes made to your database have been persisted.");
|
|
|
} catch (Exception $e) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Assesses whether or not the "PDO" driver provided supports transactions
|
|
|
- *
|
|
|
- * @param mixed $driver Driver prodicted for particular connection
|
|
|
- *
|
|
|
- * @return boolean
|
|
|
- */
|
|
|
- private static function driverSupportsTransactions($driver)
|
|
|
+ private static function driverSupportsTransactions($driver): bool
|
|
|
{
|
|
|
$methods = ['beginTransaction', 'rollback'];
|
|
|
|
|
@@ -85,16 +78,16 @@ trait DatabaseTransactionHelpers
|
|
|
/**
|
|
|
* Assesses whether drivers without transaction support can proceed
|
|
|
*
|
|
|
- * @param string $connection Name of the connection
|
|
|
+ * @param string $driverClassName
|
|
|
*
|
|
|
- * @return boolean
|
|
|
+ * @return bool
|
|
|
*/
|
|
|
- private function canAllowDatabasePersistence(string $connection)
|
|
|
+ private function shouldAllowDatabasePersistence(string $driverClassName): bool
|
|
|
{
|
|
|
$config = $this->getConfig();
|
|
|
|
|
|
- $whitelistedConnections = $config->get('allow_database_persistence', []);
|
|
|
- return in_array($connection, $whitelistedConnections);
|
|
|
+ $whitelistedDrivers = $config->get('continue_without_database_transactions', []);
|
|
|
+ return in_array($driverClassName, $whitelistedDrivers);
|
|
|
}
|
|
|
|
|
|
/**
|