From c1d323f12dc7a02de277c45e3f60b5641949a96b Mon Sep 17 00:00:00 2001 From: Conor Keegan Date: Mon, 25 Jul 2016 11:31:23 +0100 Subject: [PATCH 1/2] Added support for updating build custom fields in xmlrpc Added a function which is similar to updating testcase custom fields --- lib/api/xmlrpc/v1/APIErrors.php | 3 + lib/api/xmlrpc/v1/xmlrpc.class.php | 98 ++++++++++++++++++++++++++++++ locale/en_GB/strings.txt | 3 + 3 files changed, 104 insertions(+) diff --git a/lib/api/xmlrpc/v1/APIErrors.php b/lib/api/xmlrpc/v1/APIErrors.php index 69f8311702..bc7980eaa5 100644 --- a/lib/api/xmlrpc/v1/APIErrors.php +++ b/lib/api/xmlrpc/v1/APIErrors.php @@ -312,6 +312,9 @@ define('NO_CUSTOMFIELDS_DT_LINKED_TO_TESTSUITES',9005); define('NO_CUSTOMFIELDS_DT_LINKED_TO_TESTSUITES_STR', lang_get('API_NO_CUSTOMFIELDS_DT_LINKED_TO_TESTSUITES',null,1)); +define('NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS',9006); +define('NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS_STR', lang_get('API_NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS',null,1)); + /** diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index 8d3c9bbdb6..5f82a29d0b 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -7453,6 +7453,103 @@ public function updateTestSuiteCustomFieldDesignValue($args) } } + /** + * Update value of Custom Field with scope='design' + * for a given Build + * + * @param struct $args + * @param string $args["devKey"]: used to check if operation can be done. + * if devKey is not valid => abort. + * + * @param string $args["buildid"]: + * @param string $args["testprojectid"]: + * @param string $args["customfields"] + * contains an map with key:Custom Field Name, value: value for CF. + * VERY IMPORTANT: value must be formatted in the way it's written to db, + * this is important for types like: + * + * DATE: strtotime() + * DATETIME: mktime() + * MULTISELECTION LIST / CHECKBOX / RADIO: se multipli selezione ! come separatore + * + * + * these custom fields must be configured to be writte during execution. + * If custom field do not meet condition value will not be written + * + * @return mixed null if everything ok, else array of IXR_Error objects + * + * @access public + */ + public function updateBuildCustomFieldsValues($args) + { + $msg_prefix="(" .__FUNCTION__ . ") - "; + $this->_setArgs($args); + + $checkFunctions = array('authenticate','checkTestProjectID', 'checkBuildID'); + $status_ok = $this->_runChecks($checkFunctions,$msg_prefix); + + if( $status_ok ) + { + if(!$this->_isParamPresent(self::$customFieldsParamName) ) + { + $status_ok = false; + $msg = sprintf(MISSING_REQUIRED_PARAMETER_STR,self::$customFieldsParamName); + $this->errors[] = new IXR_Error(MISSING_REQUIRED_PARAMETER, $msg); + } + } + + if( $status_ok ) + { + // now check if custom fields are ok + // For each custom field need to check if: + // 1. is linked to test project + // 2. is available for Build at design time + $cfieldMgr = new cfield_mgr($this->dbObj); + + // Just ENABLED + $linkedSet = $cfieldMgr->get_linked_cfields_at_design($this->args[self::$testProjectIDParamName], + cfield_mgr::ENABLED,null,'build',null,'name'); + if( is_null($linkedSet) ) + { + $status_ok = false; + $msg = NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS_STR; + $this->errors[] = new IXR_Error(NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS, $msg); + } + } + + if( $status_ok ) + { + $cfSet = $args[self::$customFieldsParamName]; + foreach($cfSet as $cfName => $cfValue) + { + // $accessKey = "custom_field_" . $item['id'] . _ + // design_values_to_db($hash,$node_id,$cf_map=null,$hash_type=null) + // + // Simple check: if name is not present on set => ignore + if( isset($linkedSet[$cfName]) ) + { + $item = $linkedSet[$cfName]; + $accessKey = "custom_field_" . $item['type'] . '_' . $item['id']; + $hash[$accessKey] = $cfValue; + $cfieldMgr->design_values_to_db($hash,$args[self::$buildIDParamName],null,null,'build'); + $ret[] = array('status' => 'ok' , + 'msg' => 'Custom Field:' . $cfName . ' processed '); + } + else + { + $ret[] = array('status' => 'ko' , + 'msg' => 'Custom Field:' . $cfName . ' skipped '); + } + + return $ret; + } + } + else + { + return $this->errors; + } + } + /** * Returns all test suites inside target * test project with target name @@ -7690,6 +7787,7 @@ function initMethodYellowPages() 'tl.addTestCaseKeywords' => 'this:addTestCaseKeywords', 'tl.removeTestCaseKeywords' => 'this:removeTestCaseKeywords', 'tl.updateTestSuiteCustomFieldDesignValue' => 'this:updateTestSuiteCustomFieldDesignValue', + 'tl.updateBuildCustomFieldsValues' => 'this:updateBuildCustomFieldsValues', 'tl.getTestSuite' => 'this:getTestSuite', 'tl.checkDevKey' => 'this:checkDevKey', 'tl.about' => 'this:about', diff --git a/locale/en_GB/strings.txt b/locale/en_GB/strings.txt index f6944d7eea..3eeefb6211 100644 --- a/locale/en_GB/strings.txt +++ b/locale/en_GB/strings.txt @@ -3469,6 +3469,9 @@ $TLS_API_ATTACH_INVALID_ATTACHMENT = "Invalid attachment info parameters: FILE_N $TLS_API_NO_CUSTOMFIELDS_DT_LINKED_TO_TESTCASES = "There are no custom fields usable at design time linked" . " to test cases on this test project "; +$TLS_API_NO_CUSTOMFIELDS_DT_LINKED_TO_BUILDS = "There are no custom fields usable at design time linked" . + " to builds on this test project "; + $TLS_API_PLATFORMNAME_ALREADY_EXISTS = "Platform name (%s) already exists (id:%s)"; From 80a034e189cd6bff7bf118b7e9293030ba5a24a9 Mon Sep 17 00:00:00 2001 From: Conor Keegan Date: Tue, 9 Aug 2016 14:48:25 +0100 Subject: [PATCH 2/2] Fix for only the first field being processed All fields are processed before the result is returned --- lib/api/xmlrpc/v1/xmlrpc.class.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/api/xmlrpc/v1/xmlrpc.class.php b/lib/api/xmlrpc/v1/xmlrpc.class.php index 5f82a29d0b..f379f901a0 100644 --- a/lib/api/xmlrpc/v1/xmlrpc.class.php +++ b/lib/api/xmlrpc/v1/xmlrpc.class.php @@ -7520,6 +7520,7 @@ public function updateBuildCustomFieldsValues($args) if( $status_ok ) { $cfSet = $args[self::$customFieldsParamName]; + $ret = array(); foreach($cfSet as $cfName => $cfValue) { // $accessKey = "custom_field_" . $item['id'] . _ @@ -7532,17 +7533,18 @@ public function updateBuildCustomFieldsValues($args) $accessKey = "custom_field_" . $item['type'] . '_' . $item['id']; $hash[$accessKey] = $cfValue; $cfieldMgr->design_values_to_db($hash,$args[self::$buildIDParamName],null,null,'build'); - $ret[] = array('status' => 'ok' , - 'msg' => 'Custom Field:' . $cfName . ' processed '); + // Add the result for each custom field to the returned array + array_push($ret, array('status' => 'ok' , + 'msg' => 'Custom Field:' . $cfName . ' processed ')); } else { - $ret[] = array('status' => 'ko' , - 'msg' => 'Custom Field:' . $cfName . ' skipped '); + array_push($ret, array('status' => 'ko' , + 'msg' => 'Custom Field:' . $cfName . ' skipped ')); } - - return $ret; } + // Return the result after all of the fields have been processed + return $ret; } else {