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)
|
|
|
|
*/
|
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
use Doctrine\DBAL\Migrations\Configuration\Configuration;
|
|
|
|
use Doctrine\DBAL\Migrations\Migration;
|
|
|
|
use Doctrine\DBAL\Migrations\OutputWriter;
|
|
|
|
use Doctrine\DBAL\Migrations\Tools\Console\Helper\MigrationStatusInfosHelper;
|
2014-12-31 01:33:56 +01:00
|
|
|
use Framadate\Utils;
|
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
require_once __DIR__ . '/../app/inc/init.php';
|
2014-12-31 01:33:56 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
class MigrationLogger {
|
|
|
|
private $log;
|
2015-02-26 10:43:24 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->log = '';
|
2014-12-31 01:33:56 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
public function addLine($message)
|
|
|
|
{
|
|
|
|
$this->log .= $message . "\n";
|
|
|
|
}
|
2014-12-31 01:33:56 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
public function getLog()
|
|
|
|
{
|
|
|
|
return $this->log;
|
2014-12-31 01:33:56 +01:00
|
|
|
}
|
|
|
|
}
|
2014-12-31 14:02:36 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
$executing = false;
|
|
|
|
$migration = null;
|
|
|
|
$output = '';
|
2014-12-31 14:02:36 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
if (isset($_POST['execute'])) {
|
|
|
|
$executing = true;
|
|
|
|
}
|
2015-01-07 14:01:08 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
$migrationsDirectory = __DIR__ . '/../app/classes/Framadate/Migrations';
|
|
|
|
$log = new MigrationLogger();
|
|
|
|
|
|
|
|
$configuration = new Configuration($connect, new OutputWriter(function ($message) use ($log) {
|
|
|
|
$log->addLine($message);
|
|
|
|
}));
|
|
|
|
$configuration->setMigrationsTableName(Utils::table(MIGRATION_TABLE) . '_new');
|
|
|
|
$configuration->setMigrationsDirectory($migrationsDirectory);
|
|
|
|
$configuration->setMigrationsNamespace('DoctrineMigrations');
|
|
|
|
$configuration->registerMigrationsFromDirectory($migrationsDirectory);
|
|
|
|
|
|
|
|
if ($executing) {
|
|
|
|
$migration = new Migration($configuration);
|
|
|
|
$migration->migrate();
|
|
|
|
$output = trim(strip_tags($log->getLog()));
|
|
|
|
}
|
|
|
|
$infos = (new MigrationStatusInfosHelper($configuration))->getMigrationsInfos();
|
2015-01-07 14:01:08 +01:00
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
$smarty->assign('countTotal', $infos['Available Migrations']);
|
|
|
|
$smarty->assign('countExecuted', $infos['Executed Migrations']);
|
|
|
|
$smarty->assign('countWaiting', $infos['New Migrations']);
|
|
|
|
$smarty->assign('executing', $executing);
|
2015-03-30 15:19:56 +02:00
|
|
|
$smarty->assign('title', __('Admin', 'Migration'));
|
2018-04-18 16:16:22 +02:00
|
|
|
$smarty->assign('output', $output);
|
|
|
|
$smarty->assign('time', round((microtime(true)-$_SERVER['REQUEST_TIME_FLOAT']), 4));
|
2015-01-07 14:01:08 +01:00
|
|
|
$smarty->display('admin/migration.tpl');
|