Merge branch 'fix-#281' into 'develop'

Fix MySQL NO_ZERO_DATE issue previous fix. Correct SQL and execute only on MySQL.

Closes #281

See merge request framasoft/framadate!247
This commit is contained in:
Thomas Citharel 2018-03-22 14:41:28 +01:00
commit 4631b8d4c4

View File

@ -44,7 +44,7 @@ class Fix_MySQL_No_Zero_Date implements Migration {
* It is called before the execute method. * It is called before the execute method.
* *
* @param \PDO $pdo The connection to database * @param \PDO $pdo The connection to database
* @return bool true is the Migration should be executed. * @return bool true if the Migration should be executed.
*/ */
function preCondition(\PDO $pdo) { function preCondition(\PDO $pdo) {
$stmt = $pdo->prepare("SELECT Column_Default from Information_Schema.Columns where Table_Name = ? AND Column_Name = ?;"); $stmt = $pdo->prepare("SELECT Column_Default from Information_Schema.Columns where Table_Name = ? AND Column_Name = ?;");
@ -53,16 +53,18 @@ class Fix_MySQL_No_Zero_Date implements Migration {
$stmt->execute(); $stmt->execute();
$default = $stmt->fetch(\PDO::FETCH_COLUMN); $default = $stmt->fetch(\PDO::FETCH_COLUMN);
return $default !== null; $driver_name = $pdo->getAttribute(\PDO::ATTR_DRIVER_NAME);
return $default !== null && $driver_name === 'mysql';
} }
/** /**
* This method is called only one time in the migration page. * This method is called only one time in the migration page.
* *
* @param \PDO $pdo The connection to database * @param \PDO $pdo The connection to database
* @return void true is the execution succeeded * @return bool|void if the execution succeeded
*/ */
function execute(\PDO $pdo) { function execute(\PDO $pdo) {
$pdo->exec('ALTER TABLE ' . Utils::table('poll') . ' CHANGE COLUMN end_date TIMESTAMP NULL DEFAULT NULL'); $pdo->exec('ALTER TABLE ' . Utils::table('poll') . ' MODIFY end_date TIMESTAMP NULL DEFAULT NULL;');
} }
} }