diff --git a/db/update21.1.sql b/db/update21.1.sql index f29e6b3013..8f3f281eaa 100644 --- a/db/update21.1.sql +++ b/db/update21.1.sql @@ -90,3 +90,5 @@ INSERT INTO `zt_pivotspec` SELECT `id`,`version`,`driver`,`mode`,`name`,`desc`,` UPDATE `zt_pivotdrill` SET `version` = '1'; DELETE FROM `zt_cron` WHERE `command` = 'moduleName=misc&methodName=cleanCache'; + +INSERT INTO `zt_cron` (`m`, `h`, `dom`, `mon`, `dow`, `command`, `remark`, `type`, `buildin`, `status`) VALUES ('0', '2', '*', '*', '*', 'moduleName=system&methodName=initSystem', '初始化产品下应用数据', 'zentao', 1, 'normal'); diff --git a/module/system/control.php b/module/system/control.php index 03d9e16513..5468c9d09b 100644 --- a/module/system/control.php +++ b/module/system/control.php @@ -1,5 +1,8 @@ sendError(dao::getError()); $this->sendSuccess(array('load' => true)); } + + /** + * 初始化产品下的应用数据(仅用于第一次安装)。 + * Init the application data of the product. + * + * @access public + * @return void + */ + public function initSystem() + { + $releaseList = $this->loadModel('release')->getListBySystem(array('0')); + if(!$releaseList) return false; + + return $this->system->initSystem(); + } } diff --git a/module/system/model.php b/module/system/model.php index eed7c3c76e..5e07e230f8 100644 --- a/module/system/model.php +++ b/module/system/model.php @@ -512,4 +512,33 @@ class systemModel extends model ->andWhere('deleted')->eq(0) ->fetchAll('id'); } + + /** + * 初始化应用。 + * Initialize application. + * + * @access public + * @return bool + */ + public function initSystem(): bool + { + $system = new stdclass(); + $system->createdDate = helper::now(); + $system->createdBy = 'system'; + + $productPairs = $this->loadModel('product')->getPairs('all', 0, '', 1); + foreach($productPairs as $productID => $productName) + { + $system->name = $productName; + $system->product = $productID; + $systemID = $this->system->create($system); + + $this->dao->update(TABLE_BUILD)->set('system')->eq($systemID)->where('id')->eq($systemID)->exec(); + $this->dao->update(TABLE_RELEASE)->set('system')->eq($systemID)->where('id')->eq($systemID)->exec(); + } + + if(!dao::isError()) $this->dao->delete()->from(TABLE_CRON)->where('command')->eq('moduleName=system&methodName=initSystem')->exec(); + + return dao::isError(); + } }