XoopsModules25x /
xoopspoll
| 1 | <?php |
||
| 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 | * Xoopspoll install functions.php |
||
| 14 | * |
||
| 15 | * @copyright:: {@link https://xoops.org/ XOOPS Project} |
||
| 16 | * @license :: {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
| 17 | * @package :: xoopspoll |
||
| 18 | * @since :: 1.40 |
||
| 19 | * @author :: zyspec <[email protected]> |
||
| 20 | */ |
||
| 21 | |||
| 22 | use XoopsModules\Xoopspoll\{ |
||
| 23 | Helper, |
||
| 24 | Utility |
||
| 25 | }; |
||
| 26 | |||
| 27 | |||
| 28 | //xoops_load('pollUtility', 'xoopspoll'); |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param \XoopsDatabase|null $db |
||
| 32 | * @param $fromTable |
||
| 33 | * @param $toTable |
||
| 34 | * @return bool |
||
| 35 | */ |
||
| 36 | function xoopspollChangeTableName(\XoopsDatabase $db, $fromTable, $toTable) |
||
| 37 | { |
||
| 38 | $fromTable = addslashes($fromTable); |
||
| 39 | $toTable = addslashes($toTable); |
||
| 40 | /* |
||
| 41 | $fromThisTable = $db->prefix("{$fromTable}"); |
||
| 42 | $toThisTable = $db->prefix("{$toTable}"); |
||
| 43 | */ |
||
| 44 | $helper = Helper::getInstance(); |
||
| 45 | $success = false; |
||
| 46 | if (Utility::dbTableExists($db, $fromTable) && !Utility::dbTableExists($db, $toTable)) { |
||
| 47 | $sql = sprintf('ALTER TABLE ' . $db->prefix((string)$fromTable) . ' RENAME ' . $db->prefix('{$toTable}')); |
||
| 48 | $success = $db->queryF($sql); |
||
| 49 | if (false === $success) { |
||
| 50 | $moduleHandler = $helper->getHandler('Module'); |
||
| 51 | $xoopspollModule = $moduleHandler->getByDirname('xoopspoll'); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 52 | $xoopspollModule->setErrors(sprintf(_AM_XOOPSPOLL_UPGRADE_FAILED, $fromTable)); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | return $success; |
||
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param \XoopsModule $module |
||
| 61 | * @param $prev_version |
||
| 62 | * @return bool |
||
| 63 | */ |
||
| 64 | function xoops_module_update_xoopspoll(\XoopsModule $module, $prev_version) |
||
| 65 | { |
||
| 66 | // referer check |
||
| 67 | $success = false; |
||
| 68 | $ref = xoops_getenv('HTTP_REFERER'); |
||
| 69 | $helper = Helper::getInstance(); |
||
| 70 | if (('' === $ref) || 0 === mb_strpos($ref, $GLOBALS['xoops']->url('modules/system/admin.php'))) { |
||
| 71 | /* module specific part */ |
||
| 72 | require_once $helper->path('include/oninstall.php'); |
||
| 73 | |||
| 74 | $installedVersion = (int)$prev_version; |
||
| 75 | xoops_loadLanguage('admin', 'xoopspoll'); |
||
| 76 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 77 | $success = true; |
||
| 78 | if ($installedVersion < 140) { |
||
| 79 | /* add column for poll anonymous which was created in versions prior |
||
| 80 | * to 1.40 of xoopspoll but not automatically created |
||
| 81 | */ |
||
| 82 | $result = $db->queryF('SHOW COLUMNS FROM ' . $db->prefix('xoopspoll_desc') . " LIKE 'anonymous'"); |
||
| 83 | $foundAnon = $db->getRowsNum($result); |
||
| 84 | if (empty($foundAnon)) { |
||
| 85 | // column doesn't exist, so try and add it |
||
| 86 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . ' ADD anonymous TINYINT( 1 ) DEFAULT 0 NOT NULL AFTER multiple'); |
||
| 87 | if (false === $success) { |
||
| 88 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'anonymous'); |
||
| 89 | } |
||
| 90 | } |
||
| 91 | /* change description to TINYTEXT */ |
||
| 92 | if ($success) { |
||
| 93 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . ' MODIFY description TINYTEXT NOT NULL'); |
||
| 94 | if (false === $success) { |
||
| 95 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'description'); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($success) { |
||
| 100 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD multilimit TINYINT( 63 ) UNSIGNED DEFAULT '0' NOT NULL AFTER multiple"); |
||
| 101 | if (false === $success) { |
||
| 102 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'multilimit'); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | if ($success) { |
||
| 106 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD mail_voter TINYINT( 1 ) UNSIGNED DEFAULT '0' NOT NULL AFTER mail_status"); |
||
| 107 | if (false === $success) { |
||
| 108 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'mail_voter'); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | if ($success) { |
||
| 112 | $result = $db->queryF('SHOW COLUMNS FROM ' . $db->prefix('xoopspoll_desc') . " LIKE 'visibility'"); |
||
| 113 | $foundCol = $db->getRowsNum($result); |
||
| 114 | if (empty($foundCol)) { |
||
| 115 | // column doesn't exist, so try and add it |
||
| 116 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD visibility INT( 3 ) DEFAULT '0' NOT NULL AFTER display"); |
||
| 117 | if (false === $success) { |
||
| 118 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'visibility'); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | if ($success) { |
||
| 125 | /* now reverse table names changes from 1.40 Beta */ |
||
| 126 | $s1 = xoopspollChangeTableName($db, 'mod_xoopspoll_option', 'xoopspoll_option'); |
||
| 127 | $s2 = xoopspollChangeTableName($db, 'mod_xoopspoll_desc', 'xoopspoll_desc'); |
||
| 128 | $s3 = xoopspollChangeTableName($db, 'mod_xoopspoll_log', 'xoopspoll_log'); |
||
| 129 | $success = ($s1 && $s2 && $s3); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | return $success; |
||
| 134 | } |
||
| 135 |