From 51af4491d9c58c760089b14a2f01eed0c6566c81 Mon Sep 17 00:00:00 2001 From: holan20180123 <56391770@qq.com> Date: Wed, 12 May 2021 17:33:59 +0800 Subject: [PATCH] * Return id when create object by API. --- module/task/control.php | 9 +++++++++ module/testcase/control.php | 5 ++++- module/testcase/model.php | 8 ++++++-- module/testreport/control.php | 1 + module/testsuite/control.php | 2 ++ module/testtask/control.php | 2 ++ module/todo/control.php | 7 +++++-- module/todo/model.php | 8 ++++++-- module/tree/control.php | 3 ++- module/tree/model.php | 11 ++++++++--- module/user/control.php | 7 +++++-- module/user/model.php | 11 ++++++++--- module/webhook/control.php | 3 ++- module/webhook/model.php | 2 +- 14 files changed, 61 insertions(+), 18 deletions(-) diff --git a/module/task/control.php b/module/task/control.php index 762703d031..c86f3c476d 100644 --- a/module/task/control.php +++ b/module/task/control.php @@ -131,6 +131,9 @@ class task extends control $this->executeHooks($taskID); + /* Return task id when call the API. */ + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $taskID)); + /* If link from no head then reload. */ if(isonlybody()) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); @@ -284,6 +287,12 @@ class task extends control $mails = $this->task->batchCreate($executionID); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + $taskIDList = array(); + foreach($mails as $mail) $taskIDList[] = $mail->taskID; + + /* Return task id list when call the API. */ + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $taskIDList)); + /* Locate the browser. */ if(!empty($iframe)) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $taskLink)); diff --git a/module/testcase/control.php b/module/testcase/control.php index ee0a1ec24e..c613b0c0a4 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -324,6 +324,7 @@ class testcase extends control $this->executeHooks($caseID); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $caseID)); /* If link from no head then reload. */ if(isonlybody()) $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true)); @@ -473,10 +474,12 @@ class testcase extends control $this->loadModel('story'); if(!empty($_POST)) { - $caseID = $this->testcase->batchCreate($productID, $branch, $storyID); + $caseIDList = $this->testcase->batchCreate($productID, $branch, $storyID); if(dao::isError()) die(js::error(dao::getError())); if(isonlybody()) die(js::closeModal('parent.parent', 'this')); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $caseIDList)); + setcookie('caseModule', 0, 0, $this->config->webRoot, '', $this->config->cookieSecure, false); $currentModule = $this->app->openApp == 'project' ? 'project' : 'testcase'; $currentMethod = $this->app->openApp == 'project' ? 'testcase' : 'browse'; diff --git a/module/testcase/model.php b/module/testcase/model.php index 4d8bc59ec6..f60252da2a 100644 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -97,9 +97,10 @@ class testcaseModel extends model * Batch create cases. * * @param int $productID + * @param int $branch * @param int $storyID * @access public - * @return void + * @return array */ function batchCreate($productID, $branch, $storyID) { @@ -181,6 +182,7 @@ class testcaseModel extends model } } + $caseIDList = array(); foreach($data as $i => $case) { $this->dao->insert(TABLE_CASE)->data($case) @@ -194,7 +196,8 @@ class testcaseModel extends model die(js::reload('parent')); } - $caseID = $this->dao->lastInsertID(); + $caseID = $this->dao->lastInsertID(); + $caseIDList[] = $caseID; /* If the story is linked project, make the case link the project. */ $this->syncCase2Project($case, $caseID); @@ -206,6 +209,7 @@ class testcaseModel extends model if($this->app->openApp == 'execution') $this->action->create('case', $caseID, 'linked2execution', '', $this->session->execution); } if(!dao::isError()) $this->loadModel('score')->create('ajax', 'batchCreate'); + return $caseIDList; } /** diff --git a/module/testreport/control.php b/module/testreport/control.php index c82957a115..e13c21359a 100644 --- a/module/testreport/control.php +++ b/module/testreport/control.php @@ -165,6 +165,7 @@ class testreport extends control $reportID = $this->testreport->create(); if(dao::isError()) die(js::error(dao::getError())); $this->loadModel('action')->create('testreport', $reportID, 'Opened'); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $reportID)); die(js::locate(inlink('view', "reportID=$reportID"), 'parent')); } diff --git a/module/testsuite/control.php b/module/testsuite/control.php index b2e1e312ce..be08277c8a 100644 --- a/module/testsuite/control.php +++ b/module/testsuite/control.php @@ -122,6 +122,8 @@ class testsuite extends control $this->executeHooks($suiteID); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $suiteID)); + $response['locate'] = $this->createLink('testsuite', 'browse', "productID=$productID"); $this->send($response); } diff --git a/module/testtask/control.php b/module/testtask/control.php index 6660051352..5d502fa5cd 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -216,6 +216,8 @@ class testtask extends control $this->loadModel('action')->create('testtask', $taskID, 'opened'); $this->executeHooks($taskID); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $taskID)); + $task = $this->dao->findById($taskID)->from(TABLE_TESTTASK)->fetch(); if($this->app->openApp == 'project') $link = $this->createLink('project', 'testtask', "projectID=$task->project"); if($this->app->openApp == 'execution') $link = $this->createLink('execution', 'testtask', "executionID=$task->execution"); diff --git a/module/todo/control.php b/module/todo/control.php index 732ef0b358..1d3808939d 100644 --- a/module/todo/control.php +++ b/module/todo/control.php @@ -69,7 +69,8 @@ class todo extends control $this->send(array('result' => 'success', 'id' => $todoID, 'name' => $todo->name, 'pri' => $todo->pri, 'priName' => $this->lang->todo->priList[$todo->pri], 'time' => date(DT_DATE4, strtotime($todo->date)) . ' ' . $todo->begin)); } - if($this->app->getViewType() == 'xhtml') die(js::locate($this->createLink('todo', 'view', "todoID=$todoID"), 'parent')); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $todoID)); + if($this->viewType == 'xhtml') die(js::locate($this->createLink('todo', 'view', "todoID=$todoID"), 'parent')); if(isonlybody()) die(js::closeModal('parent.parent')); die(js::locate($this->createLink('my', 'todo', "type=all&userID=&status=all&orderBy=id_desc"), 'parent')); } @@ -96,7 +97,7 @@ class todo extends control if($date == 'today') $date = date(DT_DATE1, time()); if(!empty($_POST)) { - $this->todo->batchCreate(); + $todoIDList = $this->todo->batchCreate(); if(dao::isError()) die(js::error(dao::getError())); /* Locate the browser. */ @@ -109,6 +110,8 @@ class todo extends control { $date= 'today'; } + + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $todoIDList)); if(isonlybody())die(js::reload('parent.parent')); die(js::locate($this->createLink('my', 'todo', "type=$date"), 'parent')); } diff --git a/module/todo/model.php b/module/todo/model.php index d73ef85c02..df64c634f8 100644 --- a/module/todo/model.php +++ b/module/todo/model.php @@ -101,7 +101,7 @@ class todoModel extends model * Create batch todo * * @access public - * @return void + * @return array */ public function batchCreate() { @@ -164,6 +164,7 @@ class todoModel extends model } } + $todoIDList = array(); foreach($validTodos as $todo) { $this->dao->insert(TABLE_TODO)->data($todo)->autoCheck()->exec(); @@ -172,10 +173,13 @@ class todoModel extends model echo js::error(dao::getError()); die(js::reload('parent')); } - $todoID = $this->dao->lastInsertID(); + $todoID = $this->dao->lastInsertID(); + $todoIDList[] = $todoID; $this->loadModel('score')->create('todo', 'create', $todoID); $this->loadModel('action')->create('todo', $todoID, 'opened'); } + + return $todoIDList; } /** diff --git a/module/tree/control.php b/module/tree/control.php index eaf069b278..e02f14bf6c 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -371,8 +371,9 @@ class tree extends control { if(!empty($_POST)) { - $this->tree->manageChild($rootID, $viewType); + $moduleIDList = $this->tree->manageChild($rootID, $viewType); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $moduleIDList)); if($viewType == 'doc' and isonlybody()) die(js::reload('parent.parent')); if(isonlybody()) die(js::closeModal('parent.parent', '', "function(){parent.parent.$('a.refresh').click()}")); diff --git a/module/tree/model.php b/module/tree/model.php index 1042dead60..9bfb5e20c5 100644 --- a/module/tree/model.php +++ b/module/tree/model.php @@ -1542,7 +1542,7 @@ class treeModel extends model * @param int $rootID * @param string $type * @access public - * @return void + * @return array */ public function manageChild($rootID, $type) { @@ -1580,6 +1580,8 @@ class treeModel extends model $parentPath = ','; } $i = 1; + + $moduleIDList = array(); foreach($childs as $moduleID => $moduleName) { if(empty($moduleName)) continue; @@ -1607,8 +1609,9 @@ class treeModel extends model $module->type = $type; $module->order = $order; $this->dao->insert(TABLE_MODULE)->data($module)->exec(); - $moduleID = $this->dao->lastInsertID(); - $childPath = $parentPath . "$moduleID,"; + $moduleID = $this->dao->lastInsertID(); + $moduleIDList[] = $moduleID; + $childPath = $parentPath . "$moduleID,"; $this->dao->update(TABLE_MODULE)->set('path')->eq($childPath)->where('id')->eq($moduleID)->limit(1)->exec(); } else @@ -1619,6 +1622,8 @@ class treeModel extends model $this->dao->update(TABLE_MODULE)->set('name')->eq(strip_tags(trim($moduleName)))->set('short')->eq($short)->set('order')->eq($order)->where('id')->eq($moduleID)->limit(1)->exec(); } } + + return $moduleIDList; } /** diff --git a/module/user/control.php b/module/user/control.php index 04aba479ba..da4a04c6f3 100644 --- a/module/user/control.php +++ b/module/user/control.php @@ -516,9 +516,10 @@ class user extends control $this->send(array('result' => 'fail', 'message' => str_replace('ID ', '', sprintf($this->lang->user->error->reserved, $_POST['account'])))); } - $this->user->create(); + $userID = $this->user->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $userID)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('company', 'browse'))); } @@ -568,7 +569,9 @@ class user extends control if(!empty($_POST)) { - $this->user->batchCreate(); + $userIDList = $this->user->batchCreate(); + + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'idList' => $userIDList)); die(js::locate($this->createLink('company', 'browse'), 'parent')); } diff --git a/module/user/model.php b/module/user/model.php index b21d70430b..aafa1289d0 100644 --- a/module/user/model.php +++ b/module/user/model.php @@ -233,7 +233,7 @@ class userModel extends model * Create a user. * * @access public - * @return void + * @return int */ public function create() { @@ -302,6 +302,8 @@ class userModel extends model $this->loadModel('action')->create('user', $userID, 'Created'); $this->loadModel('mail'); if($this->config->mail->mta == 'sendcloud' and !empty($user->email)) $this->mail->syncSendCloud('sync', $user->email, $user->realname); + + return $usereID; } } @@ -310,7 +312,7 @@ class userModel extends model * * @param int $users * @access public - * @return void + * @return array */ public function batchCreate() { @@ -400,6 +402,7 @@ class userModel extends model } $this->loadModel('mail'); + $userIDList = array(); foreach($data as $user) { if($user->group) @@ -413,7 +416,8 @@ class userModel extends model $this->dao->insert(TABLE_USER)->data($user)->autoCheck()->exec(); /* Fix bug #2941 */ - $userID = $this->dao->lastInsertID(); + $userID = $this->dao->lastInsertID(); + $userIDList[] = $userID; $this->loadModel('action')->create('user', $userID, 'Created'); if(dao::isError()) @@ -427,6 +431,7 @@ class userModel extends model if($this->config->mail->mta == 'sendcloud' and !empty($user->email)) $this->mail->syncSendCloud('sync', $user->email, $user->realname); } } + return $userIDList; } /** diff --git a/module/webhook/control.php b/module/webhook/control.php index df969f3426..0e4762b49c 100644 --- a/module/webhook/control.php +++ b/module/webhook/control.php @@ -62,8 +62,9 @@ class webhook extends control { if($_POST) { - $this->webhook->create(); + $webhookID = $this->webhook->create(); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); + if($this->viewType == 'json') $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $webhookID)); $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => inlink('browse'))); } diff --git a/module/webhook/model.php b/module/webhook/model.php index 306d100d21..d68eae960f 100644 --- a/module/webhook/model.php +++ b/module/webhook/model.php @@ -211,7 +211,7 @@ class webhookModel extends model ->batchCheck($this->config->webhook->create->requiredFields, 'notempty') ->autoCheck() ->exec(); - return !dao::isError(); + return $this->dao->lastInsertId(); } /**