ggoffy /
wgsitenotice
| 1 | <?php |
||
| 2 | |||
| 3 | namespace XoopsModules\Wgsitenotice\Common; |
||
| 4 | |||
| 5 | /* |
||
| 6 | You may not change or alter any portion of this comment or credits |
||
| 7 | of supporting developers from this source code or any supporting source code |
||
| 8 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 9 | |||
| 10 | This program is distributed in the hope that it will be useful, |
||
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 13 | */ |
||
| 14 | |||
| 15 | use XoopsModules\Wgsitenotice\Common; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Class Migrate synchronize existing tables with target schema |
||
| 19 | * |
||
| 20 | * @category Migrate |
||
| 21 | * @author Richard Griffith <[email protected]> |
||
| 22 | * @copyright 2016 XOOPS Project (https://xoops.org) |
||
| 23 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 24 | * @link https://xoops.org |
||
| 25 | */ |
||
| 26 | |||
| 27 | class Migrate extends \Xmf\Database\Migrate |
||
|
0 ignored issues
–
show
|
|||
| 28 | { |
||
| 29 | private $renameTables; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param \XoopsModules\Wgsitenotice\Common\Configurator|null $configurator |
||
| 33 | */ |
||
| 34 | public function __construct(Common\Configurator $configurator = null) |
||
| 35 | { |
||
| 36 | if (null !== $configurator) { |
||
| 37 | $this->renameTables = $configurator->renameTables; |
||
| 38 | |||
| 39 | $moduleDirName = \basename(\dirname(__DIR__, 2)); |
||
| 40 | parent::__construct($moduleDirName); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * change table prefix if needed |
||
| 46 | */ |
||
| 47 | private function changePrefix() |
||
| 48 | { |
||
| 49 | foreach ($this->renameTables as $oldName => $newName) { |
||
| 50 | if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) { |
||
| 51 | $this->tableHandler->renameTable($oldName, $newName); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Change integer IPv4 column to varchar IPv6 capable |
||
| 58 | * |
||
| 59 | * @param string $tableName table to convert |
||
| 60 | * @param string $columnName column with IP address |
||
| 61 | */ |
||
| 62 | private function convertIPAddresses($tableName, $columnName) |
||
|
0 ignored issues
–
show
|
|||
| 63 | { |
||
| 64 | if ($this->tableHandler->useTable($tableName)) { |
||
| 65 | $attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName); |
||
| 66 | if (false !== \mb_strpos($attributes, ' int(')) { |
||
| 67 | if (false === \mb_strpos($attributes, 'unsigned')) { |
||
| 68 | $this->tableHandler->alterColumn($tableName, $columnName, " bigint(16) NOT NULL DEFAULT '0' "); |
||
| 69 | $this->tableHandler->update($tableName, [$columnName => "4294967296 + $columnName"], "WHERE $columnName < 0", false); |
||
| 70 | } |
||
| 71 | $this->tableHandler->alterColumn($tableName, $columnName, " varchar(45) NOT NULL DEFAULT '' "); |
||
| 72 | $this->tableHandler->update($tableName, [$columnName => "INET_NTOA($columnName)"], '', false); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Move do* columns from newbb_posts to newbb_posts_text table |
||
| 79 | */ |
||
| 80 | private function moveDoColumns() |
||
|
0 ignored issues
–
show
|
|||
| 81 | { |
||
| 82 | $tableName = 'newbb_posts_text'; |
||
| 83 | $srcTableName = 'newbb_posts'; |
||
| 84 | if ($this->tableHandler->useTable($tableName) |
||
| 85 | && $this->tableHandler->useTable($srcTableName)) { |
||
| 86 | $attributes = $this->tableHandler->getColumnAttributes($tableName, 'dohtml'); |
||
| 87 | if (false === $attributes) { |
||
| 88 | $this->synchronizeTable($tableName); |
||
| 89 | $updateTable = $GLOBALS['xoopsDB']->prefix($tableName); |
||
| 90 | $joinTable = $GLOBALS['xoopsDB']->prefix($srcTableName); |
||
| 91 | $sql = "UPDATE `$updateTable` t1 INNER JOIN `$joinTable` t2 ON t1.post_id = t2.post_id \n" . "SET t1.dohtml = t2.dohtml, t1.dosmiley = t2.dosmiley, t1.doxcode = t2.doxcode\n" . ' , t1.doimage = t2.doimage, t1.dobr = t2.dobr'; |
||
| 92 | $this->tableHandler->addToQueue($sql); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Perform any upfront actions before synchronizing the schema |
||
| 99 | * |
||
| 100 | * Some typical uses include |
||
| 101 | * table and column renames |
||
| 102 | * data conversions |
||
| 103 | */ |
||
| 104 | protected function preSyncActions() |
||
| 105 | { |
||
| 106 | $this->changePrefix(); |
||
| 107 | /* |
||
| 108 | // columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point |
||
| 109 | $this->moveDoColumns(); |
||
| 110 | // Convert IP address columns from int to readable varchar(45) for IPv6 |
||
| 111 | $this->convertIPAddresses('newbb_posts', 'poster_ip'); |
||
| 112 | $this->convertIPAddresses('newbb_report', 'reporter_ip'); |
||
| 113 | */ |
||
| 114 | } |
||
| 115 | } |
||
| 116 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths