From 9dbb7b14b9f3c2c74dce3887446ff1e750dd7cee Mon Sep 17 00:00:00 2001 From: Conrad Vermeulen Date: Fri, 16 Nov 2007 15:05:29 +0000 Subject: [PATCH] WSA-65 "Remove php5 specific modifiers on functions so that web services works on both 3.4.x and 3.5.x" Updated. The webservice must not have any try/catch handling as this does not parse at all in php4 --- ktwebservice/webservice.php | 71 ++++++++++++++++++++--------------------------------------------------- search2/search/search.inc.php | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 70 insertions(+), 55 deletions(-) diff --git a/ktwebservice/webservice.php b/ktwebservice/webservice.php index e5a7b6b..8f82c04 100644 --- a/ktwebservice/webservice.php +++ b/ktwebservice/webservice.php @@ -3953,65 +3953,34 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $kt); } $response=array( - 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, + 'status_code'=>KTWS_ERR_PROBLEM, 'message'=>'', 'hits'=>array() ); - $noText = (stripos($options,'notext') !== false); - $results = array(); - - try + if (!defined('HAS_SEARCH_FUNCTIONALITY')) { - $expr = parseExpression($query); - - $rs = $expr->evaluate(); - usort($rs, 'rank_compare'); - - $results = array(); - foreach($rs as $hit) - { - $item = array( - 'document_id' => (int) $hit->DocumentID, - 'title' => (string) $hit->Title, - 'relevance' => (float) $hit->Rank, - 'text' => (string) $noText?'':$hit->Text, - 'filesize' => (int) $hit->Filesize, - 'fullpath' => (string) $hit->FullPath, - 'version' => (string) $hit->Version, - 'filename' => (string) $hit->Filename, - 'checked_out_by' => (string) $hit->CheckedOutUser, - 'checked_out_date' => (string) $hit->DateCheckedOut, - 'is_available' => (bool) $hit->IsAvailable, - 'workflow' => (string) $hit->Workflow, - 'workflow_state' => (string) $hit->WorkflowState, - 'folder_id' => (int) $hit->FolderId, - 'mime_type' => (string) $hit->MimeType, - 'modified_by' => (string) $hit->ModifiedBy, - 'modified_date' => (string) $hit->DateModified, - 'created_by' => (string) $hit->CreatedBy, - 'created_date' => (string) $hit->DateCreated, - 'owner' => (string) $hit->Owner, - 'is_immutable'=> (bool) $hit->Immutable, - 'status' => (string) $hit->Status - ); - - $item = new SOAP_Value('item',"{urn:$this->namespace}kt_search_result_item", $item); - $results[] = $item; - - } + $response['message'] = _kt('Search has not been implemented for this version of KnowledgeTree'); + return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $response); + } - $response['message'] = ''; + $results = processSearchExpression($query); + if (PEAR::isError($results)) + { + $response['message'] = _kt('Could not process query.') . $results->getMessage(); + $results = array(); + } + else + { + foreach($results as $key=>$item) + { + $results[$key] = new SOAP_Value('item',"{urn:$this->namespace}kt_search_result_item", $item); + } + $response['message'] = ''; $response['status_code'] = KTWS_SUCCESS; - } - catch(Exception $e) - { - $this->debug("search - exception " . $e->getMessage(), $session_id); - $results = array(); - $response['message'] = _kt('Could not process query.') . $e->getMessage(); - } - $response['hits'] = new SOAP_Value('hits',"{urn:$this->namespace}kt_search_results", $results); + } + $response['hits'] = new SOAP_Value('hits',"{urn:$this->namespace}kt_search_results", $results); return new SOAP_Value('return',"{urn:$this->namespace}kt_search_response", $response); } diff --git a/search2/search/search.inc.php b/search2/search/search.inc.php index 651f817..378a437 100755 --- a/search2/search/search.inc.php +++ b/search2/search/search.inc.php @@ -263,14 +263,14 @@ class SearchHelper public static function getSavedSearches($userID) { - + // need to test for broken db configuration so that the queries dont fail // and so that we can be redirected to the db error page // TODO: maybe best to have a special db error page rather than the default template when logged in - + global $default; if (is_null($default->_db) || PEAR::isError($default->_db)) return array(); - + $sql = "SELECT id, name FROM search_saved WHERE type='S'"; // if we are not the system admin, then we get only ours or shared searches @@ -540,6 +540,52 @@ function parseExpression($expr_str) return $parser->getExprResult(); } - +function processSearchExpression($query) +{ + try + { + $expr = parseExpression($query); + + $rs = $expr->evaluate(); + usort($rs, 'rank_compare'); + + $results = array(); + foreach($rs as $hit) + { + $item = array( + 'document_id' => (int) $hit->DocumentID, + 'title' => (string) $hit->Title, + 'relevance' => (float) $hit->Rank, + 'text' => (string) $noText?'':$hit->Text, + 'filesize' => (int) $hit->Filesize, + 'fullpath' => (string) $hit->FullPath, + 'version' => (string) $hit->Version, + 'filename' => (string) $hit->Filename, + 'checked_out_by' => (string) $hit->CheckedOutUser, + 'checked_out_date' => (string) $hit->DateCheckedOut, + 'is_available' => (bool) $hit->IsAvailable, + 'workflow' => (string) $hit->Workflow, + 'workflow_state' => (string) $hit->WorkflowState, + 'folder_id' => (int) $hit->FolderId, + 'mime_type' => (string) $hit->MimeType, + 'modified_by' => (string) $hit->ModifiedBy, + 'modified_date' => (string) $hit->DateModified, + 'created_by' => (string) $hit->CreatedBy, + 'created_date' => (string) $hit->DateCreated, + 'owner' => (string) $hit->Owner, + 'is_immutable'=> (bool) $hit->Immutable, + 'status' => (string) $hit->Status + ); + + $results[] = $item; + + } + return $results; + } + catch(Exception $e) + { + return new PEAR_Error(_kt('Could not process query.') . $e->getMessage()); + } +} ?> \ No newline at end of file -- libgit2 0.21.4