* adjust upgrade for delete company field.

This commit is contained in:
wyd621
2013-11-19 06:51:13 +00:00
parent e529262e4d
commit 50bf3dff05
+13 -16
View File
@@ -732,23 +732,20 @@ class upgradeModel extends model
$this->dbh->exec("ALTER TABLE " . TABLE_GROUPPRIV . " DROP `company`;");
/* Delete version and sn that don's conform to the rules. Prevent conflict when delete company's field.*/
$version = $this->dao->select('*')->from(TABLE_CONFIG)
->where('`key`')->eq('version')
->andWhere('company')->eq(0)
->andWhere('owner')->eq('system')
->andWhere('module')->eq('common')
->andWhere('section')->eq('global')
->fetch();
$this->dao->delete()->from(TABLE_CONFIG)->where('`key`')->eq('version')->andWhere('id')->ne($version->id)->exec();
$configs = $this->dao->select('*')->from(TABLE_CONFIG)->orderBy('id desc')->fetchAll('id');
$items = array();
$delID = array();
foreach($configs as $config)
{
if(isset($items[$config->owner][$config->module][$config->section][$config->key]))
{
$delID[] = $config->id;
continue;
}
$sn = $this->dao->select('*')->from(TABLE_CONFIG)
->where('`key`')->eq('sn')
->andWhere('company')->eq($this->app->company->id)
->andWhere('owner')->eq('system')
->andWhere('module')->eq('common')
->andWhere('section')->eq('global')
->fetch();
$this->dao->delete()->from(TABLE_CONFIG)->where('`key`')->eq('sn')->andWhere('id')->ne($sn->id)->exec();
$items[$config->owner][$config->module][$config->section][$config->key] = $config->id;
}
if($delID) $this->dao->delete()->from(TABLE_CONFIG)->where('id')->in($delID)->exec();
$this->dbh->exec("ALTER TABLE " . TABLE_CONFIG . " DROP `company`;");