* Refactor upgradeModel::addAdminInviteField.

This commit is contained in:
wangxuepeng
2023-12-19 10:24:50 +08:00
parent 6da054bda9
commit 76ffd72551
3 changed files with 36 additions and 2 deletions
+2 -1
View File
@@ -8771,6 +8771,7 @@ class upgradeModel extends model
}
/**
* 为喧喧表添加adminInvite字段。
* Add adminInvite field for xuanxuan.
*
* @access public
@@ -8780,7 +8781,7 @@ class upgradeModel extends model
{
$table = $this->config->db->prefix . 'im_chat';
$exists = $this->checkFieldsExists($table, 'adminInvite');
if(!$exists) $this->dbh->exec("ALTER TABLE $table ADD `adminInvite` enum('0','1') NOT NULL DEFAULT '0' AFTER `mergedChats`");
if(!$exists) $this->dbh->exec("ALTER TABLE {$table} ADD `adminInvite` enum('0','1') NOT NULL DEFAULT '0' AFTER `mergedChats`");
}
/**
@@ -0,0 +1,34 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
/**
title=测试 upgradeModel->hasConsistencyError();
cid=1
- 修改后,im_chart表中存在adminInvite字段 @adminInvite
**/
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/upgrade.class.php';
zdTable('user')->gen(1);
su('admin');
$upgrade = new upgradeTest();
$checkExistSql = "show columns from `%s` like '%s'";
$dropSql = "Alter table `%s` drop column `%s`";
global $config, $tester;
$table = $config->db->prefix . 'im_chat';
$column = 'adminInvite';
$result = $tester->dbh->query(sprintf($checkExistSql, $table, $column))->fetch();
if($result) $deleteAction = $tester->dbh->exec(sprintf($dropSql, $table, $column)); //检测到adminInvite字段存在,删除该字段
$upgrade->addAdminInviteField();
$result2 = $tester->dbh->query(sprintf($checkExistSql, $table, $column))->fetch();
r($result2) && p('Field') && e('adminInvite'); //修改后,im_chart表中存在adminInvite字段
@@ -17,7 +17,6 @@ include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/upgrade.class.php';
global $app;
$path = $app->getTmpRoot() . 'log/';
$filename = 'consistency.%s.log.php';