From 091243f32c7dd1b1eb1e4c10a1ff6fe36eda83aa Mon Sep 17 00:00:00 2001 From: wangchunsheng Date: Mon, 2 Jul 2012 13:40:50 +0000 Subject: [PATCH] * rewrite the updateVersion() and setItem() logic. --- module/admin/control.php | 6 +++--- module/misc/control.php | 2 +- module/setting/model.php | 44 ++++++++++++++-------------------------- module/user/control.php | 2 +- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/module/admin/control.php b/module/admin/control.php index d75eec4a02..c91719c522 100644 --- a/module/admin/control.php +++ b/module/admin/control.php @@ -44,7 +44,7 @@ class admin extends control */ public function ignore() { - $this->loadModel('setting')->setItemGE32('system', 'common', 'global', 'community', 'na'); + $this->loadModel('setting')->setItem('system', 'common', 'global', 'community', 'na'); die(js::locate(inlink('index'), 'parent')); } @@ -61,7 +61,7 @@ class admin extends control $response = $this->admin->registerByAPI(); if($response == 'success') { - $this->loadModel('setting')->setItemGE32('system', 'common', 'global', 'community', $this->post->account); + $this->loadModel('setting')->setItem('system', 'common', 'global', 'community', $this->post->account); echo js::alert($this->lang->admin->register->success); die(js::locate(inlink('index'), 'parent')); } @@ -85,7 +85,7 @@ class admin extends control $response = $this->admin->bindByAPI(); if($response == 'success') { - $this->loadModel('setting')->setItemGE32('system', 'common', 'global', 'community', $this->post->account); + $this->loadModel('setting')->setItem('system', 'common', 'global', 'community', $this->post->account); echo js::alert($this->lang->admin->bind->success); die(js::locate(inlink('index'), 'parent')); } diff --git a/module/misc/control.php b/module/misc/control.php index 996d0ec903..cd08c04dd1 100644 --- a/module/misc/control.php +++ b/module/misc/control.php @@ -20,7 +20,7 @@ class misc extends control public function ping() { if(mt_rand(0, 1) == 1) $this->loadModel('setting')->setSN(); - die(""); + die(""); } /** diff --git a/module/setting/model.php b/module/setting/model.php index 847ea93be5..02ab450796 100644 --- a/module/setting/model.php +++ b/module/setting/model.php @@ -69,8 +69,19 @@ class settingModel extends model */ public function updateVersion($version) { - if($version >= 3.2) $this->setItemGE32('system', 'common', 'global', 'version', $version, 0); - else $this->setItemLT32('system', 'global', 'version', $version, 0); + if($version >= 3.2) return $this->setItem('system', 'common', 'global', 'version', $version, 0); + + $this->dao->delete()->from(TABLE_CONFIG) + ->where('owner')->eq('system') + ->andWhere('section')->eq('global') + ->andWhere('`key`')->eq('version') + ->andWhere('company')->eq(0) + ->exec(); + $data->owner = 'system'; + $data->section = 'global'; + $data->key = 'version'; + $data->company = 0; + return $this->dao->insert(TABLE_CONFIG)->data($data, false)->exec(); } /** @@ -104,7 +115,7 @@ class settingModel extends model $sn == '13593e340ee2bdffed640d0c4eed8bec') { $sn = $this->computeSN(); - $this->setItemGE32('system', 'common', 'global', 'sn', $sn, 0); + $this->setItem('system', 'common', 'global', 'sn', $sn, 0); } } @@ -143,7 +154,7 @@ class settingModel extends model * @access public * @return void */ - public function setItemGE32($owner, $module, $section, $key, $value = '', $company = 'current') + public function setItem($owner, $module, $section, $key, $value = '', $company = 'current') { $item->company = $company === 'current' ? $this->app->company->id : $company; $item->owner = $owner; @@ -152,31 +163,6 @@ class settingModel extends model $item->key = $key; $item->value = $value; - $this->dao->delete()->from(TABLE_CONFIG)->where('`key`')->eq('version')->exec($autoCompany = false); - $this->dao->replace(TABLE_CONFIG)->data($item)->exec($autoCompany = false); - } - - /** - * Set value of an item. - * - * @param string $owner - * @param string $module - * @param string $section - * @param string $key - * @param string $value - * @param string|int $company - * @access public - * @return void - */ - public function setItemLT32($owner, $section, $key, $value = '', $company = 'current') - { - $item->company = $company === 'current' ? $this->app->company->id : $company; - $item->owner = $owner; - $item->section = $section; - $item->key = $key; - $item->value = $value; - - $this->dao->delete()->from(TABLE_CONFIG)->where('`key`')->eq('version')->exec($autoCompany = false); $this->dao->replace(TABLE_CONFIG)->data($item)->exec($autoCompany = false); } diff --git a/module/user/control.php b/module/user/control.php index 7c2357533d..4e61c7d38b 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -424,7 +424,7 @@ class user extends control $header['title'] = $this->lang->user->login; $this->view->header = $header; $this->view->referer = $this->referer; - $this->view->s = $this->loadModel('setting')->getItem('system', 'common', 'global', 'sn'); + $this->view->s = $this->loadModel('setting')->getItem('system', 'common', 'global', 'sn', 0); $this->view->keepLogin = $this->cookie->keepLogin ? $this->cookie->keepLogin : 'off'; $this->display(); }