XoopsModules25x /
suico
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | /* |
||
| 5 | You may not change or alter any portion of this comment or credits |
||
| 6 | of supporting developers from this source code or any supporting source code |
||
| 7 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, |
||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 12 | */ |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @category Module |
||
| 16 | * @package suico |
||
| 17 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 18 | * @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
||
| 19 | * @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org> |
||
| 20 | */ |
||
| 21 | |||
| 22 | use XoopsModules\Suico\{ |
||
| 23 | Common\Configurator, |
||
| 24 | Common\Migrate, |
||
| 25 | Helper, |
||
| 26 | Utility |
||
| 27 | }; |
||
| 28 | /** @var Helper $helper */ |
||
| 29 | /** @var Utility $utility */ |
||
| 30 | /** @var Common\Configurator $configurator */ |
||
| 31 | /** @var Common\Migrate $migrator */ |
||
| 32 | |||
| 33 | if ((!defined('XOOPS_ROOT_PATH')) || !($GLOBALS['xoopsUser'] instanceof \XoopsUser) |
||
| 34 | || !$GLOBALS['xoopsUser']->isAdmin()) { |
||
| 35 | exit('Restricted access' . PHP_EOL); |
||
| 36 | } |
||
| 37 | include dirname(__DIR__) . '/preloads/autoloader.php'; |
||
| 38 | /** |
||
| 39 | * @param string $tablename |
||
| 40 | * |
||
| 41 | * @return bool |
||
| 42 | */ |
||
| 43 | function tableExists($tablename) |
||
| 44 | { |
||
| 45 | $result = $GLOBALS['xoopsDB']->queryF("SHOW TABLES LIKE '${tablename}'"); |
||
| 46 | return $GLOBALS['xoopsDB']->getRowsNum($result) > 0; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Prepares system prior to attempting to install module |
||
| 51 | * @param \XoopsModule $module {@link \XoopsModule} |
||
| 52 | * @return bool true if ready to install, false if not |
||
| 53 | */ |
||
| 54 | function xoops_module_pre_update_suico( |
||
| 55 | \XoopsModule $module |
||
| 56 | ) { |
||
| 57 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 58 | $helper = Helper::getInstance(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 59 | $utility = new Utility(); |
||
| 60 | $xoopsSuccess = $utility::checkVerXoops($module); |
||
| 61 | $phpSuccess = $utility::checkVerPhp($module); |
||
| 62 | $configurator = new Configurator(); |
||
| 63 | $migrator = new Migrate($configurator); |
||
| 64 | $migrator->synchronizeSchema(); |
||
| 65 | return $xoopsSuccess && $phpSuccess; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Performs tasks required during update of the module |
||
| 70 | * @param \XoopsModule $module {@link XoopsModule} |
||
| 71 | * @param null $previousVersion |
||
| 72 | * |
||
| 73 | * @return bool true if update successful, false if not |
||
| 74 | */ |
||
| 75 | function xoops_module_update_suico( |
||
| 76 | XoopsModule $module, |
||
| 77 | $previousVersion = null |
||
| 78 | ) { |
||
| 79 | $moduleDirName = basename(dirname(__DIR__)); |
||
| 80 | $moduleDirNameUpper = mb_strtoupper($moduleDirName); |
||
| 81 | |||
| 82 | $helper = Helper::getInstance(); |
||
| 83 | $utility = new Utility(); |
||
| 84 | $configurator = new Configurator(); |
||
| 85 | $helper->loadLanguage('common'); |
||
| 86 | $migrator = new Migrate($configurator); |
||
| 87 | $migrator->synchronizeSchema(); |
||
| 88 | if ($previousVersion < 360) { |
||
| 89 | //rename column EXAMPLE |
||
| 90 | // $tables = new Tables(); |
||
| 91 | // $table = 'xxxx_categories'; |
||
| 92 | // $column = 'order'; |
||
| 93 | // $newName = 'order'; |
||
| 94 | // $attributes = "INT(5) NOT NULL DEFAULT '0'"; |
||
| 95 | // if ($tables->useTable($table)) { |
||
| 96 | // $tables->alterColumn($table, $column, $attributes, $newName); |
||
| 97 | // if (!$tables->executeQueue()) { |
||
| 98 | // echo '<br>' . constant('CO_' . $moduleDirNameUpper . '_UPGRADEFAILED0') . ' ' . $migrate->getLastError(); |
||
| 99 | // } |
||
| 100 | // } |
||
| 101 | //delete old HTML templates |
||
| 102 | if (count($configurator->templateFolders) > 0) { |
||
| 103 | foreach ($configurator->templateFolders as $folder) { |
||
| 104 | $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); |
||
| 105 | if (is_dir($templateFolder)) { |
||
| 106 | $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']); |
||
| 107 | foreach ($templateList as $k => $v) { |
||
| 108 | $fileInfo = new SplFileInfo($templateFolder . $v); |
||
| 109 | if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { |
||
| 110 | if (is_file($templateFolder . $v)) { |
||
| 111 | unlink($templateFolder . $v); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | } |
||
| 118 | // --- DELETE OLD FILES --------------- |
||
| 119 | if (count($configurator->oldFiles) > 0) { |
||
| 120 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 121 | foreach ( |
||
| 122 | array_keys( |
||
| 123 | $configurator->oldFiles |
||
| 124 | ) as $i |
||
| 125 | ) { |
||
| 126 | $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); |
||
| 127 | if (is_file($tempFile)) { |
||
| 128 | unlink($tempFile); |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | // --- DELETE OLD FOLDERS --------------- |
||
| 133 | xoops_load('XoopsFile'); |
||
| 134 | if (count($configurator->oldFolders) > 0) { |
||
| 135 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 136 | foreach ( |
||
| 137 | array_keys( |
||
| 138 | $configurator->oldFolders |
||
| 139 | ) as $i |
||
| 140 | ) { |
||
| 141 | $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); |
||
| 142 | /** @var XoopsObjectHandler $folderHandler */ |
||
| 143 | $folderHandler = XoopsFile::getHandler( |
||
| 144 | 'folder', |
||
| 145 | $tempFolder |
||
| 146 | ); |
||
| 147 | $folderHandler->delete($tempFolder); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | // --- CREATE UPLOAD FOLDERS --------------- |
||
| 151 | if (count($configurator->uploadFolders) > 0) { |
||
| 152 | // foreach (array_keys($GLOBALS['uploadFolders']) as $i) { |
||
| 153 | foreach ( |
||
| 154 | array_keys( |
||
| 155 | $configurator->uploadFolders |
||
| 156 | ) as $i |
||
| 157 | ) { |
||
| 158 | $utility::createFolder($configurator->uploadFolders[$i]); |
||
| 159 | } |
||
| 160 | } |
||
| 161 | // --- COPY blank.png FILES --------------- |
||
| 162 | if (count($configurator->copyBlankFiles) > 0) { |
||
| 163 | $file = dirname(__DIR__) . '/assets/images/blank.png'; |
||
| 164 | foreach (array_keys($configurator->copyBlankFiles) as $i) { |
||
| 165 | $dest = $configurator->copyBlankFiles[$i] . '/blank.png'; |
||
| 166 | $utility::copyFile($file, $dest); |
||
| 167 | } |
||
| 168 | } |
||
| 169 | //delete .html entries from the tpl table |
||
| 170 | $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix( |
||
| 171 | 'tplfile' |
||
| 172 | ) . " WHERE `tpl_module` = '" . $module->getVar( |
||
| 173 | 'dirname', |
||
| 174 | 'n' |
||
| 175 | ) . "' AND `tpl_file` LIKE '%.html%'"; |
||
| 176 | $GLOBALS['xoopsDB']->queryF($sql); |
||
| 177 | /** @var XoopsGroupPermHandler $gpermHandler */ |
||
| 178 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 179 | return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
| 180 | } |
||
| 181 | $profileHandler = $helper->getHandler('Profile'); |
||
| 182 | $profileHandler->cleanOrphan($GLOBALS['xoopsDB']->prefix('users'), 'uid', 'profile_id'); |
||
| 183 | $fieldHandler = $helper->getHandler('Field'); |
||
| 184 | $user_fields = $fieldHandler->getUserVars(); |
||
| 185 | $criteria = new Criteria('field_name', "('" . implode("', '", $user_fields) . "')", 'IN'); |
||
| 186 | $fieldHandler->updateAll('field_config', 0, $criteria); |
||
| 187 | return true; |
||
| 188 | } |
||
| 189 |