1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
You may not change or alter any portion of this comment or credits |
4
|
|
|
of supporting developers from this source code or any supporting source code |
5
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
6
|
|
|
|
7
|
|
|
This program is distributed in the hope that it will be useful, |
8
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
9
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @category Module |
14
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
15
|
|
|
* @license GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
16
|
|
|
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
use Xmf\Module\Admin; |
20
|
|
|
use Xmf\Request; |
|
|
|
|
21
|
|
|
use XoopsModules\Suico\{ |
22
|
|
|
Common\Configurator, |
23
|
|
|
Common\Migrate |
24
|
|
|
}; |
25
|
|
|
/** @var Admin $adminObject */ |
26
|
|
|
|
27
|
|
|
require_once __DIR__ . '/admin_header.php'; |
28
|
|
|
xoops_cp_header(); |
29
|
|
|
$adminObject->displayNavigation(basename(__FILE__)); |
30
|
|
|
echo <<<EOF |
31
|
|
|
<form method="post" class="form-inline"> |
32
|
|
|
<div class="form-group"> |
33
|
|
|
<input name="show" class="btn btn-default" type="submit" value="Show SQL"> |
34
|
|
|
</div> |
35
|
|
|
<div class="form-group"> |
36
|
|
|
<input name="migrate" class="btn btn-default" type="submit" value="Do Migration"> |
37
|
|
|
</div> |
38
|
|
|
<div class="form-group"> |
39
|
|
|
<input name="schema" class="btn btn-default" type="submit" value="Write Schema"> |
40
|
|
|
</div> |
41
|
|
|
</form> |
42
|
|
|
EOF; |
43
|
|
|
//XoopsLoad::load('migrate', 'newbb'); |
44
|
|
|
$configurator = new Configurator(); |
45
|
|
|
$migrator = new Migrate($configurator); |
46
|
|
|
$op = Request::getCmd('op', 'default'); |
47
|
|
|
$opShow = Request::getCmd('show', null, 'POST'); |
48
|
|
|
$opMigrate = Request::getCmd('migrate', null, 'POST'); |
49
|
|
|
$opSchema = Request::getCmd('schema', null, 'POST'); |
50
|
|
|
$op = !empty($opShow) ? 'show' : $op; |
51
|
|
|
$op = !empty($opMigrate) ? 'migrate' : $op; |
52
|
|
|
$op = !empty($opSchema) ? 'schema' : $op; |
53
|
|
|
$message = ''; |
54
|
|
|
switch ($op) { |
55
|
|
|
case 'show': |
56
|
|
|
$queue = $migrator->getSynchronizeDDL(); |
57
|
|
|
if (!empty($queue)) { |
58
|
|
|
echo "<pre>\n"; |
59
|
|
|
foreach ($queue as $line) { |
60
|
|
|
echo $line . ";\n"; |
61
|
|
|
} |
62
|
|
|
echo "</pre>\n"; |
63
|
|
|
} |
64
|
|
|
break; |
65
|
|
|
case 'migrate': |
66
|
|
|
$migrator->synchronizeSchema(); |
67
|
|
|
$message = 'Database migrated to current schema.'; |
68
|
|
|
break; |
69
|
|
|
case 'schema': |
70
|
|
|
xoops_confirm( |
71
|
|
|
['op' => 'confirmwrite'], |
72
|
|
|
'migrate.php', |
73
|
|
|
'Warning! This is intended for developers only. Confirm write schema file from current database.', |
74
|
|
|
'Confirm' |
75
|
|
|
); |
76
|
|
|
break; |
77
|
|
|
case 'confirmwrite': |
78
|
|
|
if ($GLOBALS['xoopsSecurity']->check()) { |
79
|
|
|
$migrator->saveCurrentSchema(); |
80
|
|
|
$message = 'Current schema file written'; |
81
|
|
|
} |
82
|
|
|
break; |
83
|
|
|
} |
84
|
|
|
echo "<div>{$message}</div>"; |
85
|
|
|
require_once __DIR__ . '/admin_footer.php'; |
86
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: