diff --git a/admin/migration.php b/admin/migration.php index 166f790712292e3a50cac0d650c62e451c15fe3b..394890945dbf4aff2578f9592ce2460634f2b031 100644 --- a/admin/migration.php +++ b/admin/migration.php @@ -24,6 +24,7 @@ use Framadate\Migration\AddColumn_ValueMax_In_poll_For_1_1; use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9; use Framadate\Migration\Alter_Comment_table_adding_date; use Framadate\Migration\Alter_Comment_table_for_name_length; +use Framadate\Migration\Fix_MySQL_No_Zero_Date; use Framadate\Migration\From_0_0_to_0_8_Migration; use Framadate\Migration\From_0_8_to_0_9_Migration; use Framadate\Migration\Generate_uniqId_for_old_votes; @@ -49,11 +50,14 @@ $migrations = [ new Alter_Comment_table_for_name_length(), new Alter_Comment_table_adding_date(), new AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9(), - new Increase_pollId_size() + new Increase_pollId_size(), + new AddColumn_ValueMax_In_poll_For_1_1(), + new Fix_MySQL_No_Zero_Date(), ]; // --------------------------------------- // Check if MIGRATION_TABLE already exists +/** @var \Framadate\FramaDB $connect */ $tables = $connect->allTables(); $pdo = $connect->getPDO(); $prefixedMigrationTable = Utils::table(MIGRATION_TABLE); diff --git a/app/classes/Framadate/Migration/Fix_MySQL_No_Zero_Date.php b/app/classes/Framadate/Migration/Fix_MySQL_No_Zero_Date.php new file mode 100644 index 0000000000000000000000000000000000000000..eb4a7693c47c6a8badb5787aa5e904a2074aed61 --- /dev/null +++ b/app/classes/Framadate/Migration/Fix_MySQL_No_Zero_Date.php @@ -0,0 +1,68 @@ +<?php +/** + * This software is governed by the CeCILL-B license. If a copy of this license + * is not distributed with this file, you can obtain one at + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt + * + * Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ + * Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft) + * + * ============================= + * + * Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence + * ne se trouve pas avec ce fichier vous pouvez l'obtenir sur + * http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt + * + * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ + * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) + */ +namespace Framadate\Migration; + +use Framadate\Utils; + +/** + * This migration sets Poll.end_date to NULL by default + * + * @package Framadate\Migration + * @version 1.1 + */ +class Fix_MySQL_No_Zero_Date implements Migration { + function __construct() { + } + + /** + * This method should describe in english what is the purpose of the migration class. + * + * @return string The description of the migration class + */ + function description() { + return 'Sets Poll end_date to NULL by default (work around MySQL NO_ZERO_DATE)'; + } + + /** + * This method could check if the execute method should be called. + * It is called before the execute method. + * + * @param \PDO $pdo The connection to database + * @return bool true is the Migration should be executed. + */ + function preCondition(\PDO $pdo) { + $stmt = $pdo->prepare("SELECT Column_Default from Information_Schema.Columns where Table_Name = ? AND Column_Name = ?;"); + $stmt->bindValue(1, Utils::table('poll')); + $stmt->bindValue(2, 'end_date'); + $stmt->execute(); + $default = $stmt->fetch(\PDO::FETCH_COLUMN); + + return $default !== null; + } + + /** + * This method is called only one time in the migration page. + * + * @param \PDO $pdo The connection to database + * @return void true is the execution succeeded + */ + function execute(\PDO $pdo) { + $pdo->exec('ALTER TABLE ' . Utils::table('poll') . ' CHANGE COLUMN end_date TIMESTAMP NULL DEFAULT NULL'); + } +} diff --git a/app/classes/Framadate/Migration/From_0_0_to_0_8_Migration.php b/app/classes/Framadate/Migration/From_0_0_to_0_8_Migration.php index 4dd1e12ec54b01de21bd7e9b75c164aa18ff253c..092de919938c368ea21eff08a2bf3630b1044d68 100644 --- a/app/classes/Framadate/Migration/From_0_0_to_0_8_Migration.php +++ b/app/classes/Framadate/Migration/From_0_0_to_0_8_Migration.php @@ -71,7 +71,7 @@ CREATE TABLE IF NOT EXISTS `sondage` ( `titre` text, `id_sondage_admin` char(24) DEFAULT NULL, `date_creation` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, - `date_fin` timestamp NOT NULL, + `date_fin` timestamp NULL DEFAULT NULL, `format` varchar(2) DEFAULT NULL, `mailsonde` tinyint(1) DEFAULT \'0\', `statut` int(11) NOT NULL DEFAULT \'1\' COMMENT \'1 = actif ; 0 = inactif ; \', diff --git a/app/classes/Framadate/Migration/From_0_8_to_0_9_Migration.php b/app/classes/Framadate/Migration/From_0_8_to_0_9_Migration.php index c8f10967600fdd05ef9beaf0c52c90e6698aa93e..bb8ab7810b3fa68ac505a18628ea73e3fc28c753 100644 --- a/app/classes/Framadate/Migration/From_0_8_to_0_9_Migration.php +++ b/app/classes/Framadate/Migration/From_0_8_to_0_9_Migration.php @@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS `' . Utils::table('poll') . '` ( `admin_name` VARCHAR(64) DEFAULT NULL, `admin_mail` VARCHAR(128) DEFAULT NULL, `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `end_date` TIMESTAMP NOT NULL, + `end_date` TIMESTAMP NULL DEFAULT NULL, `format` VARCHAR(1) DEFAULT NULL, `editable` TINYINT(1) DEFAULT \'0\', `receiveNewVotes` TINYINT(1) DEFAULT \'0\',