Skip to content

Commit

Permalink
更新模組時的自動修改資料庫欄位
Browse files Browse the repository at this point in the history
  • Loading branch information
tadlearn committed Jul 20, 2021
1 parent 0399c8a commit 29a802f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions class/Update.php
Expand Up @@ -19,24 +19,24 @@ public static function mk_group($name = "")
return $groupid;
}

// 進行某些檢查
public static function chk_1()
// 進行有無候補欄位檢查
public static function chk_candidate()
{
global $xoopsDB;
// $sql = 'SELECT count(*) FROM ' . $xoopsDB->prefix('資料表名') . ' ';
// $result = $xoopsDB->query($sql);
// if (empty($result)) {
// return true;
// }
$sql = 'SELECT count(`candidate`) FROM ' . $xoopsDB->prefix('tad_signup_actions') . ' ';
$result = $xoopsDB->query($sql);
if (empty($result)) {
return true;
}

return false;
}

// 執行某些調整
public static function go_1()
// 執行新增候補欄位
public static function go_candidate()
{
global $xoopsDB;
// $sql = 'ALTER TABLE ' . $xoopsDB->prefix('資料表名') . '';
// $xoopsDB->queryF($sql) or redirect_header(XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin', 30, $xoopsDB->error());
$sql = 'ALTER TABLE ' . $xoopsDB->prefix('tad_signup_actions') . ' ADD `candidate` tinyint(3) unsigned NOT NULL';
$xoopsDB->queryF($sql) or redirect_header(XOOPS_URL . '/modules/system/admin.php?fct=modulesadmin', 30, $xoopsDB->error());
}
}
5 changes: 3 additions & 2 deletions include/onUpdate.php
Expand Up @@ -38,8 +38,9 @@ function xoops_module_update_tad_signup(XoopsModule $module, $old_version)
{
global $xoopsDB;

if (Update::chk_1()) {
Update::go_1();
// 新增候補欄位
if (Update::chk_candidate()) {
Update::go_candidate();
}

return true;
Expand Down
1 change: 1 addition & 0 deletions sql/mysql.sql
Expand Up @@ -8,6 +8,7 @@ CREATE TABLE `tad_signup_actions` (
`setup` text NOT NULL,
`uid` mediumint(8) unsigned NOT NULL,
`enable` enum('1','0') NOT NULL,
`candidate` tinyint(3) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Expand Down

0 comments on commit 29a802f

Please sign in to comment.