|
@@ -3,6 +3,9 @@
|
|
|
namespace Knuckles\Scribe\Extracting;
|
|
|
|
|
|
use Exception;
|
|
|
+use Knuckles\Scribe\Exceptions\DbTransactionSupportException;
|
|
|
+use Knuckles\Scribe\Exceptions\ScribeException;
|
|
|
+use Knuckles\Scribe\Tools\ConsoleOutputUtils as c;
|
|
|
|
|
|
trait DatabaseTransactionHelpers
|
|
|
{
|
|
@@ -15,14 +18,22 @@ trait DatabaseTransactionHelpers
|
|
|
|
|
|
foreach ($connections as $conn) {
|
|
|
try {
|
|
|
- tap(
|
|
|
- app('db')->connection($conn),
|
|
|
- function ($driver) {
|
|
|
- if (self::driverSupportsTransactions($driver)) {
|
|
|
- $driver->beginTransaction();
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
+ $driver = app('db')->connection($conn);
|
|
|
+
|
|
|
+ if (self::driverSupportsTransactions($driver)) {
|
|
|
+ $driver->beginTransaction();
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($this->isNoTransactionSupportAllowed($conn)) {
|
|
|
+ throw DbTransactionSupportException::create($conn, get_class($driver));
|
|
|
+ }
|
|
|
+
|
|
|
+ c::warn("Database driver for the connection [{$conn}] does not support transactions!");
|
|
|
+ c::warn("Any changes made to your database will persist!");
|
|
|
+ } catch (ScribeException $e) {
|
|
|
+ throw $e;
|
|
|
} catch (Exception $e) {
|
|
|
}
|
|
|
}
|
|
@@ -37,14 +48,16 @@ trait DatabaseTransactionHelpers
|
|
|
|
|
|
foreach ($connections as $conn) {
|
|
|
try {
|
|
|
- tap(
|
|
|
- app('db')->connection($conn),
|
|
|
- function ($driver) {
|
|
|
- if (self::driverSupportsTransactions($driver)) {
|
|
|
- $driver->rollBack();
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
+ $driver = app('db')->connection($conn);
|
|
|
+
|
|
|
+ if (self::driverSupportsTransactions($driver)) {
|
|
|
+ $driver->rollBack();
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ c::warn("Database driver for the connection [{$conn}] does not support transactions!");
|
|
|
+ c::warn("Any changes made to your database will persist!");
|
|
|
} catch (Exception $e) {
|
|
|
}
|
|
|
}
|
|
@@ -69,4 +82,31 @@ trait DatabaseTransactionHelpers
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Assesses whether drivers without transaction support can proceed
|
|
|
+ *
|
|
|
+ * @param string $connection_name Name of the connection
|
|
|
+ *
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ private function isNoTransactionSupportAllowed(string $connection_name)
|
|
|
+ {
|
|
|
+ $config = $this->getConfig();
|
|
|
+
|
|
|
+ $allow_list = $config->get('run_without_database_transactions', false);
|
|
|
+
|
|
|
+ if (is_array($allow_list)) {
|
|
|
+ return in_array($connection_name, $allow_list);
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Returns an instance of the documentation config
|
|
|
+ *
|
|
|
+ * @return DocumentationConfig
|
|
|
+ */
|
|
|
+ abstract public function getConfig();
|
|
|
}
|