From 0dde8ad3eddbc4a7477f0a62eab6a5e16858375e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E9=87=91=E5=8B=87?= Date: Mon, 10 Apr 2023 09:19:01 +0000 Subject: [PATCH] Fix default value of db. --- db/update18.3.sql | 14 +++++++++++- db/zentao.sql | 24 ++++++++++----------- lib/base/dao/dao.class.php | 36 +++++++++++++++++++++++++++++-- lib/dao/dm.class.php | 5 ++++- module/branch/model.php | 2 ++ module/bug/model.php | 2 +- module/execution/model.php | 2 ++ module/kanban/model.php | 28 ++++++++++++++++-------- module/product/model.php | 18 +++++++++------- module/productplan/model.php | 2 +- module/programplan/model.php | 6 ++++-- module/project/model.php | 41 +++++++++++++++++++++++------------- module/report/model.php | 4 ++-- module/story/model.php | 1 + 14 files changed, 131 insertions(+), 54 deletions(-) diff --git a/db/update18.3.sql b/db/update18.3.sql index 2a2ce610fa..aadaf5e657 100644 --- a/db/update18.3.sql +++ b/db/update18.3.sql @@ -215,8 +215,17 @@ CHANGE `lastEditedBy` `lastEditedBy` char(30) NOT NULL DEFAULT '', CHANGE `lastEditedDate` `lastEditedDate` date NULL; ALTER TABLE `zt_bug` +CHANGE `hardware` `hardware` varchar(30) NOT NULL DEFAULT '', CHANGE `injection` `injection` mediumint unsigned NOT NULL DEFAULT '0', +CHANGE `repo` `repo` mediumint unsigned NOT NULL DEFAULT '0', +CHANGE `mr` `mr` mediumint unsigned NOT NULL DEFAULT '0', +CHANGE `entry` `entry` text COLLATE 'utf8mb3_general_ci' NULL, +CHANGE `lines` `lines` varchar(10) COLLATE 'utf8mb3_general_ci' NOT NULL DEFAULT '', +CHANGE `v1` `v1` varchar(40) COLLATE 'utf8mb3_general_ci' NOT NULL DEFAULT '', +CHANGE `v2` `v2` varchar(40) COLLATE 'utf8mb3_general_ci' NOT NULL DEFAULT '', CHANGE `identify` `identify` mediumint unsigned NOT NULL DEFAULT '0', +CHANGE `activatedCount` `activatedCount` smallint NOT NULL DEFAULT '0', +CHANGE `activatedDate` `activatedDate` datetime NULL, CHANGE `assignedDate` `assignedDate` datetime NULL, CHANGE `resolvedDate` `resolvedDate` datetime NULL, CHANGE `closedDate` `closedDate` datetime NULL, @@ -609,7 +618,8 @@ CHANGE `editedDate` `editedDate` datetime NULL; ALTER TABLE `zt_stakeholder` CHANGE `editedBy` `editedBy` char(30) NOT NULL DEFAULT '', -CHANGE `editedDate` `editedDate` date NULL; +CHANGE `editedDate` `editedDate` date NULL, +CHANGE `deleted` `deleted` enum('0','1') NOT NULL DEFAULT '0'; ALTER TABLE `zt_story` CHANGE `assignedDate` `assignedDate` datetime NULL, @@ -623,12 +633,14 @@ CHANGE `closedDate` `closedDate` datetime NULL, CHANGE `closedReason` `closedReason` varchar(30) NOT NULL DEFAULT '', CHANGE `activatedDate` `activatedDate` datetime NULL, CHANGE `feedbackBy` `feedbackBy` varchar(100) NOT NULL DEFAULT '', +CHANGE `stagedBy` `stagedBy` char(30) NOT NULL DEFAULT '', CHANGE `notifyEmail` `notifyEmail` varchar(100) NOT NULL DEFAULT ''; ALTER TABLE `zt_storyreview` CHANGE `reviewDate` `reviewDate` datetime NULL; ALTER TABLE `zt_task` +CHANGE `design` `design` mediumint unsigned NOT NULL DEFAULT '0', CHANGE `estStarted` `estStarted` date NULL, CHANGE `realStarted` `realStarted` datetime NULL, CHANGE `finishedBy` `finishedBy` varchar(30) NOT NULL DEFAULT '', diff --git a/db/zentao.sql b/db/zentao.sql index 8ca08a0424..facafa7967 100755 --- a/db/zentao.sql +++ b/db/zentao.sql @@ -267,15 +267,15 @@ CREATE TABLE IF NOT EXISTS `zt_bug` ( `type` varchar(30) NOT NULL DEFAULT '', `os` varchar(255) NOT NULL DEFAULT '', `browser` varchar(255) NOT NULL DEFAULT '', - `hardware` varchar(30) NOT NULL, + `hardware` varchar(30) NOT NULL DEFAULT '', `found` varchar(30) NOT NULL DEFAULT '', `steps` mediumtext NOT NULL, `status` enum('active','resolved','closed') NOT NULL DEFAULT 'active', `subStatus` varchar(30) NOT NULL DEFAULT '', `color` char(7) NOT NULL, `confirmed` tinyint(1) NOT NULL DEFAULT '0', - `activatedCount` smallint(6) NOT NULL, - `activatedDate` datetime NOT NULL, + `activatedCount` smallint(6) NOT NULL DEFAULT '0', + `activatedDate` datetime NULL, `feedbackBy` varchar(100) NOT NULL, `notifyEmail` varchar(100) NOT NULL, `mailto` text, @@ -297,12 +297,12 @@ CREATE TABLE IF NOT EXISTS `zt_bug` ( `caseVersion` smallint(6) NOT NULL DEFAULT '1', `feedback` mediumint(8) unsigned NOT NULL DEFAULT '0', `result` mediumint(8) unsigned NOT NULL, - `repo` mediumint(8) unsigned NOT NULL, - `mr` mediumint(8) unsigned NOT NULL, - `entry` text NOT NULL, - `lines` varchar(10) NOT NULL, - `v1` varchar(40) NOT NULL, - `v2` varchar(40) NOT NULL, + `repo` mediumint(8) unsigned NOT NULL DEFAULT '0', + `mr` mediumint(8) unsigned NOT NULL DEFAULT '0', + `entry` text NULL, + `lines` varchar(10) NOT NULL DEFAULT '', + `v1` varchar(40) NOT NULL DEFAULT '', + `v2` varchar(40) NOT NULL DEFAULT '', `repoType` varchar(30) NOT NULL DEFAULT '', `issueKey` varchar(50) NOT NULL DEFAULT '', `testtask` mediumint(8) unsigned NOT NULL, @@ -1544,7 +1544,7 @@ CREATE TABLE IF NOT EXISTS `zt_stakeholder` ( `createdDate` date NOT NULL, `editedBy` char(30) NOT NULL DEFAULT '', `editedDate` date NULL, - `deleted` enum('0','1') NOT NULL, + `deleted` enum('0','1') NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `objectID` (`objectID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; @@ -1571,7 +1571,7 @@ CREATE TABLE IF NOT EXISTS `zt_story` ( `subStatus` varchar(30) NOT NULL DEFAULT '', `color` char(7) NOT NULL, `stage` enum('','wait','planned','projected','developing','developed','testing','tested','verified','released','closed') NOT NULL DEFAULT 'wait', - `stagedBy` char(30) NOT NULL, + `stagedBy` char(30) NOT NULL DEFAULT '', `mailto` text, `lib` mediumint(8) unsigned NOT NULL DEFAULT '0', `fromStory` mediumint(8) unsigned NOT NULL DEFAULT '0', @@ -1661,7 +1661,7 @@ CREATE TABLE IF NOT EXISTS `zt_task` ( `parent` mediumint(8) NOT NULL DEFAULT '0', `execution` mediumint(8) unsigned NOT NULL DEFAULT '0', `module` mediumint(8) unsigned NOT NULL DEFAULT '0', - `design` mediumint(8) unsigned NOT NULL, + `design` mediumint(8) unsigned NOT NULL DEFAULT '0', `story` mediumint(8) unsigned NOT NULL DEFAULT '0', `storyVersion` smallint(6) NOT NULL DEFAULT '1', `designVersion` smallint(6) unsigned NOT NULL, diff --git a/lib/base/dao/dao.class.php b/lib/base/dao/dao.class.php index e993b05e49..8942e0756c 100644 --- a/lib/base/dao/dao.class.php +++ b/lib/base/dao/dao.class.php @@ -1874,10 +1874,14 @@ class baseSQL * @access public * @return static|sql the sql object. */ - public function where($arg1, $arg2 = null, $arg3 = null) + public function where($arg1 = '', $arg2 = null, $arg3 = null) { if($this->inCondition and !$this->conditionIsTrue) return $this; - if($arg3 !== null) + if(!$arg1) + { + $condition = ''; + } + elseif($arg3 !== null) { $value = $this->quote($arg3); $condition = "`$arg1` $arg2 " . $this->quote($arg3); @@ -2105,6 +2109,34 @@ class baseSQL return $this; } + /** + * 不为空日期 + * Create not zero date. + * + * @access public + * @return static|sql the sql object. + */ + public function notZeroDate() + { + if($this->inCondition and !$this->conditionIsTrue) return $this; + $this->sql .= " > '1970-01-01' "; + return $this; + } + + /** + * 不为空时间 + * Create not zero datetime. + * + * @access public + * @return static|sql the sql object. + */ + public function notZeroDatetime() + { + if($this->inCondition and !$this->conditionIsTrue) return $this; + $this->sql .= " > '1970-01-01 00:00:01' "; + return $this; + } + /** * 创建ORDER BY部分。 * Create the order by part. diff --git a/lib/dao/dm.class.php b/lib/dao/dm.class.php index efeea6b44f..1ce24f5539 100644 --- a/lib/dao/dm.class.php +++ b/lib/dao/dm.class.php @@ -123,12 +123,15 @@ class dm extends dao private function formatIfFunction($field) { preg_match('/if\(.+\)+/i', $field, $matches); + $if = $matches[0]; if(substr_count($if, '(') == 1) { $pos = strpos($if, ')'); $if = substr($if, 0, $pos+1); } + if(strpos($field, 'sum(') == 0) $if = substr($if, 0, strlen($if)-1); + $parts = explode(',', substr($if, 3, strlen($if)-4)); // remove 'if(' and ')' $case = 'CASE WHEN ' . implode(',', array_slice($parts, 0, count($parts)-2)) . ' THEN ' . $parts[count($parts)-2] . ' ELSE ' . $parts[count($parts)-1] . ' END'; $field = str_ireplace($if, $case, $field); @@ -146,7 +149,7 @@ class dm extends dao * @access public * @return static|sql the sql object. */ - public function where($arg1, $arg2 = null, $arg3 = null) + public function where($arg1 = '', $arg2 = null, $arg3 = null) { $arg1 = $this->formatWhere($arg1); return parent::where($arg1, $arg2, $arg3); diff --git a/module/branch/model.php b/module/branch/model.php index 51f70c7fb0..e7983045fa 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -105,6 +105,8 @@ class branchModel extends model */ public function getPairs($productID, $params = '', $executionID = 0, $mergedBranches = '') { + if(!$productID) $productID = 0; + $executionBranches = array(); if($executionID) { diff --git a/module/bug/model.php b/module/bug/model.php index 119d5e1bb7..6327665556 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -62,7 +62,7 @@ class bugModel extends model $bug = fixer::input('post') ->setDefault('openedBy', $this->app->user->account) ->setDefault('openedDate', $now) - ->setDefault('project,execution,story,task', 0) + ->setDefault('project,execution,story,task,duplicateBug,linkBug', 0) ->setDefault('openedBuild', '') ->setDefault('notifyEmail', '') ->setDefault('deadline', '0000-00-00') diff --git a/module/execution/model.php b/module/execution/model.php index e3ba57b71c..798282eebd 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -541,6 +541,8 @@ class executionModel extends model $lib->type = 'execution'; $lib->main = '1'; $lib->acl = 'default'; + $lib->addedBy = $this->app->user->account; + $lib->addedDate = helper::now(); $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); $whitelist = explode(',', $sprint->whitelist); diff --git a/module/kanban/model.php b/module/kanban/model.php index de4bbf004c..fd8051f012 100755 --- a/module/kanban/model.php +++ b/module/kanban/model.php @@ -238,6 +238,8 @@ class kanbanModel extends model $lane->lastEditedTime = helper::now(); $lane->color = '#7ec5ff'; $lane->order = 1; + $lane->groupby = ''; + $lane->extra = ''; $this->dao->insert(TABLE_KANBANLANE)->data($lane)->exec(); $laneID = $this->dao->lastInsertId(); @@ -266,6 +268,7 @@ class kanbanModel extends model $column->order = $order; $column->limit = -1; $column->color = '#333'; + $column->type = ''; $this->createColumn($regionID, $column); $order ++; @@ -2488,6 +2491,10 @@ class kanbanModel extends model { $lane->type = $type; $lane->execution = $executionID; + $lane->region = 0; + $lane->group = 0; + $lane->groupby = ''; + $lane->extra = ''; $this->dao->insert(TABLE_KANBANLANE)->data($lane)->exec(); $laneID = $this->dao->lastInsertId(); @@ -2514,9 +2521,10 @@ class kanbanModel extends model foreach($this->lang->kanban->storyColumn as $colType => $name) { $data = new stdClass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; + $data->name = $name; + $data->color = '#333'; + $data->type = $colType; + $data->region = 0; if(strpos(',developing,developed,', $colType) !== false) $data->parent = $devColumnID; if(strpos(',testing,tested,', $colType) !== false) $data->parent = $testColumnID; @@ -2543,9 +2551,10 @@ class kanbanModel extends model foreach($this->lang->kanban->bugColumn as $colType => $name) { $data = new stdClass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; + $data->name = $name; + $data->color = '#333'; + $data->type = $colType; + $data->region = 0; if(strpos(',fixing,fixed,', $colType) !== false) $data->parent = $resolvingColumnID; if(strpos(',testing,tested,', $colType) !== false) $data->parent = $testColumnID; if(strpos(',resolving,test,', $colType) !== false) $data->parent = -1; @@ -2571,9 +2580,10 @@ class kanbanModel extends model foreach($this->lang->kanban->taskColumn as $colType => $name) { $data = new stdClass(); - $data->name = $name; - $data->color = '#333'; - $data->type = $colType; + $data->name = $name; + $data->color = '#333'; + $data->type = $colType; + $data->region = 0; if(strpos(',developing,developed,', $colType) !== false) $data->parent = $devColumnID; if($colType == 'develop') $data->parent = -1; diff --git a/module/product/model.php b/module/product/model.php index 1e2bcfb24f..538000b247 100755 --- a/module/product/model.php +++ b/module/product/model.php @@ -798,11 +798,13 @@ class productModel extends model /* Create doc lib. */ $this->app->loadLang('doc'); $lib = new stdclass(); - $lib->product = $productID; - $lib->name = $this->lang->doclib->main['product']; - $lib->type = 'product'; - $lib->main = '1'; - $lib->acl = 'default'; + $lib->product = $productID; + $lib->name = $this->lang->doclib->main['product']; + $lib->type = 'product'; + $lib->main = '1'; + $lib->acl = 'default'; + $lib->addedBy = $this->app->user->account; + $lib->addedDate = helper::now(); $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); return $productID; @@ -2477,11 +2479,11 @@ class productModel extends model elseif($module == 'feedback') { if($this->config->vision == 'rnd') - { + { return helper::createLink('feedback', 'admin', "browseType=byProduct&productID=%s"); - } + } elseif($this->config->vision == 'lite') - { + { return helper::createLink('feedback', 'browse', "browseType=byProduct&productID=%s"); } } diff --git a/module/productplan/model.php b/module/productplan/model.php index 7f8ca46b98..e1b876f9b6 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -523,7 +523,7 @@ class productplanModel extends model ->setIF($this->post->future || empty($_POST['end']), 'end', $this->config->productplan->future) ->setDefault('createdBy', $this->app->user->account) ->setDefault('createdDate', helper::now()) - ->setDefault('branch', 0) + ->setDefault('branch,order', 0) ->join('branch', ',') ->remove('delta,uid,future') ->get(); diff --git a/module/programplan/model.php b/module/programplan/model.php index e4284c3a73..02710f6f2a 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -745,9 +745,9 @@ class programplanModel extends model $datas[] = $plan; } - + if(empty($datas)) - { + { dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->programplan->name); return false; } @@ -969,6 +969,8 @@ class programplanModel extends model $lib->type = 'execution'; $lib->main = '1'; $lib->acl = 'default'; + $lib->addedBy = $this->app->user->account; + $lib->addedDate = helper::now(); $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); /* Add creators and PM to stage teams and project teams. */ diff --git a/module/project/model.php b/module/project/model.php index 5b42f71382..3ca191bb05 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -785,7 +785,7 @@ class projectModel extends model $finishedCount = $this->dao->select('count(id) as taskCount')->from(TABLE_TASK)->where('execution')->in(array_keys($executions))->andWhere('finishedBy')->ne('')->andWhere('deleted')->eq(0)->fetch('taskCount'); $delayedCount = $this->dao->select('count(id) as count')->from(TABLE_TASK) ->where('execution')->in(array_keys($executions)) - ->andWhere('deadline')->ne('0000-00-00') + ->andWhere('deadline')->notZeroDate() ->andWhere('deadline')->lt(helper::today()) ->andWhere('status')->in('wait,doing') ->andWhere('deleted')->eq(0) @@ -1163,7 +1163,7 @@ class projectModel extends model ->leftJoin(TABLE_PROJECTSTORY)->alias('t2')->on('t1.id=t2.story') ->where('t1.deleted')->eq(0) ->beginIF($projectID)->andWhere('t2.project')->eq($projectID)->fi() - ->groupBy('product, branch') + ->groupBy('t2.product, t2.branch') ->fetchGroup('product', 'branch'); } @@ -1411,13 +1411,15 @@ class projectModel extends model } $lib = new stdclass(); - $lib->project = $projectID; - $lib->name = $this->lang->doclib->main['project']; - $lib->type = 'project'; - $lib->main = '1'; - $lib->acl = 'default'; - $lib->users = ',' . implode(',', array_filter($authorizedUsers)) . ','; - $lib->vision = zget($project, 'vision', 'rnd'); + $lib->project = $projectID; + $lib->name = $this->lang->doclib->main['project']; + $lib->type = 'project'; + $lib->main = '1'; + $lib->acl = 'default'; + $lib->users = ',' . implode(',', array_filter($authorizedUsers)) . ','; + $lib->vision = zget($project, 'vision', 'rnd'); + $lib->addedBy = $this->app->user->account; + $lib->addedDate = helper::now(); $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); if($project->hasProduct) $this->updateProducts($projectID); @@ -1432,9 +1434,14 @@ class projectModel extends model $product->program = $project->parent ? current(array_filter(explode(',', $program->path))) : 0; $product->acl = $project->acl == 'open' ? 'open' : 'private'; $product->PO = $project->PM; + $product->QD = ''; + $product->RD = ''; + $product->whitelist = ''; $product->createdBy = $this->app->user->account; $product->createdDate = helper::now(); $product->status = 'normal'; + $product->line = 0; + $product->desc = ''; $product->createdVersion = $this->config->version; $product->vision = zget($project, 'vision', 'rnd'); @@ -1448,6 +1455,8 @@ class projectModel extends model $projectProduct = new stdclass(); $projectProduct->project = $projectID; $projectProduct->product = $productID; + $projectProduct->branch = 0; + $projectProduct->plan = 0; $this->dao->insert(TABLE_PROJECTPRODUCT)->data($projectProduct)->exec(); @@ -1456,11 +1465,13 @@ class projectModel extends model /* Create doc lib. */ $this->app->loadLang('doc'); $lib = new stdclass(); - $lib->product = $productID; - $lib->name = $this->lang->doclib->main['product']; - $lib->type = 'product'; - $lib->main = '1'; - $lib->acl = 'default'; + $lib->product = $productID; + $lib->name = $this->lang->doclib->main['product']; + $lib->type = 'product'; + $lib->main = '1'; + $lib->acl = 'default'; + $lib->addedBy = $this->app->user->account; + $lib->addedDate = helper::now(); $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); } } @@ -1811,7 +1822,7 @@ class projectModel extends model ->setDefault('lastEditedBy', $this->app->user->account) ->setDefault('lastEditedDate', $now) ->stripTags($editorIdList, $this->config->allowedTags) - ->remove('comment')->get(); + ->remove('id,comment')->get(); $project = $this->loadModel('file')->processImgURL($project, $editorIdList, $this->post->uid); $this->dao->update(TABLE_PROJECT)->data($project) diff --git a/module/report/model.php b/module/report/model.php index 4b5b138c6e..d099258813 100644 --- a/module/report/model.php +++ b/module/report/model.php @@ -457,8 +457,8 @@ class reportModel extends model $executions = $this->dao->select('id,name')->from(TABLE_EXECUTION)->where('deleted')->eq(0) ->andwhere('type')->eq('sprint') ->andwhere('multiple')->eq('1') - ->andWhere('LEFT(begin, 4)', true)->eq($year) - ->orWhere('LEFT(end, 4)')->eq($year) + ->andWhere('LEFT(`begin`, 4)', true)->eq($year) + ->orWhere('LEFT(`end`, 4)')->eq($year) ->markRight(1) ->beginIF($accounts) ->andWhere('openedBy', true)->in($accounts) diff --git a/module/story/model.php b/module/story/model.php index 6db4d3375a..74e046257d 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -230,6 +230,7 @@ class storyModel extends model ->setDefault('plan,verify,notifyEmail', '') ->setDefault('openedBy', $this->app->user->account) ->setDefault('openedDate', $now) + ->setDefault('estimate', 0) ->setIF($this->post->assignedTo, 'assignedDate', $now) ->setIF($this->post->plan > 0, 'stage', 'planned') ->setIF($this->post->estimate, 'estimate', (float)$this->post->estimate)