Passed
Pull Request — master (#88)
by Michael
02:56
created

admin/migrate.php (1 issue)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
//
4
//  ------------------------------------------------------------------------ //
5
//                XOOPS - PHP Content Management System                      //
6
//                  Copyright (c) 2000-2020 XOOPS.org                        //
7
//                       <https://xoops.org>                             //
8
//  ------------------------------------------------------------------------ //
9
//  This program is free software; you can redistribute it and/or modify     //
10
//  it under the terms of the GNU General Public License as published by     //
11
//  the Free Software Foundation; either version 2 of the License, or        //
12
//  (at your option) any later version.                                      //
13
//                                                                           //
14
//  You may not change or alter any portion of this comment or credits       //
15
//  of supporting developers from this source code or any supporting         //
16
//  source code which is considered copyrighted (c) material of the          //
17
//  original comment or credit authors.                                      //
18
//                                                                           //
19
//  This program is distributed in the hope that it will be useful,          //
20
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
//  GNU General Public License for more details.                             //
23
//                                                                           //
24
//  You should have received a copy of the GNU General Public License        //
25
//  along with this program; if not, write to the Free Software              //
26
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
//  ------------------------------------------------------------------------ //
28
// Author: Kazumi Ono (AKA onokazu)                                          //
29
// URL: http://www.myweb.ne.jp/, https://xoops.org/, http://jp.xoops.org/ //
30
// Project: XOOPS Project                                                    //
31
// ------------------------------------------------------------------------- //
32
33
use Xmf\Request;
34
use XoopsModules\Tdmdownloads\{
35
    Common\Migrate};
36
37
require_once __DIR__ . '/admin_header.php';
38
xoops_cp_header();
39
40
$adminObject->displayNavigation(basename(__FILE__));
41
42
echo <<<EOF
43
<form method="post" class="form-inline">
44
<div class="form-group">
45
<input name="show" class="btn btn-default" type="submit" value="Show SQL">
46
</div>
47
<div class="form-group">
48
<input name="migrate" class="btn btn-default" type="submit" value="Do Migration">
49
</div>
50
<div class="form-group">
51
<input name="schema" class="btn btn-default" type="submit" value="Write Schema">
52
</div>
53
</form>
54
EOF;
55
56
//XoopsLoad::load('migrate', 'newbb');
57
58
/** @var Tdmdownloads\Common\Configurator $configurator */
59
$configurator = new Tdmdownloads\Common\Configurator();
0 ignored issues
show
The type Tdmdownloads\Common\Configurator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
61
/** @var \XoopsModules\Tdmdownloads\Common\Migrate $migrator */
62
$migrator = new Migrate($configurator);
63
64
$op        = Request::getCmd('op', 'default');
65
$opShow    = Request::getCmd('show', null, 'POST');
66
$opMigrate = Request::getCmd('migrate', null, 'POST');
67
$opSchema  = Request::getCmd('schema', null, 'POST');
68
$op        = !empty($opShow) ? 'show' : $op;
69
$op        = !empty($opMigrate) ? 'migrate' : $op;
70
$op        = !empty($opSchema) ? 'schema' : $op;
71
72
$message = '';
73
74
switch ($op) {
75
    case 'show':
76
        $queue = $migrator->getSynchronizeDDL();
77
        if (!empty($queue)) {
78
            echo "<pre>\n";
79
80
            foreach ($queue as $line) {
81
                echo $line . ";\n";
82
            }
83
84
            echo "</pre>\n";
85
        }
86
        break;
87
    case 'migrate':
88
        $migrator->synchronizeSchema();
89
        $message = 'Database migrated to current schema.';
90
        break;
91
    case 'schema':
92
        xoops_confirm(['op' => 'confirmwrite'], 'migrate.php', 'Warning! This is intended for developers only. Confirm write schema file from current database.', 'Confirm');
93
        break;
94
    case 'confirmwrite':
95
        if ($GLOBALS['xoopsSecurity']->check()) {
96
            $migrator->saveCurrentSchema();
97
98
            $message = 'Current schema file written';
99
        }
100
        break;
101
}
102
103
echo "<div>$message</div>";
104
105
require_once __DIR__ . '/admin_footer.php';
106