mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-09 02:54:26 +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) {
|
catch (\Exception $exception) {
|
||||||
return $this->app->redirectPath('admin_databases', [
|
return $this->app->redirectPath('admin_databases', [
|
||||||
'success' => 0,
|
'success' => 0,
|
||||||
'error' => 'mount-failed'
|
// 'error' => 'mount-failed'
|
||||||
|
'error' => $exception->getMessage()
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -66,6 +66,8 @@ class DatabaseMaintenanceService
|
|||||||
|
|
||||||
public function upgradeDatabase(\base $base, $applyPatches)
|
public function upgradeDatabase(\base $base, $applyPatches)
|
||||||
{
|
{
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$recommends = [];
|
$recommends = [];
|
||||||
$allTables = [];
|
$allTables = [];
|
||||||
|
|
||||||
@@ -126,6 +128,8 @@ class DatabaseMaintenanceService
|
|||||||
*/
|
*/
|
||||||
public function alterTableEngine($tableName, $engine, array & $recommends)
|
public function alterTableEngine($tableName, $engine, array & $recommends)
|
||||||
{
|
{
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$sql = 'ALTER TABLE `' . $tableName . '` ENGINE = ' . $engine;
|
$sql = 'ALTER TABLE `' . $tableName . '` ENGINE = ' . $engine;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -145,6 +149,8 @@ class DatabaseMaintenanceService
|
|||||||
*/
|
*/
|
||||||
public function createTable(\SimpleXMLElement $table)
|
public function createTable(\SimpleXMLElement $table)
|
||||||
{
|
{
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$field_stmt = $defaults_stmt = [];
|
$field_stmt = $defaults_stmt = [];
|
||||||
|
|
||||||
$create_stmt = "CREATE TABLE IF NOT EXISTS `" . $table['name'] . "` (";
|
$create_stmt = "CREATE TABLE IF NOT EXISTS `" . $table['name'] . "` (";
|
||||||
@@ -270,6 +276,8 @@ class DatabaseMaintenanceService
|
|||||||
|
|
||||||
public function upgradeTable(\SimpleXMLElement $table)
|
public function upgradeTable(\SimpleXMLElement $table)
|
||||||
{
|
{
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$correct_table = ['fields' => [], 'indexes' => [], 'collation' => []];
|
$correct_table = ['fields' => [], 'indexes' => [], 'collation' => []];
|
||||||
$alter = $alter_pre = $return = [];
|
$alter = $alter_pre = $return = [];
|
||||||
|
|
||||||
@@ -476,6 +484,8 @@ class DatabaseMaintenanceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($alter_pre as $a) {
|
foreach ($alter_pre as $a) {
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->connection->exec($a);
|
$this->connection->exec($a);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -488,6 +498,8 @@ class DatabaseMaintenanceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach ($alter as $a) {
|
foreach ($alter as $a) {
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->connection->exec($a);
|
$this->connection->exec($a);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@@ -561,6 +573,7 @@ class DatabaseMaintenanceService
|
|||||||
$this->app['swiftmailer.transport'] = null;
|
$this->app['swiftmailer.transport'] = null;
|
||||||
|
|
||||||
foreach ($list_patches as $patch) {
|
foreach ($list_patches as $patch) {
|
||||||
|
|
||||||
// Gets doctrine migrations required for current patch
|
// Gets doctrine migrations required for current patch
|
||||||
foreach ($patch->getDoctrineMigrations() as $doctrineVersion) {
|
foreach ($patch->getDoctrineMigrations() as $doctrineVersion) {
|
||||||
/** @var \Doctrine\DBAL\Migrations\Version $version */
|
/** @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
|
// Execute migration if not marked as migrated and not already applied by an older patch
|
||||||
if (!$migration->isAlreadyApplied()) {
|
if (!$migration->isAlreadyApplied()) {
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$version->execute('up');
|
$version->execute('up');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -586,10 +601,14 @@ class DatabaseMaintenanceService
|
|||||||
// Or mark it as migrated
|
// Or mark it as migrated
|
||||||
$version->markMigrated();
|
$version->markMigrated();
|
||||||
} else {
|
} else {
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
$version->execute('up');
|
$version->execute('up');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->reconnect();
|
||||||
|
|
||||||
if (false === $patch->apply($base, $this->app)) {
|
if (false === $patch->apply($base, $this->app)) {
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
@@ -597,4 +616,12 @@ class DatabaseMaintenanceService
|
|||||||
|
|
||||||
return $success;
|
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;
|
namespace Alchemy\Phrasea\Model\Types;
|
||||||
|
|
||||||
use Doctrine\DBAL\Types\Type;
|
use Doctrine\DBAL\Types\Type;
|
||||||
|
use Doctrine\DBAL\Platforms\MySqlPlatform;
|
||||||
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
||||||
|
|
||||||
class BinaryString extends Type
|
class BinaryString extends Type
|
||||||
@@ -23,10 +24,21 @@ class BinaryString extends Type
|
|||||||
return static::BINARY_STRING;
|
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)
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
|
||||||
{
|
{
|
||||||
if ($platform->getName() === 'mysql') {
|
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);
|
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
|
||||||
@@ -39,4 +51,12 @@ class BinaryString extends Type
|
|||||||
{
|
{
|
||||||
return $platform->getVarcharDefaultLength();
|
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>'));
|
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 ($input->getOption('dump') || $input->getOption('stderr')) {
|
||||||
if (0 < count($queries)) {
|
if (0 < count($queries)) {
|
||||||
$output->writeln("Some SQL queries can be executed to optimize\n");
|
$output->writeln("Some SQL queries can be executed to optimize\n");
|
||||||
|
Reference in New Issue
Block a user