mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 11:03:17 +00:00
PHRAS-2161_coll-id-in-log-docs_MASTER
- explicit message when databox is failed to mount. - reconnect db for long migration scripts - mark (comment) doctrine "binary_strings" type so the upgrade is not done every time because the field was read-back as "varchar" - proposal on long migration scripts (could be faster)
This commit is contained in:
@@ -177,7 +177,8 @@ class DataboxesController extends Controller
|
||||
catch (\Exception $exception) {
|
||||
return $this->app->redirectPath('admin_databases', [
|
||||
'success' => 0,
|
||||
'error' => 'mount-failed'
|
||||
// 'error' => 'mount-failed'
|
||||
'error' => $exception->getMessage()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -66,6 +66,8 @@ class DatabaseMaintenanceService
|
||||
|
||||
public function upgradeDatabase(\base $base, $applyPatches)
|
||||
{
|
||||
$this->reconnect();
|
||||
|
||||
$recommends = [];
|
||||
$allTables = [];
|
||||
|
||||
@@ -126,6 +128,8 @@ class DatabaseMaintenanceService
|
||||
*/
|
||||
public function alterTableEngine($tableName, $engine, array & $recommends)
|
||||
{
|
||||
$this->reconnect();
|
||||
|
||||
$sql = 'ALTER TABLE `' . $tableName . '` ENGINE = ' . $engine;
|
||||
|
||||
try {
|
||||
@@ -145,6 +149,8 @@ class DatabaseMaintenanceService
|
||||
*/
|
||||
public function createTable(\SimpleXMLElement $table)
|
||||
{
|
||||
$this->reconnect();
|
||||
|
||||
$field_stmt = $defaults_stmt = [];
|
||||
|
||||
$create_stmt = "CREATE TABLE IF NOT EXISTS `" . $table['name'] . "` (";
|
||||
@@ -270,6 +276,8 @@ class DatabaseMaintenanceService
|
||||
|
||||
public function upgradeTable(\SimpleXMLElement $table)
|
||||
{
|
||||
$this->reconnect();
|
||||
|
||||
$correct_table = ['fields' => [], 'indexes' => [], 'collation' => []];
|
||||
$alter = $alter_pre = $return = [];
|
||||
|
||||
@@ -476,6 +484,8 @@ class DatabaseMaintenanceService
|
||||
}
|
||||
|
||||
foreach ($alter_pre as $a) {
|
||||
$this->reconnect();
|
||||
|
||||
try {
|
||||
$this->connection->exec($a);
|
||||
} catch (\Exception $e) {
|
||||
@@ -488,6 +498,8 @@ class DatabaseMaintenanceService
|
||||
}
|
||||
|
||||
foreach ($alter as $a) {
|
||||
$this->reconnect();
|
||||
|
||||
try {
|
||||
$this->connection->exec($a);
|
||||
} catch (\Exception $e) {
|
||||
@@ -561,6 +573,7 @@ class DatabaseMaintenanceService
|
||||
$this->app['swiftmailer.transport'] = null;
|
||||
|
||||
foreach ($list_patches as $patch) {
|
||||
|
||||
// Gets doctrine migrations required for current patch
|
||||
foreach ($patch->getDoctrineMigrations() as $doctrineVersion) {
|
||||
/** @var \Doctrine\DBAL\Migrations\Version $version */
|
||||
@@ -579,6 +592,8 @@ class DatabaseMaintenanceService
|
||||
|
||||
// Execute migration if not marked as migrated and not already applied by an older patch
|
||||
if (!$migration->isAlreadyApplied()) {
|
||||
$this->reconnect();
|
||||
|
||||
$version->execute('up');
|
||||
continue;
|
||||
}
|
||||
@@ -586,10 +601,14 @@ class DatabaseMaintenanceService
|
||||
// Or mark it as migrated
|
||||
$version->markMigrated();
|
||||
} else {
|
||||
$this->reconnect();
|
||||
|
||||
$version->execute('up');
|
||||
}
|
||||
}
|
||||
|
||||
$this->reconnect();
|
||||
|
||||
if (false === $patch->apply($base, $this->app)) {
|
||||
$success = false;
|
||||
}
|
||||
@@ -597,4 +616,12 @@ class DatabaseMaintenanceService
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
private function reconnect()
|
||||
{
|
||||
if($this->connection->ping() === false) {
|
||||
$this->connection->close();
|
||||
$this->connection->connect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,7 @@
|
||||
namespace Alchemy\Phrasea\Model\Types;
|
||||
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||
|
||||
class BinaryString extends Type
|
||||
@@ -23,10 +24,21 @@ class BinaryString extends Type
|
||||
return static::BINARY_STRING;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @see: https://blog.vandenbrand.org/2015/06/25/creating-a-custom-doctrine-dbal-type-the-right-way/
|
||||
* about the reason of the COMMENT in the column
|
||||
*/
|
||||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||
{
|
||||
if ($platform->getName() === 'mysql') {
|
||||
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)." ". $platform->getCollationFieldDeclaration('utf8_bin');
|
||||
/** @var MySqlPlatform $platform */
|
||||
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration)
|
||||
// . " CHARACTER SET utf8"
|
||||
. " " . $platform->getColumnCollationDeclarationSQL('utf8_bin')
|
||||
. " COMMENT '(DC2Type:binary_string)'"
|
||||
;
|
||||
}
|
||||
|
||||
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
|
||||
@@ -39,4 +51,12 @@ class BinaryString extends Type
|
||||
{
|
||||
return $platform->getVarcharDefaultLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function requiresSQLCommentHint(AbstractPlatform $platform)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -81,8 +81,13 @@ class module_console_systemUpgrade extends Command
|
||||
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
|
||||
}
|
||||
|
||||
$queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container);
|
||||
|
||||
/** @var appbox $appBox */
|
||||
$appBox = $this->getService('phraseanet.appbox');
|
||||
$queries = $appBox->forceUpgrade($upgrader, $this->container);
|
||||
/**
|
||||
* todo (?) combine schema changes on a table as a simngle sql
|
||||
* because on big tables like logs, adding 2 columns is 2 very long sql
|
||||
*/
|
||||
if ($input->getOption('dump') || $input->getOption('stderr')) {
|
||||
if (0 < count($queries)) {
|
||||
$output->writeln("Some SQL queries can be executed to optimize\n");
|
||||
|
Reference in New Issue
Block a user