2014-12-31 01:33:56 +01:00
|
|
|
<?php
|
2015-01-18 17:03:47 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2016-08-04 22:26:37 +02:00
|
|
|
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
2015-01-18 17:03:47 +01:00
|
|
|
*
|
|
|
|
* =============================
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*/
|
|
|
|
|
2015-01-01 01:18:49 +01:00
|
|
|
use Framadate\Migration\From_0_0_to_0_8_Migration;
|
2014-12-31 01:33:56 +01:00
|
|
|
use Framadate\Migration\From_0_8_to_0_9_Migration;
|
2015-03-05 21:30:33 +01:00
|
|
|
use Framadate\Migration\AddColumn_receiveNewComments_For_0_9;
|
2015-04-02 11:58:47 +02:00
|
|
|
use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9;
|
2015-04-05 18:36:43 +02:00
|
|
|
use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
|
2015-10-12 21:59:45 +02:00
|
|
|
use Framadate\Migration\Alter_Comment_table_for_name_length;
|
2015-10-12 22:26:22 +02:00
|
|
|
use Framadate\Migration\Alter_Comment_table_adding_date;
|
2015-06-24 22:37:46 +02:00
|
|
|
use Framadate\Migration\Generate_uniqId_for_old_votes;
|
2015-04-09 12:34:48 +02:00
|
|
|
use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9;
|
2015-12-05 14:24:38 +01:00
|
|
|
use Framadate\Migration\Increase_pollId_size;
|
2014-12-31 01:33:56 +01:00
|
|
|
use Framadate\Migration\Migration;
|
2015-09-18 11:20:04 +02:00
|
|
|
use Framadate\Migration\RPadVotes_from_0_8;
|
2014-12-31 01:33:56 +01:00
|
|
|
use Framadate\Utils;
|
|
|
|
|
2015-01-07 14:01:08 +01:00
|
|
|
include_once __DIR__ . '/../app/inc/init.php';
|
2014-12-31 01:33:56 +01:00
|
|
|
|
2015-02-26 10:43:24 +01:00
|
|
|
set_time_limit(300);
|
|
|
|
|
2014-12-31 01:33:56 +01:00
|
|
|
// List a Migration sub classes to execute
|
|
|
|
$migrations = [
|
2015-01-01 01:18:49 +01:00
|
|
|
new From_0_0_to_0_8_Migration(),
|
2015-01-17 01:22:03 +01:00
|
|
|
new From_0_8_to_0_9_Migration(),
|
2015-04-02 11:58:47 +02:00
|
|
|
new AddColumn_receiveNewComments_For_0_9(),
|
2015-04-05 18:36:43 +02:00
|
|
|
new AddColumn_uniqId_In_vote_For_0_9(),
|
|
|
|
new AddColumn_hidden_In_poll_For_0_9(),
|
2015-06-24 22:37:46 +02:00
|
|
|
new Generate_uniqId_for_old_votes(),
|
2015-10-12 23:46:02 +02:00
|
|
|
new RPadVotes_from_0_8(),
|
2015-10-12 21:59:45 +02:00
|
|
|
new Alter_Comment_table_for_name_length(),
|
2015-04-09 12:34:48 +02:00
|
|
|
new Alter_Comment_table_adding_date(),
|
|
|
|
new AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9(),
|
2015-12-05 14:24:38 +01:00
|
|
|
new Increase_pollId_size()
|
2014-12-31 01:33:56 +01:00
|
|
|
];
|
2014-12-31 14:02:36 +01:00
|
|
|
// ---------------------------------------
|
2014-12-31 01:33:56 +01:00
|
|
|
|
|
|
|
// Check if MIGRATION_TABLE already exists
|
|
|
|
$tables = $connect->allTables();
|
|
|
|
$pdo = $connect->getPDO();
|
2014-12-31 15:19:15 +01:00
|
|
|
$prefixedMigrationTable = Utils::table(MIGRATION_TABLE);
|
2014-12-31 01:33:56 +01:00
|
|
|
|
2014-12-31 15:19:15 +01:00
|
|
|
if (!in_array($prefixedMigrationTable, $tables)) {
|
2014-12-31 01:33:56 +01:00
|
|
|
$pdo->exec('
|
2014-12-31 15:19:15 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS `' . $prefixedMigrationTable . '` (
|
2014-12-31 01:33:56 +01:00
|
|
|
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
|
|
`name` TEXT NOT NULL,
|
|
|
|
`execute_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
PRIMARY KEY (`id`)
|
|
|
|
)
|
|
|
|
ENGINE = MyISAM
|
|
|
|
DEFAULT CHARSET = utf8;');
|
|
|
|
}
|
|
|
|
|
2015-08-13 10:00:45 +02:00
|
|
|
$selectStmt = $pdo->prepare('SELECT id FROM `' . $prefixedMigrationTable . '` WHERE name=?');
|
|
|
|
$insertStmt = $pdo->prepare('INSERT INTO `' . $prefixedMigrationTable . '` (name) VALUES (?)');
|
2014-12-31 14:02:36 +01:00
|
|
|
$countSucceeded = 0;
|
|
|
|
$countFailed = 0;
|
|
|
|
$countSkipped = 0;
|
2014-12-31 01:33:56 +01:00
|
|
|
|
|
|
|
// Loop on every Migration sub classes
|
2015-01-07 14:01:08 +01:00
|
|
|
$success = [];
|
|
|
|
$fail = [];
|
2014-12-31 01:33:56 +01:00
|
|
|
foreach ($migrations as $migration) {
|
|
|
|
$className = get_class($migration);
|
|
|
|
|
|
|
|
// Check if $className is a Migration sub class
|
|
|
|
if (!$migration instanceof Migration) {
|
2015-01-07 14:01:08 +01:00
|
|
|
$smarty->assign('error', 'The class ' . $className . ' is not a sub class of Framadate\\Migration\\Migration.');
|
|
|
|
$smarty->display('error.tpl');
|
2014-12-31 01:33:56 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the Migration is already executed
|
|
|
|
$selectStmt->execute([$className]);
|
|
|
|
$executed = $selectStmt->rowCount();
|
|
|
|
$selectStmt->closeCursor();
|
|
|
|
|
2015-01-02 09:08:07 +01:00
|
|
|
if (!$executed && $migration->preCondition($pdo)) {
|
2014-12-31 01:33:56 +01:00
|
|
|
$migration->execute($pdo);
|
2014-12-31 14:02:36 +01:00
|
|
|
if ($insertStmt->execute([$className])) {
|
|
|
|
$countSucceeded++;
|
2015-02-26 10:44:49 +01:00
|
|
|
$success[] = $migration->description();
|
2014-12-31 14:02:36 +01:00
|
|
|
} else {
|
|
|
|
$countFailed++;
|
2015-02-26 10:44:49 +01:00
|
|
|
$fail[] = $migration->description();
|
2014-12-31 14:02:36 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$countSkipped++;
|
2014-12-31 01:33:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-12-31 14:02:36 +01:00
|
|
|
|
|
|
|
$countTotal = $countSucceeded + $countFailed + $countSkipped;
|
|
|
|
|
2015-01-07 14:01:08 +01:00
|
|
|
$smarty->assign('success', $success);
|
|
|
|
$smarty->assign('fail', $fail);
|
|
|
|
|
|
|
|
$smarty->assign('countSucceeded', $countSucceeded);
|
|
|
|
$smarty->assign('countFailed', $countFailed);
|
|
|
|
$smarty->assign('countSkipped', $countSkipped);
|
|
|
|
$smarty->assign('countTotal', $countTotal);
|
2015-02-26 10:44:49 +01:00
|
|
|
$smarty->assign('time', $total_time = round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT']), 4));
|
2015-01-07 14:01:08 +01:00
|
|
|
|
2015-03-30 15:19:56 +02:00
|
|
|
$smarty->assign('title', __('Admin', 'Migration'));
|
2015-01-07 14:01:08 +01:00
|
|
|
|
|
|
|
$smarty->display('admin/migration.tpl');
|