需求背景
Bug Status 扩容
-> 找到 维护bug信息的表,在禅道中为 zt_bug 。观察 status字段,发现其为enum,即枚举格式,需要对其进行修改,就是需要增加枚举的值。
``sql -- 测试环境集成 增量sql 2021.1.29 ALTER tablezt_bug` modify column status ENUM (“active”,”resolved”,”closed”,”postpone”,”in process”,”fixed”) default ‘active’;
<a name="H1BXw"></a>## 后端方面- 首先要根据url访问路径大致确认要修改的代码在源代码的 module所处位置。- 直接看实例- [http://localhost:8888/www/bug-edit-1406.html](http://localhost:8888/www/bug-edit-1406.html)<br />这样一个链接,首先可以确定到 module 为 bug,涉及到的视图文件名为 edit 。<a name="b5xmS"></a>### 找到模块- 进入到源码目录下,找bug module- - 目录解释- bug - > module 名- css - > 层叠样式表文件- js -> js方法代码- lang -> 该模块主要使用的字段存放- view -> 该模块的视图文件存放- model -> 该模块主要的后端方法存放<a name="lyYy5"></a>### 找到视图文件- 在视图文件中去寻找自己要修改的目标字段,比如本例中的bug_status- <a name="hE17C"></a>### 修改字库- 找到这蹩脚的bug状态字段支持,按照扩展的规则另起目录文件进行编辑。<br /><a name="W0py1"></a>### 修改方法- 因为是对bug的状态进行修改,也就是通常后端中常见的update方法。- 找到方法之后,就需要研读代码。读懂代码最好的方式是打断点进行debug,一个bug D上一天,虽愚也会有所闻的。- 按照 规定 在 zentaopms/module/bug/ext/model/update.php 下进行修改,没有的话请创建,这是前面几张文章提到的开发规范```php<?php// 对 bug/model.php 中的update方法进行拓展/*** Update a bug.** @param int $bugID* @access public* @return void*/public function update($bugID){// get oldBugInfo$oldBug = $this->dao->select('*')->from(TABLE_BUG)->where('id')->eq((int)$bugID)->fetch();if(!empty($_POST['lastEditedDate']) and $oldBug->lastEditedDate != $this->post->lastEditedDate){dao::$errors[] = $this->lang->error->editedByOther;return false;}$now = helper::now();$bug = fixer::input('post')->cleanInt('product,module,severity,project,story,task,branch')->stripTags($this->config->bug->editor->edit['id'], $this->config->allowedTags)->setDefault('product,module,project,story,task,duplicateBug,branch', 0)->setDefault('openedBuild', '')->setDefault('plan', 0)->setDefault('deadline', '0000-00-00')->setDefault('resolvedDate', '0000-00-00 00:00:00')->setDefault('lastEditedBy', $this->app->user->account)->add('lastEditedDate', $now)->setIF(strpos($this->config->bug->edit->requiredFields, 'deadline') !== false, 'deadline', $this->post->deadline)->join('openedBuild', ',')->join('mailto', ',')->join('linkBug', ',')->setIF($this->post->assignedTo != $oldBug->assignedTo, 'assignedDate', $now)->setIF($this->post->resolvedBy != '' and $this->post->resolvedDate == '', 'resolvedDate', $now)->setIF($this->post->resolution != '' and $this->post->resolvedDate == '', 'resolvedDate', $now)->setIF($this->post->resolution != '' and $this->post->resolvedBy == '', 'resolvedBy', $this->app->user->account)->setIF($this->post->closedBy != '' and $this->post->closedDate == '', 'closedDate', $now)->setIF($this->post->closedDate != '' and $this->post->closedBy == '', 'closedBy', $this->app->user->account)->setIF($this->post->closedBy != '' or $this->post->closedDate != '', 'assignedTo', 'closed')->setIF($this->post->closedBy != '' or $this->post->closedDate != '', 'assignedDate', $now)->setIF($this->post->resolution != '' or $this->post->resolvedDate != '', 'status', 'resolved')->setIF($this->post->closedBy != '' or $this->post->closedDate != '', 'status', 'closed')->setIF(($this->post->resolution != '' or $this->post->resolvedDate != '') and $this->post->assignedTo == '', 'assignedTo', $oldBug->openedBy)->setIF(($this->post->resolution != '' or $this->post->resolvedDate != '') and $this->post->assignedTo == '', 'assignedDate', $now)->setIF($this->post->resolution == '' and $this->post->resolvedDate =='', 'status', 'active')->setIF($this->post->resolution != '', 'confirmed', 1)// 对原有的update方法进行拓展,支持新增的两个bug_status->setIF($this->post->status == 'in process', 'status', 'in process')->setIF($this->post->status == 'postpone', 'status', 'postpone')->setIF($this->post->status == 'fixed', 'status', 'fixed')// FIXME 支持修改新增的字段->setIF($this->post->story != false and $this->post->story != $oldBug->story, 'storyVersion', $this->loadModel('story')->getVersion($this->post->story))->setIF(!$this->post->linkBug, 'linkBug', '')->remove('comment,files,labels,uid,contactListMenu')->get();$bug = $this->loadModel('file')->processImgURL($bug, $this->config->bug->editor->edit['id'], $this->post->uid);$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->edit->requiredFields, 'notempty')->checkIF($bug->resolvedBy, 'resolution', 'notempty')->checkIF($bug->closedBy, 'resolution', 'notempty')->checkIF($bug->resolution == 'duplicate', 'duplicateBug', 'notempty')->where('id')->eq((int)$bugID)->exec();if(!dao::isError()){if(!empty($bug->resolvedBy)) $this->loadModel('score')->create('bug', 'resolve', $bugID);$this->file->updateObjectID($this->post->uid, $bugID, 'bug');return common::createChanges($oldBug, $bug);}}
