* Adjust action module.

This commit is contained in:
leiyong
2021-03-05 18:12:21 +08:00
parent ba5bf6720a
commit 1dfda97a43
4 changed files with 118 additions and 77 deletions
+9 -7
View File
@@ -33,11 +33,13 @@ $config->action->objectNameFields['job'] = 'name';
$config->action->commonImgSize = 870;
$config->action->majorList = array();
$config->action->majorList['task'] = array('assigned', 'finished', 'activated');
$config->action->majorList['bug'] = array('assigned', 'resolved');
$config->action->majorList['release'] = array('opened');
$config->action->majorList['build'] = array('opened');
$config->action->majorList['product'] = array('opened', 'edited');
$config->action->majorList['project'] = array('opened', 'edited');
$config->action->majorList['task'] = array('assigned', 'finished', 'activated');
$config->action->majorList['bug'] = array('assigned', 'resolved');
$config->action->majorList['release'] = array('opened');
$config->action->majorList['build'] = array('opened');
$config->action->majorList['product'] = array('opened', 'edited');
$config->action->majorList['program'] = array('opened', 'edited');
$config->action->majorList['project'] = array('opened', 'edited');
$config->action->majorList['execution'] = array('opened', 'edited');
$config->action->needGetPRJType = 'story,build,task,bug,case,testcase,caselib,testtask,testsuite,testreport,doc,issue,release,risk,design';
$config->action->needGetProjectType = 'story,build,task,bug,case,testcase,caselib,testtask,testsuite,testreport,doc,issue,release,risk,design';
+20 -20
View File
@@ -12,13 +12,13 @@
class action extends control
{
/**
* Trash
*
* @param string $type all|hidden
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* Trash.
*
* @param string $type all|hidden
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
@@ -60,8 +60,8 @@ class action extends control
/**
* Undelete an object.
*
* @param int $actionID
*
* @param int $actionID
* @access public
* @return void
*/
@@ -72,9 +72,9 @@ class action extends control
}
/**
* Hide an deleted object.
*
* @param int $actionID
* Hide an deleted object.
*
* @param int $actionID
* @access public
* @return void
*/
@@ -86,8 +86,8 @@ class action extends control
/**
* Hide all deleted objects.
*
* @param string $confirm
*
* @param string $confirm yes|no
* @access public
* @return void
*/
@@ -105,10 +105,10 @@ class action extends control
}
/**
* Comment.
*
* @param string $objectType
* @param int $objectID
* Comment.
*
* @param string $objectType
* @param int $objectID
* @access public
* @return void
*/
@@ -127,8 +127,8 @@ class action extends control
/**
* Edit comment of a action.
*
* @param int $actionID
*
* @param int $actionID
* @access public
* @return void
*/
+70 -50
View File
@@ -33,13 +33,14 @@ class actionModel extends model
public function create($objectType, $objectID, $actionType, $comment = '', $extra = '', $actor = '', $autoDelete = true)
{
if(strtolower($actionType) == 'commented' and empty($comment)) return false;
$actor = $actor ? $actor : $this->app->user->account;
$actionType = strtolower($actionType);
if($actor == 'guest' and $actionType == 'logout') return false;
$action = new stdclass();
$objectType = str_replace('`', '', $objectType);
$action = new stdclass();
$action->objectType = strtolower($objectType);
$action->objectID = $objectID;
$action->actor = $actor;
@@ -48,7 +49,7 @@ class actionModel extends model
$action->extra = $extra;
/* Use purifier to process comment. Fix bug #2683. */
$action->comment = fixer::stripDataTags($comment);
$action->comment = fixer::stripDataTags($comment);
/* Process action. */
if($this->post->uid)
@@ -67,8 +68,10 @@ class actionModel extends model
if($this->post->uid) $this->file->updateObjectID($this->post->uid, $objectID, $objectType);
/* Call the message notification function. */
$this->loadModel('message')->send($objectType, $objectID, $actionType, $actionID, $actor);
/* Add index for global search. */
$this->saveIndex($objectType, $objectID, $actionType);
return $actionID;
@@ -102,10 +105,9 @@ class actionModel extends model
public function getUnreadActions($actionID = 0)
{
if(!is_numeric($actionID)) $actionID = 0;
$objectList['task'] = TABLE_TASK;
$objectList['bug'] = TABLE_BUG;
$actions = array();
$actions = array();
$objectList = array('task' => TABLE_TASK, 'bug' => TABLE_BUG);
foreach($objectList as $object => $table)
{
$idList = $this->dao->select('id')->from($table)->where('assignedTo')->eq($this->app->user->account)->fetchPairs('id');
@@ -208,7 +210,6 @@ class actionModel extends model
*/
public function getList($objectType, $objectID)
{
if($this->config->systemMode == 'classic' and $objectType == 'execution') $objectType = 'project';
$commiters = $this->loadModel('user')->getCommiters();
$actions = $this->dao->select('*')->from(TABLE_ACTION)
->beginIF($objectType == 'project')
@@ -219,7 +220,9 @@ class actionModel extends model
->where('objectType')->eq($objectType)
->andWhere('objectID')->eq((int)$objectID)
->fi()
->orderBy('date, id')->fetchAll('id');
->orderBy('date, id')
->fetchAll('id');
$histories = $this->getHistory(array_keys($actions));
$this->loadModel('file');
@@ -241,12 +244,12 @@ class actionModel extends model
{
$action->actor = $commiters[$action->actor];
}
elseif($actionName == 'linked2project')
elseif($actionName == 'linked2execution')
{
$name = $this->dao->select('name')->from(TABLE_PROJECT)->where('id')->eq($action->extra)->fetch('name');
if($name) $action->extra = common::hasPriv('project', 'story') ? html::a(helper::createLink('project', 'story', "projectID=$action->extra"), $name) : $name;
}
elseif($actionName == 'linked2prj')
elseif($actionName == 'linked2project')
{
$name = $this->dao->select('name')->from(TABLE_PROJECT)->where('id')->eq($action->extra)->fetch('name');
$productID = trim($action->product, ',');
@@ -281,12 +284,12 @@ class actionModel extends model
{
$action->extra = html::a(helper::createLink('bug', 'view', "bugID=$action->extra"), $action->extra);
}
elseif($actionName == 'unlinkedfromproject')
elseif($actionName == 'unlinkedfromexecution')
{
$name = $this->dao->select('name')->from(TABLE_PROJECT)->where('id')->eq($action->extra)->fetch('name');
if($name) $action->extra = common::hasPriv('project', 'story') ? html::a(helper::createLink('project', 'story', "projectID=$action->extra"), "#$action->extra " . $name) : "#$action->extra " . $name;
}
elseif($actionName == 'unlinkedfromprj')
elseif($actionName == 'unlinkedfromproject')
{
$name = $this->dao->select('name')->from(TABLE_PROJECT)->where('id')->eq($action->extra)->fetch('name');
$productID = trim($action->product, ',');
@@ -382,12 +385,12 @@ class actionModel extends model
$action->extra = strtolower($extra);
if($id)
{
$table = $this->config->objectTables[$action->extra];
$field = $this->config->action->objectNameFields[$action->extra];
$object = $this->dao->select($field . ',PRJ')->from($table)->where('id')->eq($id)->fetch();
$name = $object->$field;
$PRJ = $object->PRJ;
if($name) $action->appendLink = html::a(helper::createLink($action->extra, 'view', "id=$id", '', '', $PRJ), "#$id " . $name);
$table = $this->config->objectTables[$action->extra];
$field = $this->config->action->objectNameFields[$action->extra];
$object = $this->dao->select($field . ',project')->from($table)->where('id')->eq($id)->fetch();
$name = $object->$field;
$projectID = $object->project;
if($name) $action->appendLink = html::a(helper::createLink($action->extra, 'view', "id=$id", '', '', $projectID), "#$id " . $name);
}
}
}
@@ -420,6 +423,7 @@ class actionModel extends model
}
$action->comment = $this->file->setImgSize($action->comment, $this->config->action->commonImgSize);
$actions[$actionID] = $action;
}
@@ -427,11 +431,11 @@ class actionModel extends model
}
/**
* process Project Actions change actionStype
* Process Project Actions change actionStype.
*
* @param array $actions
* @param array $actions
* @access public
* @return void
* @return array
*/
public function processProjectActions($actions)
{
@@ -498,9 +502,9 @@ class actionModel extends model
{
if(!isset($this->config->objectTables[$objectType]))continue;
$objectIds = array_unique($objectIds);
$table = $this->config->objectTables[$objectType];
$field = $this->config->action->objectNameFields[$objectType];
$objectIds = array_unique($objectIds);
$table = $this->config->objectTables[$objectType];
$field = $this->config->action->objectNameFields[$objectType];
$objectNames[$objectType] = $this->dao->select("id, $field AS name")->from($table)->where('id')->in($objectIds)->fetchPairs();
}
@@ -551,6 +555,7 @@ class actionModel extends model
* Print actions of an object.
*
* @param array $action
* @param string $desc
* @access public
* @return void
*/
@@ -648,14 +653,14 @@ class actionModel extends model
/* Build has priv condition. */
$condition = 1;
if($productID == 'all') $products = $this->app->user->view->products;
if($productID == 'all') $products = $this->app->user->view->products;
if($executionID == 'all') $executions = $this->app->user->view->sprints;
if($productID == 'all' or $executionID == 'all')
{
$executionCondition = $executionID == 'all' ? "execution " . helper::dbIN($executions) : '';
$productCondition = $productID == 'all' ? "INSTR('," . $products . ",', product) > 0" : '';
if(is_numeric($productID)) $productCondition = "product like'%,$productID,%' or product='$productID'";
$productCondition = $productID == 'all' ? "INSTR('," . $products . ",', product) > 0" : '';
if(is_numeric($productID)) $productCondition = "product like'%,$productID,%' or product='$productID'";
if(is_numeric($executionID)) $executionCondition = "execution='$executionID'";
$condition = "(product =',0,' AND execution = '0')";
@@ -698,7 +703,7 @@ class actionModel extends model
}
/**
* Get dynamic show action
* Get dynamic show action.
*
* @return String
*/
@@ -723,7 +728,7 @@ class actionModel extends model
* Get dynamic by search.
*
* @param array $products
* @param array $projects
* @param array $executions
* @param int $queryID
* @param string $orderBy
* @param object $pager
@@ -732,7 +737,7 @@ class actionModel extends model
* @access public
* @return array
*/
public function getDynamicBySearch($products, $projects, $queryID, $orderBy = 'date_desc', $pager = null, $date = '', $direction = 'next')
public function getDynamicBySearch($products, $executions, $queryID, $orderBy = 'date_desc', $pager = null, $date = '', $direction = 'next')
{
$query = $queryID ? $this->loadModel('search')->getQuery($queryID) : '';
@@ -744,9 +749,9 @@ class actionModel extends model
}
if($this->session->actionQuery == false) $this->session->set('actionQuery', ' 1 = 1');
$allProduct = "`product` = 'all'";
$allProject = "`project` = 'all'";
$actionQuery = $this->session->actionQuery;
$allProduct = "`product` = 'all'";
$allExecution = "`execution` = 'all'";
$actionQuery = $this->session->actionQuery;
$productID = 0;
if(preg_match("/`product` = '(\d*)'/", $actionQuery, $out))
@@ -763,14 +768,14 @@ class actionModel extends model
$actionQuery = str_replace($allProduct, '1', $actionQuery);
}
/* If the sql not include 'project', add check purview for project. */
if(strpos($actionQuery, $allProject) === false)
/* If the sql not include 'execution', add check purview for execution. */
if(strpos($actionQuery, $allExecution) === false)
{
$actionQuery = $actionQuery . ' AND `project`' . helper::dbIN(array_keys($projects));
$actionQuery = $actionQuery . ' AND `execution`' . helper::dbIN(array_keys($executions));
}
else
{
$actionQuery = str_replace($allProject, '1', $actionQuery);
$actionQuery = str_replace($allExecution, '1', $actionQuery);
}
$actionQuery = str_replace("`product` = '$productID'", "`product` LIKE '%,$productID,%'", $actionQuery);
@@ -795,6 +800,7 @@ class actionModel extends model
{
$actionCondition = $this->getActionCondition();
if(is_array($actionCondition)) return array();
return $actions = $this->dao->select('*')->from(TABLE_ACTION)
->where($sql)
->beginIF(!empty($actionCondition))->andWhere("($actionCondition)")->fi()
@@ -813,6 +819,7 @@ class actionModel extends model
public function transformActions($actions)
{
$this->app->loadLang('todo');
/* Get commiters. */
$commiters = $this->loadModel('user')->getCommiters();
@@ -827,13 +834,13 @@ class actionModel extends model
$field = $this->config->action->objectNameFields[$objectType];
if($table != TABLE_TODO)
{
if(strpos($this->config->action->needGetPRJType, $objectType) !== false)
if(strpos($this->config->action->needGetProjectType, $objectType) !== false)
{
$objectInfo = $this->dao->select("id, PRJ, $field AS name")->from($table)->where('id')->in($objectIds)->fetchAll();
$objectInfo = $this->dao->select("id, project, $field AS name")->from($table)->where('id')->in($objectIds)->fetchAll();
foreach($objectInfo as $object)
{
$objectName[$object->id] = $object->name;
$objectPRJ[$object->id] = $object->PRJ;
$objectName[$object->id] = $object->name;
$objectProject[$object->id] = $object->project;
}
}
elseif($objectType == 'project' or $objectType == 'execution')
@@ -841,18 +848,18 @@ class actionModel extends model
$objectInfo = $this->dao->select("id, project, $field AS name")->from($table)->where('id')->in($objectIds)->fetchAll();
foreach($objectInfo as $object)
{
$objectName[$object->id] = $object->name;
$objectPRJ[$object->id] = $object->project > 0 ? $object->project : $object->id;
$objectName[$object->id] = $object->name;
$objectProject[$object->id] = $object->project > 0 ? $object->project : $object->id;
}
}
else
{
$objectName = $this->dao->select("id, $field AS name")->from($table)->where('id')->in($objectIds)->fetchPairs();
$objectPRJ = array();
$objectName = $this->dao->select("id, $field AS name")->from($table)->where('id')->in($objectIds)->fetchPairs();
$objectProject = array();
}
$objectNames[$objectType] = $objectName;
$objectPRJs[$objectType] = $objectPRJ;
$objectNames[$objectType] = $objectName;
$objectProjects[$objectType] = $objectProject;
}
else
{
@@ -879,7 +886,7 @@ class actionModel extends model
/* Add name field to the actions. */
$action->objectName = isset($objectNames[$action->objectType][$action->objectID]) ? $objectNames[$action->objectType][$action->objectID] : '';
$PRJ = isset($objectPRJs[$action->objectType][$action->objectID]) ? $objectPRJs[$action->objectType][$action->objectID] : 0;
$projectID = isset($objectProjects[$action->objectType][$action->objectID]) ? $objectProjects[$action->objectType][$action->objectID] : 0;
$actionType = strtolower($action->action);
$objectType = strtolower($action->objectType);
@@ -915,7 +922,7 @@ class actionModel extends model
continue;
}
$action->objectLink = helper::createLink($moduleName, $methodName, sprintf($vars, $action->objectID), '', '', $PRJ);
$action->objectLink = helper::createLink($moduleName, $methodName, sprintf($vars, $action->objectID), '', '', $projectID);
$action->objectLabel = $objectLabel;
}
else
@@ -967,9 +974,10 @@ class actionModel extends model
/**
* Print changes of every action.
*
*
* @param string $objectType
* @param array $histories
* @param bool $canChangeTag
* @access public
* @return void
*/
@@ -1078,6 +1086,18 @@ class actionModel extends model
$this->create($action->objectType, $action->objectID, 'undeleted');
}
public function updateUserView($objectType = '')
{
$project = $this->dao->select('id,name,code,acl')->from(TABLE_PROJECT)->where('id')->eq($action->objectID)->fetch();
$count = $this->dao->select('COUNT(*) AS count')->from(TABLE_PROJECT)->where('deleted')->eq('0')->andWhere("(`name`='{$project->name}'" . ($project->code ? " OR `code`='{$project->code}'" : '') . ")")->fetch('count');
if($count > 0 && $objectType == 'execution')
{
echo js::alert(sprintf($this->lang->action->needEdit, $this->lang->action->objectTypes['project']));
die(js::locate(helper::createLink('project', 'edit', "projectID=$action->objectID&action=undelete&extra=$actionID"), 'parent'));
}
if($project->acl != 'open') $this->loadModel('user')->updateUserView($project->id, 'project');
}
/**
* Hide an object.
*
+19
View File
@@ -491,6 +491,25 @@ class projectModel extends model
->fetchPairs('project');
}
/**
* Get products of a project.
*
* @param int $projectID
* @param bool $withBranch
* @access public
* @return array
*/
public function getProducts($projectID, $withBranch = true)
{
$query = $this->dao->select('t2.id, t2.name, t2.type, t1.branch, t1.plan')->from(TABLE_PROJECTPRODUCT)->alias('t1')
->leftJoin(TABLE_PRODUCT)->alias('t2')
->on('t1.product = t2.id')
->where('t1.project')->eq((int)$projectID)
->andWhere('t2.deleted')->eq(0);
if(!$withBranch) return $query->fetchPairs('id', 'name');
return $query->fetchAll('id');
}
/**
* Build the query.
*