function update($id, $doc_id, $title, $scope, $countReq, $user_id, $type = TL_REQ_SPEC_TYPE_FEATURE, $node_order = null) { $result['status_ok'] = 1; $result['msg'] = 'ok'; $title = trim_and_limit($title); $doc_id = trim_and_limit($doc_id); $path = $this->tree_mgr->get_path($id); $tproject_id = $path[0]['parent_id']; $last_idx = count($path) - 1; $parent_id = $last_idx == 0 ? null : $path[$last_idx]['parent_id']; $chk = $this->check_main_data($title, $doc_id, $path[0]['parent_id'], $parent_id, $id); if ($chk['status_ok']) { /* contribution by asimon83/mx-julian */ if (config_get('internal_links')->enable) { $scope = req_link_replace($this->db, $scope, $tproject_id); } /* end contribution by asimon83/mx-julian */ $db_now = $this->db->db_now(); $sql = " UPDATE {$this->object_table} " . " SET scope='" . $this->db->prepare_string($scope) . "', " . " doc_id='" . $this->db->prepare_string($doc_id) . "', " . " type='" . $this->db->prepare_string($type) . "', " . " total_req ='" . $this->db->prepare_string($countReq) . "', " . " modifier_id={$user_id},modification_ts={$db_now} "; $sql .= "WHERE id={$id}"; if (!$this->db->exec_query($sql)) { $result['msg'] = lang_get('error_updating_reqspec'); $result['status_ok'] = 0; } if ($result['status_ok']) { // need to update node on tree $sql = " UPDATE {$this->tables['nodes_hierarchy']} " . " SET name='" . $this->db->prepare_string($title) . "'"; if (!is_null($node_order)) { $sql .= ",node_order=" . intval($node_order); } $sql .= " WHERE id={$id}"; if (!$this->db->exec_query($sql)) { $result['msg'] = lang_get('error_updating_reqspec'); $result['status_ok'] = 0; } } } else { $result['status_ok'] = $chk['status_ok']; $result['msg'] = $chk['msg']; } return $result; }
function update($item, $options = null) { $result = array('status_ok' => 1, 'msg' => 'ok', 'revision_id' => -1); $my['options'] = array('skip_controls' => false, 'create_rev' => false, 'log_message' => ''); $my['options'] = array_merge($my['options'], (array) $options); $title = trim_and_limit($item['name']); $doc_id = trim_and_limit($item['doc_id']); $path = $this->tree_mgr->get_path($item['id']); $tproject_id = $path[0]['parent_id']; $last_idx = count($path) - 1; $parent_id = $last_idx == 0 ? null : $path[$last_idx]['parent_id']; $chk = $this->check_main_data($title, $doc_id, $path[0]['parent_id'], $parent_id, $item['id']); if ($chk['status_ok'] || $my['options']['skip_controls']) { if (config_get('internal_links')->enable) { $item['scope'] = req_link_replace($this->db, $item['scope'], $tproject_id); } $cnr = null; if ($my['options']['create_rev']) { $cnr = $this->create_new_revision($item['id'], $item + $my['options']); } else { // missing piece, need to update all fields on last revision $cnr = $this->update_revision($item); } $db_now = $this->db->db_now(); $sql = " UPDATE {$this->object_table} " . " SET doc_id='" . $this->db->prepare_string($doc_id) . "' " . " WHERE id={$item['id']}"; if (!$this->db->exec_query($sql)) { $result['msg'] = lang_get('error_updating_reqspec'); $result['status_ok'] = 0; } if ($result['status_ok']) { // need to update node on tree $sql = " UPDATE {$this->tables['nodes_hierarchy']} " . " SET name='" . $this->db->prepare_string($title) . "'"; if (isset($item['node_order']) && !is_null($item['node_order'])) { $sql .= ",node_order=" . intval($item['node_order']); } $sql .= " WHERE id={$item['id']}"; // echo __FUNCTION__ . '::' . $sql . '<br>'; if (!$this->db->exec_query($sql)) { $result['msg'] = lang_get('error_updating_reqspec'); $result['status_ok'] = 0; } } if ($result['status_ok'] && !is_null($cnr)) { $result['revision_id'] = $cnr['id']; } } else { $result['status_ok'] = $chk['status_ok']; $result['msg'] = $chk['msg']; } return $result; }
function update($id, $version_id, $reqdoc_id, $title, $scope, $user_id, $status, $type, $expected_coverage, $node_order = null, $tproject_id = null, $skip_controls = 0) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $result['status_ok'] = 1; $result['msg'] = 'ok'; $db_now = $this->db->db_now(); $field_size = config_get('field_size'); // get SRSid, needed to do controls $rs = $this->get_by_id($id, $version_id); $req = $rs[0]; $srs_id = $req['srs_id']; // try to avoid function calls when data is available on caller $tproject_id = is_null($tproject_id) ? $this->tree_mgr->getTreeRoot($srs_id) : $tproject_id; /* contribution by asimon83/mx-julian */ if (config_get('internal_links')->enable) { $scope = req_link_replace($this->db, $scope, $tproject_id); } /* end contribution by asimon83/mx-julian */ $reqdoc_id = trim_and_limit($reqdoc_id, $field_size->req_docid); $title = trim_and_limit($title, $field_size->req_title); $chk = $this->check_basic_data($srs_id, $tproject_id, $title, $reqdoc_id, $id); if ($chk['status_ok'] || $skip_controls) { $sql = array(); $q = "/* {$debugMsg} */ UPDATE {$this->tables['nodes_hierarchy']} " . " SET name='" . $this->db->prepare_string($title) . "'"; if (!is_null($node_order)) { $q .= ', node_order= ' . abs(intval($node_order)); } $sql[] = $q . " WHERE id={$id}"; $sql[] = "/* {$debugMsg} */ UPDATE {$this->tables['requirements']} " . " SET req_doc_id='" . $this->db->prepare_string($reqdoc_id) . "'" . " WHERE id={$id}"; $sql[] = "/* {$debugMsg} */ UPDATE {$this->tables['req_versions']} " . " SET scope='" . $this->db->prepare_string($scope) . "', " . " status='" . $this->db->prepare_string($status) . "', " . " type='" . $this->db->prepare_string($type) . "', " . " modifier_id={$user_id}, modification_ts={$db_now}, " . " expected_coverage={$expected_coverage} " . " WHERE id={$version_id}"; foreach ($sql as $stm) { $qres = $this->db->exec_query($stm); if (!$qres) { $result['status_ok'] = 0; $result['msg'] = $this->db->error_msg; $result['sql'] = $stm; break; } } } else { $result['status_ok'] = $chk['status_ok']; $result['msg'] = $chk['msg']; } return $result; }
function update($id, $version_id, $reqdoc_id, $title, $scope, $user_id, $status, $type, $expected_coverage, $node_order = null, $tproject_id = null, $skip_controls = 0, $create_revision = false, $log_msg = null) { $debugMsg = 'Class:' . __CLASS__ . ' - Method: ' . __FUNCTION__; $result['status_ok'] = 1; $result['msg'] = 'ok'; $db_now = $this->db->db_now(); // get SRSid, needed to do controls $rs = $this->get_by_id($id, $version_id); $req = $rs[0]; $srs_id = $req['srs_id']; // try to avoid function calls when data is available on caller $tproject_id = is_null($tproject_id) ? $this->tree_mgr->getTreeRoot($srs_id) : $tproject_id; if ($this->internal_links->enable) { $scope = req_link_replace($this->db, $scope, $tproject_id); } $reqdoc_id = trim_and_limit($reqdoc_id, $this->fieldSize->req_docid); $title = trim_and_limit($title, $this->fieldSize->req_title); $chk = $this->check_basic_data($srs_id, $tproject_id, $title, $reqdoc_id, $id); if ($chk['status_ok'] || $skip_controls) { if ($create_revision) { $this->create_new_revision($version_id, $user_id, $tproject_id, $req, $log_msg); } $sql = array(); $q = "/* {$debugMsg} */ UPDATE {$this->tables['nodes_hierarchy']} " . " SET name='" . $this->db->prepare_string($title) . "'"; if (!is_null($node_order)) { $q .= ', node_order= ' . abs(intval($node_order)); } $sql[] = $q . " WHERE id={$id}"; $sql[] = "/* {$debugMsg} */ UPDATE {$this->tables['requirements']} " . " SET req_doc_id='" . $this->db->prepare_string($reqdoc_id) . "'" . " WHERE id={$id}"; $sql_temp = "/* {$debugMsg} */ UPDATE {$this->tables['req_versions']} " . " SET scope='" . $this->db->prepare_string($scope) . "', " . " status='" . $this->db->prepare_string($status) . "', " . " expected_coverage={$expected_coverage}, " . " type='" . $this->db->prepare_string($type) . "' "; // only if no new revision is created set modifier and modification ts // otherwise those values are handled by function create_new_revision() if (!$create_revision) { $sql_temp .= ", modifier_id={$user_id}, modification_ts={$db_now} "; } $sql[] = $sql_temp . " WHERE id={$version_id}"; foreach ($sql as $stm) { $qres = $this->db->exec_query($stm); if (!$qres) { $result['status_ok'] = 0; $result['msg'] = $this->db->error_msg; $result['sql'] = $stm; break; } } } else { $result['status_ok'] = $chk['status_ok']; $result['msg'] = $chk['msg']; } return $result; }