|
| 1 | +<?php |
| 2 | +// |
| 3 | +// ------------------------------------------------------------------------ // |
| 4 | +// XOOPS - PHP Content Management System // |
| 5 | +// Copyright (c) 2000-2016 XOOPS.org // |
| 6 | +// <https://xoops.org/> // |
| 7 | +// ------------------------------------------------------------------------ // |
| 8 | +// This program is free software; you can redistribute it and/or modify // |
| 9 | +// it under the terms of the GNU General Public License as published by // |
| 10 | +// the Free Software Foundation; either version 2 of the License, or // |
| 11 | +// (at your option) any later version. // |
| 12 | +// // |
| 13 | +// You may not change or alter any portion of this comment or credits // |
| 14 | +// of supporting developers from this source code or any supporting // |
| 15 | +// source code which is considered copyrighted (c) material of the // |
| 16 | +// original comment or credit authors. // |
| 17 | +// // |
| 18 | +// This program is distributed in the hope that it will be useful, // |
| 19 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
| 20 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
| 21 | +// GNU General Public License for more details. // |
| 22 | +// // |
| 23 | +// You should have received a copy of the GNU General Public License // |
| 24 | +// along with this program; if not, write to the Free Software // |
| 25 | +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
| 26 | +// ------------------------------------------------------------------------ // |
| 27 | +// Author: Kazumi Ono (AKA onokazu) // |
| 28 | +// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://jp.xoops.org/ // |
| 29 | +// Project: XOOPS Project // |
| 30 | +// ------------------------------------------------------------------------- // |
| 31 | + |
| 32 | +use Xmf\Request; |
| 33 | +use XoopsModules\Tdmcreate; |
| 34 | + |
| 35 | +require_once __DIR__ . '/admin_header.php'; |
| 36 | +xoops_cp_header(); |
| 37 | + |
| 38 | +$adminObject->displayNavigation(basename(__FILE__)); |
| 39 | + |
| 40 | +echo <<<EOF |
| 41 | +<form method="post" class="form-inline"> |
| 42 | +<div class="form-group"> |
| 43 | +<input name="show" class="btn btn-default" type="submit" value="Show SQL"> |
| 44 | +</div> |
| 45 | +<div class="form-group"> |
| 46 | +<input name="migrate" class="btn btn-default" type="submit" value="Do Migration"> |
| 47 | +</div> |
| 48 | +<div class="form-group"> |
| 49 | +<input name="schema" class="btn btn-default" type="submit" value="Write Schema"> |
| 50 | +</div> |
| 51 | +</form> |
| 52 | +EOF; |
| 53 | + |
| 54 | +//XoopsLoad::load('migrate', 'newbb'); |
| 55 | + |
| 56 | +/** @var Tdmcreate\Common\Configurator $configurator */ |
| 57 | +$configurator = new Tdmcreate\Common\Configurator(); |
| 58 | + |
| 59 | +/** @var \XoopsModules\Tdmcreate\Common\Migrate $migrator */ |
| 60 | +$migrator = new \XoopsModules\Tdmcreate\Common\Migrate($configurator); |
| 61 | + |
| 62 | +$op = Request::getCmd('op', 'default'); |
| 63 | +$opShow = Request::getCmd('show', null, 'POST'); |
| 64 | +$opMigrate = Request::getCmd('migrate', null, 'POST'); |
| 65 | +$opSchema = Request::getCmd('schema', null, 'POST'); |
| 66 | +$op = !empty($opShow) ? 'show' : $op; |
| 67 | +$op = !empty($opMigrate) ? 'migrate' : $op; |
| 68 | +$op = !empty($opSchema) ? 'schema' : $op; |
| 69 | + |
| 70 | +$message = ''; |
| 71 | + |
| 72 | +switch ($op) { |
| 73 | + case 'show': |
| 74 | + $queue = $migrator->getSynchronizeDDL(); |
| 75 | + if (!empty($queue)) { |
| 76 | + echo "<pre>\n"; |
| 77 | + foreach ($queue as $line) { |
| 78 | + echo $line . ";\n"; |
| 79 | + } |
| 80 | + echo "</pre>\n"; |
| 81 | + } |
| 82 | + break; |
| 83 | + case 'migrate': |
| 84 | + $migrator->synchronizeSchema(); |
| 85 | + $message = 'Database migrated to current schema.'; |
| 86 | + break; |
| 87 | + case 'schema': |
| 88 | + xoops_confirm(['op' => 'confirmwrite'], 'migrate.php', 'Warning! This is intended for developers only. Confirm write schema file from current database.', 'Confirm'); |
| 89 | + break; |
| 90 | + case 'confirmwrite': |
| 91 | + if ($GLOBALS['xoopsSecurity']->check()) { |
| 92 | + $migrator->saveCurrentSchema(); |
| 93 | + $message = 'Current schema file written'; |
| 94 | + } |
| 95 | + break; |
| 96 | +} |
| 97 | + |
| 98 | +echo "<div>$message</div>"; |
| 99 | + |
| 100 | +require_once __DIR__ . '/admin_footer.php'; |
0 commit comments