From 8dc89ab8c7395e7275d52ea504779386f96ca35d Mon Sep 17 00:00:00 2001 From: kevin_fourie Date: Tue, 20 Nov 2007 16:46:15 +0000 Subject: [PATCH] Merged in from DEV trunk... --- bin/scheduler.php | 165 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------- control.php | 4 +++- i18n/knowledgeTree.pot | 28 ++++++++++++++++++++++++++-- ktapi/KTAPIDocument.inc.php | 307 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- ktapi/KTAPIFolder.inc.php | 46 +++++++++++++++++++++++----------------------- ktapi/KTAPISession.inc.php | 30 +++++++++++++++--------------- ktwebdav/lib/KTWebDAVServer.inc.php | 445 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------- ktwebservice/nunit/authentication.cs | 2 +- ktwebservice/nunit/document_add.cs | 63 ++++++++++++++++++++------------------------------------------- ktwebservice/nunit/document_checkout.cs | 46 +++++++++++++++++++++++----------------------- ktwebservice/nunit/document_copy.cs | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ktwebservice/nunit/document_detail.cs | 23 ++++++----------------- ktwebservice/nunit/document_download.cs | 17 +---------------- ktwebservice/nunit/document_history.cs | 14 +------------- ktwebservice/nunit/document_links.cs | 17 +---------------- ktwebservice/nunit/document_metadata.cs | 15 +-------------- ktwebservice/nunit/document_owner.cs | 16 +--------------- ktwebservice/nunit/document_rename.cs | 14 +------------- ktwebservice/nunit/document_system_metadata.cs | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- ktwebservice/nunit/document_type.cs | 14 ++------------ ktwebservice/nunit/document_workflow.cs | 27 ++++++++------------------- ktwebservice/nunit/folder.cs | 14 +++----------- ktwebservice/nunit/helper.cs | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- ktwebservice/nunit/makefile | 13 ++++++++----- ktwebservice/nunit/query.cs | 15 ++++----------- ktwebservice/proxy/proxy.php | 165 --------------------------------------------------------------------------------------------------------------------------------------------------------------------- ktwebservice/webservice.php | 873 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------------------------- lib/browse/browseutil.inc.php | 32 +++++++++++++++++++------------- lib/documentmanagement/documentutil.inc.php | 32 +++++++++++++++++++++++--------- lib/foldermanagement/folderutil.inc.php | 39 ++++++++++++++++++++++----------------- lib/permissions/permissionutil.inc.php | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- lib/session/Session.inc | 2 +- lib/util/ktutil.inc | 4 ++-- lib/workflow/workflowutil.inc.php | 20 ++++++++++---------- login.php | 29 ++++++++++++++++++++++++++--- plugins/housekeeper/HouseKeeperPlugin.php | 11 ++++++++++- plugins/ktcore/admin/managePermissions.php | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------- plugins/rssplugin/loadFeed.inc.php | 18 ++++++++++++------ plugins/rssplugin/rss2array.inc.php | 7 +++---- plugins/search2/ExternalDashlet.php | 2 +- resources/graphics/download.png | Bin 586 -> 0 bytes search2/indexing/bin/optimise.php | 8 ++++++-- search2/indexing/indexerCore.inc.php | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php | 15 +++++++++++++++ search2/search/fields/AnyMetadataField.inc.php | 2 +- search2/search/search.inc.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- sql/mysql/install/data.sql | 7 +++++-- templates/ktcore/login.smarty | 20 ++++++++++++++++---- templates/ktcore/manage_permissions.smarty | 19 ++++++++++++++++++- templates/ktcore/search2/adv_query_builder.smarty | 3 ++- templates/ktcore/search2/lucene_statistics.smarty | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------- 51 files changed, 2304 insertions(+), 1042 deletions(-) create mode 100644 ktwebservice/nunit/document_copy.cs delete mode 100644 ktwebservice/proxy/proxy.php diff --git a/bin/scheduler.php b/bin/scheduler.php index 7c1be67..e51162e 100644 --- a/bin/scheduler.php +++ b/bin/scheduler.php @@ -88,20 +88,20 @@ function calculateRunTime($sFreq, $iTime) { } // Update the task information in the database -function updateTask($sTable, $aFieldValues, $iId) { - DBUtil::autoUpdate($sTable, $aFieldValues, $iId); +function updateTask($aFieldValues, $iId) { + DBUtil::autoUpdate('scheduler_tasks', $aFieldValues, $iId); } // Get the list of tasks due to be run from the database -function getTaskList($sTable) { +function getTaskList() { $now = date('Y-m-d H:i:s'); //time(); - $query = "SELECT * FROM {$sTable} - WHERE is_complete = 0 AND run_time < '{$now}'"; + + $query = "SELECT * FROM scheduler_tasks WHERE is_complete = 0 AND run_time < '{$now}'"; $result = DBUtil::getResultArray($query); if (PEAR::isError($result)){ - exit(); + return false; } return $result; } @@ -109,16 +109,22 @@ function getTaskList($sTable) { /* ** Scheduler script ** */ -$sTable = 'scheduler_tasks'; +global $default; -// Get task list -$aList = getTaskList($sTable); +$default->log->debug('Scheduler: starting'); -global $default; +// Get task list +$aList = getTaskList(); +if (empty($aList)) +{ + $default->log->debug('Scheduler: stopping - nothing to do'); + return; +} // Loop through tasks and run -if(!empty($aList)){ - foreach($aList as $item){ + + foreach($aList as $item) + { $aUpdate = array(); $iEnd = 0; $iStart = 0; $iDuration = 0; $sFreq = ''; $sParameters = ''; @@ -132,64 +138,84 @@ if(!empty($aList)){ $sParameters = $item['script_params']; // Check if script is windows or *nix compatible - $extArr = explode('.', $sTaskUrl); - $ext = array_pop($extArr); - $script = implode('.', $extArr); - if(OS_WINDOWS){ - switch($ext){ - case 'sh': - $sTaskUrl = $script.'.bat'; - break; - case 'bin': - $sTaskUrl = $script.'.exe'; - break; - } - }else{ - switch($ext){ - case 'bat': - if(file_exists(KT_DIR . $script.'.sh')){ - $sTaskUrl = $script.'.sh'; - break; - } - // File doesn't exist - log error - $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script}.sh"); - continue; - break; - case 'exe': - if(file_exists(KT_DIR . $script)){ - $sTaskUrl = $script; - break; - } - if(file_exists(KT_DIR . $script.'.bin')){ - $sTaskUrl = $script.'.bin'; - break; - } - // File doesn't exist - log error - $default->log->error("Scheduler: Task script can't be found at ".KT_DIR."{$script} or ".KT_DIR."{$script}.bin"); - continue; - break; - } + $ext = pathinfo($sTaskUrl, PATHINFO_EXTENSION); + $script = substr($sTaskUrl,0,-strlen($ext)-1); + + if(OS_WINDOWS) + { + $mapping = array('sh'=>'bin','bat'=>'exe'); + if (array_key_exists($ext, $mapping)) + { + $sTaskUrl = $script . '.' . $mapping[$ext]; + } + } + else + { + $mapping = array('bat'=>'sh', 'exe'=>'bin'); + + if (array_key_exists($ext, $mapping)) + { + switch ($ext) + { + case 'exe': + if (is_executable(KT_DIR . '/' . $script)) + { + $sTaskUrl = $script; + break; + } + default: + $sTaskUrl = $script . '.' . $mapping[$ext]; + } + } + + if (!is_executable(KT_DIR . '/' . $script) && $ext != 'php') + { + $default->log->error("Scheduler: The script '{$sTaskUrl}' is not executable."); + continue; + } + } + + $file = realpath(KT_DIR . '/' . $sTaskUrl); + + if ($file === false) + { + $default->log->error("Scheduler: The script '{$sTaskUrl}' cannot be resolved."); + continue; } $iTime = time(); - $iStart = explode(' ', microtime()); + $iStart = KTUtil::getBenchmarkTime(); // Run the script - $file = realpath(KT_DIR . '/' . $sTaskUrl); $cmd = "\"$file\" {$sParameters}"; - $start = KTUtil::getBenchmarkTime(); + if ($ext == 'php') + { + $config = KTConfig::getSingleton(); + $phpPath = $config->get('externalBinary/php'); + + // being protective as some scripts work on relative paths + $dirname = dirname($file); + chdir($dirname); + + $cmd = "$phpPath $cmd"; + } + if (OS_WINDOWS) { $cmd = str_replace( '/','\\',$cmd); - $res = `"$cmd" 2>&1`; + $res = `$cmd`; } else { $res = shell_exec($cmd." 2>&1"); } + // On completion - reset run time + $iEnd = KTUtil::getBenchmarkTime(); + $iDuration = number_format($iEnd - $iStart,2); + if (!empty($res)) { $default->log->info("Scheduler - Task: $sTask"); @@ -199,37 +225,26 @@ if(!empty($aList)){ } else { - $time = number_format(KTUtil::getBenchmarkTime() - $start,2,'.',','); - $default->log->debug("Scheduler - Task: {$sTask} completed in {$diff}s."); + $default->log->debug("Scheduler - Task: {$sTask} completed in {$iDuration}s."); } - - // On completion - reset run time - $iEnd = explode(' ', microtime()); - $iDuration = ($iEnd[1] + $iEnd[0]) - ($iStart[1] + $iStart[0]); - $iDuration = round($iDuration, 3); - - if(($sFreq == 'once' || empty($sFreq)) && $retval !== FALSE){ + if(($sFreq == 'once' || empty($sFreq)) && $retval !== FALSE) + { // Set is_complete to true $aUpdate['is_complete'] = '1'; - }else{ + } + else + { $iNextTime = calculateRunTime($sFreq, $iTime); $aUpdate['run_time'] = date('Y-m-d H:i:s', $iNextTime); } + $aUpdate['previous_run_time'] = date('Y-m-d H:i:s', $iTime); $aUpdate['run_duration'] = $iDuration; - updateTask($sTable, $aUpdate, $item['id']); - - // clear parameters - if(!empty($aParams)){ - foreach($aParams as $param){ - $aParam = explode('=', $param); - $$aParam[0] = ''; - } - $aParam = array(); - $aParams = array(); - } + updateTask($aUpdate, $item['id']); } -} + +$default->log->debug('Scheduler: stopping'); + ?> \ No newline at end of file diff --git a/control.php b/control.php index c2defb6..a51014b 100644 --- a/control.php +++ b/control.php @@ -1,6 +1,6 @@ getMessage()); + session_start(); + $_SESSION['errormessage']['login'] = $ret->getMessage(); } redirect($url); exit(0); diff --git a/i18n/knowledgeTree.pot b/i18n/knowledgeTree.pot index 36c507a..abf5278 100644 --- a/i18n/knowledgeTree.pot +++ b/i18n/knowledgeTree.pot @@ -4062,8 +4062,32 @@ msgstr "" msgid "Error creating allocation" msgstr "" -#: plugins/ktcore/admin/managePermissions.php:76 -msgid "Error creating permission" +#: plugins/ktcore/admin/managePermissions.php:81 +msgid "An error occured while creating your permission" +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:86 +msgid "An error occured while creating your permission: The System Name was not provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:92 +msgid "An error occured while creating your permission: The Display Name was not provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:98 +msgid "An error occured while creating your permission: The Display Name and System Name weren't provided." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:120 +msgid "An error occured while creating your permission: The Display Name and System Name you have provided both already exist." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:129 +msgid "An error occured while creating your permission: A permission with the same System Name already exists." +msgstr "" + +#: plugins/ktcore/admin/managePermissions.php:138 +msgid "An error occured while creating your permission: A permission with the same Display Name already exists." msgstr "" #: plugins/ktcore/admin/managePermissions.php:95 diff --git a/ktapi/KTAPIDocument.inc.php b/ktapi/KTAPIDocument.inc.php index 32a0ceb..3ab4902 100644 --- a/ktapi/KTAPIDocument.inc.php +++ b/ktapi/KTAPIDocument.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -314,13 +314,16 @@ class KTAPI_Document extends KTAPI_FolderItem { continue; } + + + $result[] = array( 'document_id'=>(int)$row['document_id'], 'title'=> $row['title'], 'size'=>(int)$row['size'], - 'workflow'=>$row['workflow'], - 'workflow_state'=>$row['workflow_state'], - 'link_type'=>$row['link_type'], + 'workflow'=>empty($row['workflow'])?'n/a':$row['workflow'], + 'workflow_state'=>empty($row['workflow_state'])?'n/a':$row['workflow_state'], + 'link_type'=>empty($row['link_type'])?'unknown':$row['link_type'], ); } @@ -447,6 +450,7 @@ class KTAPI_Document extends KTAPI_FolderItem * @param string $reason * @param string $newname * @param string $newfilename + * @return KTAPI_Document */ function copy(&$ktapi_target_folder, $reason, $newname=null, $newfilename=null) { @@ -533,12 +537,14 @@ class KTAPI_Document extends KTAPI_FolderItem $oTrigger = new $sTrigger; $aInfo = array( 'document' => $new_document, - 'old_folder' => $this->folder->get_folder(), + 'old_folder' => $this->ktapi_folder->get_folder(), 'new_folder' => $target_folder, ); $oTrigger->setInfo($aInfo); $ret = $oTrigger->postValidate(); } + + return KTAPI_Document::get($this->ktapi, $new_document->getId()); } /** @@ -676,6 +682,10 @@ class KTAPI_Document extends KTAPI_FolderItem } $doctypeid = KTAPI::get_documenttypeid($documenttype); + if (PEAR::isError($doctypeid)) + { + return $doctypeid; + } if ($this->document->getDocumentTypeId() != $doctypeid) { @@ -836,7 +846,7 @@ class KTAPI_Document extends KTAPI_FolderItem } $workflowid=$this->document->getWorkflowId(); - if (!empty($workflowid)) + if (empty($workflowid)) { return new PEAR_Error(KTAPI_ERROR_WORKFLOW_NOT_IN_PROGRESS); } @@ -1045,6 +1055,11 @@ class KTAPI_Document extends KTAPI_FolderItem function update_metadata($metadata) { global $default; + if (empty($metadata)) + { + return; + } + $packed = $this->get_packed_metadata($metadata); DBUtil::startTransaction(); @@ -1079,6 +1094,233 @@ class KTAPI_Document extends KTAPI_FolderItem } + /** + * This updates the system metadata on the document. + * + * @param array $sysdata + */ + function update_sysdata($sysdata) + { + if (empty($sysdata)) + { + return; + } + $owner_mapping = array( + 'created_by'=>'creator_id', + 'modified_by'=>'modified_user_id', + 'owner'=>'owner_id' + ); + + $documents = array(); + $document_content = array(); + + foreach($sysdata as $rec) + { + if (is_object($rec)) + { + $name = $rec->name; + $value = sanitizeForSQL($rec->value); + } + elseif(is_array($rec)) + { + $name = $rec['name']; + $value = sanitizeForSQL($rec['value']); + } + else + { + // just ignore + continue; + } + switch($name) + { + case 'created_date': + $documents['created'] = $value; + break; + case 'modified_date': + $documents['modified'] = $value; + break; + case 'is_immutable': + $documents['immutable'] = in_array(strtolower($value), array('1','true','on','yes'))?'1':'0'; + break; + case 'filename': + $document_content['filename'] = $value; + break; + case 'major_version': + $document_content['major_version'] = $value; + break; + case 'minor_version': + $document_content['minor_version'] = $value; + break; + case 'version': + $version = number_format($value + 0,5); + list($major_version, $minor_version) = explode('.', $version); + $document_content['major_version'] = $major_version; + $document_content['minor_version'] = $minor_version; + break; + case 'mime_type': + $sql = "select id from mime_types where mimetypes='$value'"; + $value = DBUtil::getResultArray($sql); + if (PEAR::isError($value)) + { + return $value; + } + if (count($value) == 0) + { + break; + } + $value = $value[0]['id']; + $document_content['mime_id'] = $value; + break; + case 'owner': + case 'created_by': + case 'modified_by': + $sql = "select id from users where name='$value'"; + $userId = DBUtil::getResultArray($sql); + if (PEAR::isError($userId)) + { + return $userId; + } + if (empty($userId)) + { + $sql = "select id from users where username='$value'"; + $userId = DBUtil::getResultArray($sql); + if (PEAR::isError($userId)) + { + return $userId; + } + } + if (empty($userId)) + { + // if not found, not much we can do + break; + } + $userId=$userId[0]; + $userId=$userId['id']; + + $name = $owner_mapping[$name]; + $documents[$name] = $userId; + break; + default: + // TODO: we should do some logging + //return new PEAR_Error('Unexpected field: ' . $name); + } + } + + if (count($documents) > 0) + { + $sql = "UPDATE documents SET "; + $i=0; + foreach($documents as $name=>$value) + { + if ($i++ > 0) $sql .= ","; + if (is_numeric($value)) + $sql .= "$name=$value"; + else + $sql .= "$name='$value'"; + } + $sql .= " WHERE id=$this->documentid"; + $result = DBUtil::runQuery($sql); + if (PEAR::isError($result)) + { + return $result; + } + } + if (count($document_content) > 0) + { + $content_id = $this->document->getContentVersionId(); + $sql = "UPDATE document_content_version SET "; + $i=0; + foreach($document_content as $name=>$value) + { + if ($i++ > 0) $sql .= ","; + $sql .= "$name='$value'"; + } + $sql .= " WHERE id=$content_id"; + $result = DBUtil::runQuery($sql); + if (PEAR::isError($result)) + { + return $result; + } + } + } + + function clearCache() + { + // TODO: we should only clear the cache for the document we are working on + // this is a quick fix but not optimal!! + + + $metadataid = $this->document->getMetadataVersionId(); + $contentid = $this->document->getContentVersionId(); + + $cache = KTCache::getSingleton(); + + $cache->remove('KTDocumentMetadataVersion/id', $metadataid); + $cache->remove('KTDocumentContentVersion/id', $contentid); + $cache->remove('KTDocumentCore/id', $this->documentid); + $cache->remove('Document/id', $this->documentid); + unset($GLOBALS['_OBJECTCACHE']['KTDocumentMetadataVersion'][$metadataid]); + unset($GLOBALS['_OBJECTCACHE']['KTDocumentContentVersion'][$contentid]); + unset($GLOBALS['_OBJECTCACHE']['KTDocumentCore'][$this->documentid]); + + $this->document = &Document::get($this->documentid); + } + + function mergeWithLastMetadataVersion() + { + // keep latest metadata version + $metadata_version = $this->document->getMetadataVersion(); + if ($metadata_version == 0) + { + // this could theoretically happen in the case we are updating metadata and sysdata, but no metadata fields are specified. + return; + } + + $metadata_id = $this->document->getMetadataVersionId(); + + // get previous version + $sql = "SELECT id, metadata_version FROM document_metadata_version WHERE id<$metadata_id AND document_id=$this->documentid order by id desc"; + $old = DBUtil::getResultArray($sql); + if (is_null($old) || PEAR::isError($old)) + { + return new PEAR_Error('Previous version could not be resolved'); + } + // only interested in the first one + $old=$old[0]; + $old_metadata_id = $old['id']; + $old_metadata_version = $old['metadata_version']; + + DBUtil::startTransaction(); + + // delete previous metadata version + + $sql = "DELETE FROM document_metadata_version WHERE id=$old_metadata_id"; + $rs = DBUtil::runQuery($sql); + if (PEAR::isError($rs)) + { + DBUtil::rollback(); + return $rs; + } + + // make latest equal to previous + $sql = "UPDATE document_metadata_version SET metadata_version=$old_metadata_version WHERE id=$metadata_id"; + $rs = DBUtil::runQuery($sql); + if (PEAR::isError($rs)) + { + DBUtil::rollback(); + return $rs; + } + $sql = "UPDATE documents SET metadata_version=$old_metadata_version WHERE id=$this->documentid"; + $rs = DBUtil::runQuery($sql); + if (PEAR::isError($rs)) + { + DBUtil::rollback(); + return $rs; + } + DBUtil::commit(); + + $this->clearCache(); + } /** * This returns a workflow transition @@ -1156,6 +1398,10 @@ class KTAPI_Document extends KTAPI_FolderItem */ function get_detail() { + global $default; + // make sure we ge tthe latest + $this->clearCache(); + $detail = array(); $document = $this->document; @@ -1191,6 +1437,7 @@ class KTAPI_Document extends KTAPI_FolderItem } $detail['created_by'] = $username; $detail['updated_date'] = $document->getLastModifiedDate(); + $detail['modified_date'] = $document->getLastModifiedDate(); $userid = $document->getModifiedUserId(); if (is_numeric($userid)) @@ -1202,6 +1449,7 @@ class KTAPI_Document extends KTAPI_FolderItem { $username='n/a'; } + $detail['modified_by'] = $username; $detail['updated_by'] = $username; $detail['document_id'] = (int) $document->getId(); $detail['folder_id'] = (int) $document->getFolderID(); @@ -1230,6 +1478,22 @@ class KTAPI_Document extends KTAPI_FolderItem } $detail['workflow_state']=$workflowstate; + $userid = $document->getOwnerID(); + + if (is_numeric($userid)) + { + $user = User::get($userid); + $username=(is_null($user) || PEAR::isError($user))?'* unknown *':$user->getName(); + } + else + { + $username = 'n/a'; + } + $detail['owner'] = $username; + + $detail['is_immutable'] = (bool) $document->getImmutable(); + + $userid = $document->getCheckedOutUserID(); if (is_numeric($userid)) @@ -1241,7 +1505,20 @@ class KTAPI_Document extends KTAPI_FolderItem { $username = 'n/a'; } - $detail['checkout_by'] = $username; + $detail['checked_out_by'] = $username; + + list($major, $minor, $fix) = explode('.', $default->systemVersion); + + + if ($major == 3 && $minor >= 5) + { + $detail['checked_out_date'] = $document->getCheckedOutDate(); + } + else + { + $detail['checked_out_date'] = $detail['modified_date']; + } + if (is_null($detail['checked_out_date'])) $detail['checked_out_date'] = 'n/a'; $detail['full_path'] = $this->ktapi_folder->get_full_path() . '/' . $this->get_title(); diff --git a/ktapi/KTAPIFolder.inc.php b/ktapi/KTAPIFolder.inc.php index 3a07bf0..4984dd8 100644 --- a/ktapi/KTAPIFolder.inc.php +++ b/ktapi/KTAPIFolder.inc.php @@ -61,7 +61,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param int $folderid * @return KTAPI_Folder */ - public static function &get(&$ktapi, $folderid) + function &get(&$ktapi, $folderid) { assert(!is_null($ktapi)); assert(is_a($ktapi, 'KTAPI')); @@ -93,7 +93,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param Folder $folder * @return KTAPI_Folder */ - public function KTAPI_Folder(&$ktapi, &$folder) + function KTAPI_Folder(&$ktapi, &$folder) { $this->ktapi = &$ktapi; $this->folder = &$folder; @@ -106,7 +106,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @access protected * @return Folder */ - public function &get_folder() + function &get_folder() { return $this->folder; } @@ -117,7 +117,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * * @return array */ - public function get_detail() + function get_detail() { $detail = array( 'id'=>(int) $this->folderid, @@ -129,12 +129,12 @@ class KTAPI_Folder extends KTAPI_FolderItem return $detail; } - public function get_parent_folder_id() + function get_parent_folder_id() { return (int) $this->folder->getParentID(); } - public function get_folder_name() + function get_folder_name() { return $this->folder->getFolderName($this->folderid); } @@ -145,12 +145,12 @@ class KTAPI_Folder extends KTAPI_FolderItem * * @return int */ - public function get_folderid() + function get_folderid() { return (int) $this->folderid; } - public static function &_get_folder_by_name($ktapi, $foldername, $folderid) + function &_get_folder_by_name($ktapi, $foldername, $folderid) { $foldername=trim($foldername); if (empty($foldername)) @@ -189,12 +189,12 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $foldername * @return KTAPI_Folder */ - public function &get_folder_by_name($foldername) + function &get_folder_by_name($foldername) { return KTAPI_Folder::_get_folder_by_name($this->ktapi, $foldername, $this->folderid); } - public function get_full_path() + function get_full_path() { $path = $this->folder->getFullPath() . '/' . $this->folder->getName(); @@ -209,7 +209,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $function * @return KTAPI_Document */ - public function &_get_document_by_name($documentname, $function='getByNameAndFolder') + function &_get_document_by_name($documentname, $function='getByNameAndFolder') { $documentname=trim($documentname); if (empty($documentname)) @@ -272,7 +272,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $documentname * @return KTAPI_Document */ - public function &get_document_by_name($documentname) + function &get_document_by_name($documentname) { return $this->_get_document_by_name($documentname,'getByNameAndFolder'); } @@ -284,12 +284,12 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $documentname * @return KTAPI_Document */ - public function &get_document_by_filename($documentname) + function &get_document_by_filename($documentname) { return $this->_get_document_by_name($documentname,'getByFilenameAndFolder'); } - public function _resolve_user($userid) + function _resolve_user($userid) { $user=null; @@ -304,7 +304,7 @@ class KTAPI_Folder extends KTAPI_FolderItem return $user; } - public function get_listing($depth=1, $what='DF') + function get_listing($depth=1, $what='DF') { if ($depth < 1) { @@ -456,7 +456,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $tempfilename This is a reference to the file that is accessible locally on the file system. * @return KTAPI_Document */ - public function &add_document($title, $filename, $documenttype, $tempfilename) + function &add_document($title, $filename, $documenttype, $tempfilename) { if (!is_file($tempfilename)) { @@ -514,7 +514,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param string $foldername * @return KTAPI_Folder */ - public function &add_folder($foldername) + function &add_folder($foldername) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_ADD_FOLDER); @@ -542,7 +542,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * * @param string $reason */ - public function delete($reason) + function delete($reason) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_DELETE); if (PEAR::isError($user)) @@ -571,7 +571,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * * @param string $newname */ - public function rename($newname) + function rename($newname) { $user = $this->can_user_access_object_requiring_permission($this->folder, KTAPI_PERMISSION_RENAME_FOLDER); if (PEAR::isError($user)) @@ -596,7 +596,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param KTAPI_Folder $ktapi_target_folder * @param string $reason */ - public function move($ktapi_target_folder, $reason='') + function move($ktapi_target_folder, $reason='') { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); @@ -628,7 +628,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @param KTAPI_Folder $ktapi_target_folder * @param string $reason */ - public function copy($ktapi_target_folder, $reason='') + function copy($ktapi_target_folder, $reason='') { assert(!is_null($ktapi_target_folder)); assert(is_a($ktapi_target_folder,'KTAPI_Folder')); @@ -661,7 +661,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @access public * @return array */ - public function get_permissions() + function get_permissions() { return new PEAR_Error('TODO'); } @@ -672,7 +672,7 @@ class KTAPI_Folder extends KTAPI_FolderItem * @access public * @return array */ - public function get_transaction_history() + function get_transaction_history() { return new PEAR_Error('TODO'); } diff --git a/ktapi/KTAPISession.inc.php b/ktapi/KTAPISession.inc.php index 358d371..4fafb88 100644 --- a/ktapi/KTAPISession.inc.php +++ b/ktapi/KTAPISession.inc.php @@ -36,7 +36,7 @@ * */ -abstract class KTAPI_Session +class KTAPI_Session { var $ktapi; var $user = null; @@ -45,7 +45,7 @@ abstract class KTAPI_Session var $active; var $origUserId; - public function KTAPI_Session(&$ktapi, &$user) + function KTAPI_Session(&$ktapi, &$user) { assert(!is_null($ktapi)); assert(is_a($ktapi,'KTAPI')); @@ -64,7 +64,7 @@ abstract class KTAPI_Session * * @return string */ - public function get_session() + function get_session() { return $this->session; } @@ -74,7 +74,7 @@ abstract class KTAPI_Session * * @return int */ - public function get_sessionid() + function get_sessionid() { return $this->sessionid; } @@ -84,19 +84,19 @@ abstract class KTAPI_Session * * @return User */ - public function &get_user() + function &get_user() { return $this->user; } - public function logout() + function logout() { $_SESSION['userID'] = $this->origUserId; $this->active=false; // don't need to do anything really } - public function is_active() + function is_active() { return $this->active; } @@ -107,7 +107,7 @@ class KTAPI_UserSession extends KTAPI_Session { var $ip = null; - public function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip) + function KTAPI_UserSession(&$ktapi, &$user, $session, $sessionid, $ip) { parent::KTAPI_Session($ktapi, $user); @@ -133,7 +133,7 @@ class KTAPI_UserSession extends KTAPI_Session * @access private * @return string */ - public function resolveIP() + function resolveIP() { if (getenv("REMOTE_ADDR")) { @@ -163,7 +163,7 @@ class KTAPI_UserSession extends KTAPI_Session * @static * @param User $user */ - private function _check_session(&$user) + function _check_session(&$user) { $user_id = $user->getId(); @@ -218,7 +218,7 @@ class KTAPI_UserSession extends KTAPI_Session * @param string $password * @return KTAPI_Session */ - public function &start_session(&$ktapi, $username, $password, $ip=null) + function &start_session(&$ktapi, $username, $password, $ip=null) { $this->active=false; if ( empty($username) ) @@ -272,7 +272,7 @@ class KTAPI_UserSession extends KTAPI_Session * @param string $ip * @return KTAPI_Session */ - public function &get_active_session(&$ktapi, $session, $ip) + function &get_active_session(&$ktapi, $session, $ip) { $sql = "SELECT id, user_id FROM active_sessions WHERE session_id='$session'"; if (!empty($ip)) @@ -313,7 +313,7 @@ class KTAPI_UserSession extends KTAPI_Session * This closes the current session. * */ - public function logout() + function logout() { $sql = "DELETE FROM active_sessions WHERE id=$this->sessionid"; $result = DBUtil::runQuery($sql); @@ -332,7 +332,7 @@ class KTAPI_UserSession extends KTAPI_Session class KTAPI_AnonymousSession extends KTAPI_UserSession { - public function &start_session(&$ktapi, $ip=null) + function &start_session(&$ktapi, $ip=null) { $user =& User::get(-2); if (is_null($user) || PEAR::isError($user) || ($user === false) || !$user->isAnonymous()) @@ -370,7 +370,7 @@ class KTAPI_AnonymousSession extends KTAPI_UserSession class KTAPI_SystemSession extends KTAPI_Session { - public function KTAPI_SystemSession(&$ktapi, &$user) + function KTAPI_SystemSession(&$ktapi, &$user) { parent::KTAPI_Session($ktapi, $user); $this->active=true; diff --git a/ktwebdav/lib/KTWebDAVServer.inc.php b/ktwebdav/lib/KTWebDAVServer.inc.php index d69513f..3f234db 100644 --- a/ktwebdav/lib/KTWebDAVServer.inc.php +++ b/ktwebdav/lib/KTWebDAVServer.inc.php @@ -1132,9 +1132,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server /** * GET method helper + * Method takes a directory path and checks whether it refers to a document or folder. The relevant folder and/or document id is returned. * - * @param string directory path - * @return array or false + * @param $path string The directory path + * @return array or bool Either returns an array of folder/document id's or false if an error occurred */ function _folderOrDocument($path) { @@ -1142,14 +1143,14 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("Entering _folderOrDocument. path is " . $path, 'info', true); - if ( !(strstr($path,"__BAOBABCLIENT__") === false) ) { - return array(0, 1); - } - + /* ** Get the directory path and the folder/document being acted on ** */ $sFileName = basename($path); // for windows replace backslash with forwardslash $sFolderPath = str_replace("\\", '/', dirname($path) ); + /* ** Get the starting point for recursing through the directory structure + FolderId = 0 if we're in the root folder + FolderId = 1 the starting point for locating any other folder ** */ if ($sFolderPath == "/" || $sFolderPath == "/ktwebdav") { $this->ktwebdavLog("This is the root folder.", 'info', true); $sFolderPath = $this->rootFolder; @@ -1164,6 +1165,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("sFolderName is " . $sFolderPath, 'info', true); $this->ktwebdavLog("iFolderID is " . $iFolderID, 'info', true); + /* ** Break up the directory path into its component directory's, + recurse through the directory's to find the correct id of the current directory. + Avoids situations where several directory's have the same name. ** */ $aFolderNames = split('/', $sFolderPath); $this->ktwebdavLog("aFolderNames are: " . print_r($aFolderNames, true), 'info', true); @@ -1196,6 +1200,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("iFolderID set to " . $iFolderID, 'info', true); } + /* ** Get the document id using the basename and parent folder id as parameters. + If an id is obtained then the path refers to a document. + If no id is returned then the path refers to a folder or a non-existing document. ** */ // FIXME: Direct database access // $sQuery = "SELECT id FROM documents WHERE folder_id = ? AND filename = ? AND status_id = 1"; $sQuery = "SELECT D.id "; @@ -1214,12 +1221,18 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return false; } + /* ** If the path refers to a folder or a non-existing document, + Get the folder id using the basename and parent folder id as parameters. + If an id is obtained then the path refers to an existing folder. + If no id is returned and the basename is empty then path refers to the root folder. + If no id is returned and the basename is not empty, then the path refers to either a non-existing folder or document. ** */ if ($iDocumentID === null) { $this->ktwebdavLog("iDocumentID is null", 'info', true); // FIXME: Direct database access $sQuery = "SELECT id FROM folders WHERE parent_id = ? AND name = ?"; $aParams = array($iFolderID, $sFileName); $id = DBUtil::getOneResultKey(array($sQuery, $aParams), 'id'); + if (PEAR::isError($id)) { $this->ktwebdavLog("A DB(2) error occurred in _folderOrDocument", 'info', true); return false; @@ -1235,6 +1248,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("Setting Location Header to " . "Location: " . $_SERVER["PHP_SELF"] . "/", 'info', true); header("Location: " . $_SERVER["PHP_SELF"] . "/"); } + $this->ktwebdavLog("DEBUG: return id ".$id, 'info', true); return array($id, null); } @@ -1647,24 +1661,16 @@ class KTWebDAVServer extends HTTP_WebDAV_Server /** * MOVE method handler + * Method checks if the source path refers to a document / folder then calls the appropriate method handler. * - * @param array parameter passing array + * @param $options array parameter passing array * @return string HTTP status code or false */ function MOVE($options) { - // Use the WebDAV standards way. - // See rfc2518 Section 8.9 - // This does a copy with delete - // FIXME: This way does not retain document history and other info - - //return $this->COPY($options, true); - - // Use the KT way. - // FIXME: This way does not allow overwrite - $this->ktwebdavLog("Entering MOVE. options are " . print_r($options, true), 'info', true); + /* ** Check that write is allowed ** */ if ($this->checkSafeMode()) { if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet @@ -1679,6 +1685,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server } */ + /* ** Get the path to the document/folder to be copied. + Call function to check if the path refers to a document or a folder. + Return 404 error if the path is invalid. ** */ $source_path = $options["path"]; // Fix for Mac Goliath @@ -1710,22 +1719,30 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return "404 Not found - Document was not found."; } + /* ** Get the returned parent folder id and document/folder id. + If the parent folder id is false, return 404 error. + If the document id is either false or null, then the source is a folder. + If the document id exists then the source is a document. + If the source is a folder then call _MOVEFolder. + If the source is a document then check if its checked out and call _MOVEDocument. ** */ list($iFolderID, $iDocumentID) = $source_res; - if ($iDocumentID === false) { + if ($iFolderID === false && ($iDocumentID === false || is_null($iDocumentID))) { $this->ktwebdavLog("404 Not found - Folder was not found.", 'info', true); return "404 Not found - Folder was not found."; } - if (is_null($iDocumentID)) { + if (is_null($iDocumentID) || $iDocumentID === false) { // Source is a folder + $this->ktwebdavLog("Source is a Folder.", 'info', true); $movestat = $this->_MOVEFolder($options, $iFolderID); } else { // Source is a document + $this->ktwebdavLog("Source is a Document.", 'info', true); if ($this->canCopyMoveRenameDocument($iDocumentID)) { $movestat = $this->_MOVEDocument($options, $iFolderID, $iDocumentID); } else { - return "Cannot MOVE document because it is checked out by another user."; + return "423 Locked - Cannot MOVE document because it is checked out by another user."; } } @@ -1746,7 +1763,9 @@ class KTWebDAVServer extends HTTP_WebDAV_Server */ function _MOVEDocument($options, $iFolderID, $iDocumentID) { + /* ** Ensure that the destination path exists ** */ if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"])); + $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true); // Fix for Mac Goliath // Modified - 25/10/07 - remove ktwebdav from document path @@ -1760,11 +1779,11 @@ class KTWebDAVServer extends HTTP_WebDAV_Server } } - $this->ktwebdavLog("Entering _MOVEDocument. options are " . print_r($options, true), 'info', true); global $default; $new = true; - //FIXME: refactor me into KTDocumentUtil + /* ** Get the relevant paths. Get the basename of the destination path as the destination filename. + Check whether the destination path refers to a folder / document. ** */ $oDocument = Document::get($iDocumentID); $oSrcFolder = Folder::get($iFolderID); $oUser =& User::get($this->userID); @@ -1772,36 +1791,16 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $source_path = $options["path"]; $dest_path = urldecode($options["dest"]); - // Is this a rename? - if (dirname($source_path) == dirname($dest_path)) { - // This is a rename - //if ($options['overwrite'] != 'T') { - // $this->ktwebdavLog("This is a Rename. Overwrite needs to be TRUE.", 'info', true); - // return "412 Precondition Failed - This is a Rename. Overwrite needs to be TRUE."; - //} - $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true); - $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true); - - // Check if the user has permissions to write this document - $oPerm =& KTPermission::getByName('ktcore.permissions.write'); - $oUser =& User::get($this->userID); - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument)) { - return "403 Forbidden - User does not have sufficient permissions"; - } - $res = KTDocumentUtil::rename($oDocument, basename($dest_path), $oUser); - if (PEAR::isError($res) || is_null($res) || ($res === false)) { - return "404 Not Found - " . $res->getMessage(); - } else { - $this->ktwebdavLog("201 Created", 'info', true); - return "201 Created"; - } - - } - + /* ** Get the source folder object. + If the destination document is null, then the destination is a folder, continue. + If the destination document returns an id, then the document exists. Check overwrite. + If overwrite is true, then check permissions and delete the document, continue. + If the destination document is false, then continue. ** */ list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); if (is_null($iDestDoc)) { // the dest is a folder + $this->ktwebdavLog("Destination is a folder.", 'info', true); } else if ($iDestDoc !== false) { // Document exists $this->ktwebdavLog("Destination Document exists.", 'info', true); @@ -1822,6 +1821,39 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $new = false; } + /* ** Check if the source and destination directories are the same and the destination is not a folder. + Then action is probably a rename. + Check if user has permission to write to the document and folder. + Rename the document. ** */ + if ((dirname($source_path) == dirname($dest_path)) && !is_null($iDestDoc)) { + // This is a rename + $this->ktwebdavLog("This is a rename.", 'info', true); + $this->ktwebdavLog("Got an oDocument of " . print_r($oDocument, true), 'info', true); + $this->ktwebdavLog("Got a new name of " . basename($dest_path), 'info', true); + + // Check if the user has permissions to write this document + $oPerm =& KTPermission::getByName('ktcore.permissions.write'); + $oUser =& User::get($this->userID); + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDocument)) { + return "403 Forbidden - User does not have sufficient permissions"; + } + + // Perform rename + $res = KTDocumentUtil::rename($oDocument, basename($dest_path), $oUser); + if (PEAR::isError($res) || is_null($res) || ($res === false)) { + return "404 Not Found - " . $res->getMessage(); + } else if($new) { + $this->ktwebdavLog("201 Created", 'info', true); + return "201 Created"; + }else { + $this->ktwebdavLog("204 No Content", 'info', true); + return "204 No Content"; + } + } + + /* ** Get the destination folder object and the source document object. + Check if user has permission to write to the document and folder. + Move the document. ** */ $oDestFolder = Folder::get($iDestFolder); $this->ktwebdavLog("Got a destination folder of " . print_r($oDestFolder, true), 'info', true); @@ -1832,57 +1864,20 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return "403 Forbidden - User does not have sufficient permissions"; } - $oOriginalFolder = $oSrcFolder; - $iOriginalFolderPermissionObjectId = $oOriginalFolder->getPermissionObjectId(); - $iDocumentPermissionObjectId = $oDocument->getPermissionObjectId(); + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Move."; - if ($iDocumentPermissionObjectId === $iOriginalFolderPermissionObjectId) { - $oDocument->setPermissionObjectId($oDestFolder->getPermissionObjectId()); - } + $res = KTDocumentUtil::move($oDocument, $oDestFolder, $oUser, $reason); - //put the document in the new folder - $oDocument->setFolderID($oDestFolder->getId()); - if (!$oDocument->update(true)) { - return "502 Bad Gateway - Document update failed."; - } - - //move the document on the file system - $oStorage =& KTStorageManagerUtil::getSingleton(); - if (!$oStorage->moveDocument($oDocument, $oSrcFolder, $oDestFolder)) { - $oDocument->setFolderID($oSrcDocumentFolder->getId()); - $oDocument->update(true); - return "502 Bad Gateway"; - } - - $sMoveMessage = sprintf("Moved from %s/%s to %s/%s: %s", - $oSrcFolder->getFullPath(), - $oSrcFolder->getName(), - $oDestFolder->getFullPath(), - $oDestFolder->getName(), - $_SERVER['HTTP_REASON']); - - // create the document transaction record - $oDocumentTransaction = & new DocumentTransaction($oDocument, $sMoveMessage, 'ktcore.transactions.move'); - $oDocumentTransaction->create(); - - $oKTTriggerRegistry = KTTriggerRegistry::getSingleton(); - $aTriggers = $oKTTriggerRegistry->getTriggers('moveDocument', 'postValidate'); - foreach ($aTriggers as $aTrigger) { - $sTrigger = $aTrigger[0]; - $oTrigger = new $sTrigger; - $aInfo = array( - "document" => $oDocument, - "old_folder" => $oSrcFolder, - "new_folder" => $oDestFolder, - ); - $oTrigger->setInfo($aInfo); - $ret = $oTrigger->postValidate(); - // FIXME: handle trigger subfailures. + if(PEAR::isError($res)){ + $this->ktwebdavLog("Move on document failed: ".$res->getMessage(), 'info', true); + return "500 Internal Server Error - Move on document failed."; } if ($new) { + $this->ktwebdavLog("201 Created", 'info', true); return "201 Created"; } else { + $this->ktwebdavLog("204 No Content", 'info', true); return "204 No Content"; } } @@ -1897,11 +1892,13 @@ class KTWebDAVServer extends HTTP_WebDAV_Server */ function _MOVEFolder($options, $iFolderID) { + /* ** Ensure that the destination path exists ** */ if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"])); $this->ktwebdavLog("Entering _MOVEFolder. options are " . print_r($options, true), 'info', true); + /* ** RFC 2518 Section 8.9.2. A folder move must have a depth of 'infinity'. + Check the requested depth. If depth is set to '0' or '1' return a 400 error. ** */ if ($options["depth"] != "infinity") { - // RFC 2518 Section 9.2, last paragraph $this->ktwebdavLog("400 Bad request", 'info', true); return "400 Bad request - depth must be 'inifinity'."; } @@ -1920,23 +1917,75 @@ class KTWebDAVServer extends HTTP_WebDAV_Server global $default; + /* ** Get the relevant paths. + Check whether the destination path refers to a folder / document. ** */ $source_path = $options["path"]; $dest_path = urldecode($options["dest"]); + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + /* ** Get the source folder objects. + If the destination document is null, then the destination is an existing folder. Check overwrite. + If overwrite is true, then check permissions and delete the folder, continue. + If the destination document returns an id, then the destination is a document, check overwrite. + If overwrite is true, then check permissions and delete the document, continue. + If the destination document is false, then continue. ** */ $oSrcFolder = Folder::get($iFolderID); + $oDestFolder = Folder::get($iDestFolder); - list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + $new = true; + if (is_null($iDestDoc)) { + // Folder exists + $this->ktwebdavLog("Destination Folder exists.", 'info', true); + $oReplaceFolder = $oDestFolder; + if ($options['overwrite'] != 'T') { + $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true); + return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE."; + } + $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true); - $oDestFolder = Folder::get($iDestFolder); + // Check if the user has permissions to delete this folder + $oPerm =& KTPermission::getByName('ktcore.permissions.delete'); + $oUser =& User::get($this->userID); - // Is this a rename? - if (dirname($source_path) == dirname($dest_path)) { - // This is a rename - //if ($options['overwrite'] != 'T') { - // $this->ktwebdavLog("This is a Rename. Overwrite needs to be TRUE.", 'info', true); - // return "412 Precondition Failed - This is a Rename. Overwrite needs to be TRUE."; - //} + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) { + return "403 Forbidden - User does not have sufficient permissions"; + } + + KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.'); + + // Destination folder has been replaced so we need to get the parent folder object + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + $oDestFolder = Folder::get($iDestFolder); + + $new = false; + } else if ($iDestDoc !== false) { + // Destination is a document + $this->ktwebdavLog("Destination is a document.", 'info', true); + $oReplaceDoc = Document::get($iDestDoc); + if ($options['overwrite'] != 'T') { + $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true); + return "412 Precondition Failed - Destination Folder is a document. Overwrite needs to be TRUE."; + } + $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Document.", 'info', true); + + // Check if the user has permissions to delete this document + $oPerm =& KTPermission::getByName('ktcore.permissions.delete'); + $oUser =& User::get($this->userID); + + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceDoc)) { + return "403 Forbidden - User does not have sufficient permissions"; + } + KTDocumentUtil::delete($oReplaceDoc, 'KTWebDAV move overwrites target.'); + $new = false; + } + /* ** Check if the source and destination directories are the same and the destination is not an existing folder. + Then action is probably a rename. + Check if user has permission to write to the folder. + Rename the document. ** */ + if (dirname($source_path) == dirname($dest_path) && !is_null($iDestDoc)) { + // This is a rename + $this->ktwebdavLog("Rename collection.", 'info', true); $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true); $this->ktwebdavLog("Got an new name of " . basename($dest_path), 'info', true); @@ -1952,36 +2001,22 @@ class KTWebDAVServer extends HTTP_WebDAV_Server if (PEAR::isError($res) || is_null($res) || ($res === false)) { return "404 Not Found - " . $res->getMessage(); } else { - $this->ktwebdavLog("201 Created", 'info', true); - return "201 Created"; - } - - } - - if (is_null($iDestDoc)) { - // the dest is a folder - } else if ($iDestDoc !== false) { - // Folder exists - $this->ktwebdavLog("Destination Folder exists.", 'info', true); - $oReplaceFolder = Folder::get($iDestDoc); - if ($options['overwrite'] != 'T') { - $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true); - return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE."; + if($new){ + $this->ktwebdavLog("201 Created", 'info', true); + return "201 Created"; + }else{ + $this->ktwebdavLog("204 No Content", 'info', true); + return "204 No Content"; + } } - $this->ktwebdavLog("Overwrite is TRUE, deleting Destination Folder.", 'info', true); - // Check if the user has permissions to delete this folder - $oPerm =& KTPermission::getByName('ktcore.permissions.delete'); - $oUser =& User::get($this->userID); - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) { - return "403 Forbidden - User does not have sufficient permissions"; - } - KTFolderUtil::delete($oReplaceFolder, 'KTWebDAV move overwrites target.'); - $new = false; } include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'); + /* ** Get the destination folder object and the source document object. + Check if user has permission to write to the folder. + Move the folder. ** */ $oUser =& User::get($this->userID); $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true); $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true); @@ -1993,18 +2028,29 @@ class KTWebDAVServer extends HTTP_WebDAV_Server if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) { return "403 Forbidden - User does not have sufficient permissions"; } - KTFolderUtil::move($oSrcFolder, $oDestFolder, $oUser); - $this->ktwebdavLog("201 Created", 'info', true); - return "201 Created"; + $res = KTFolderUtil::move($oSrcFolder, $oDestFolder, $oUser); + + if(PEAR::isError($res)){ + $this->ktwebdavLog("Move on folder failed: ".$res->getMessage(), 'info', true); + return "500 Internal Server Error - Move on folder failed."; + } + if($new){ + $this->ktwebdavLog("201 Created", 'info', true); + return "201 Created"; + }else{ + $this->ktwebdavLog("204 No Content", 'info', true); + return "204 No Content"; + } } /** * COPY method handler + * Method checks if the source path refers to a document / folder then calls the appropriate method handler. * - * @param array parameter passing array - * @param string delete source flag + * @param $options array parameter passing array + * @param $del string delete source flag * @return string HTTP status code or false */ function COPY($options, $del = false) @@ -2012,6 +2058,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("Entering COPY. options are " . print_r($options, true), 'info', true); $this->ktwebdavLog("del is: " . $del, 'info', true); + /* ** Check that writing to the server is allowed * **/ if ($this->checkSafeMode()) { if (!empty($_SERVER["CONTENT_LENGTH"])) { // no body parsing yet @@ -2025,6 +2072,10 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return "502 bad gateway - No copying to different WebDAV Servers yet"; } */ + + /* ** Get the path to the document/folder to be copied. + Call function to check if the path refers to a document or a folder. + Return 404 error if the path is invalid. ** */ $source_path = $options["path"]; $this->ktwebdavLog("SourcePath is: " . $source_path, 'info', true); $source_res = $this->_folderOrDocument($source_path); @@ -2033,13 +2084,19 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return "404 Not found - The document could not be found."; } + /* ** Get the returned parent folder id and document/folder id. + If the parent folder id is false, return 404 error. + If the document id is either false or null, then the source is a folder. + If the document id exists then the source is a document. + If the source is a folder then call _COPYFolder. + If the source is a document then check if its checked out and call _COPYDocument. ** */ list($iFolderID, $iDocumentID) = $source_res; - if ($iDocumentID === false) { + if ($iFolderID === false && ($iDocumentID === false || is_null($iDocumentID))) { $this->ktwebdavLog("404 Not found - The folder could not be found.", 'info', true); return "404 Not found - The folder could not be found."; } - if (is_null($iDocumentID)) { + if (is_null($iDocumentID) || $iDocumentID === false) { // Source is a folder $this->ktwebdavLog("Source is a Folder.", 'info', true); $copystat = $this->_COPYFolder($options, $iFolderID); @@ -2049,13 +2106,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $this->ktwebdavLog("Source is a Document.", 'info', true); if ($this->canCopyMoveRenameDocument($iDocumentID)) { - $copystat = $this->_COPYDocument($options, $iFolderID, $iDocumentID, $dest_folder_id); + $copystat = $this->_COPYDocument($options, $iFolderID, $iDocumentID); } else { - return "Cannot COPY document because it is checked out by another user."; + // Document is locked + return "423 Locked - Cannot COPY document because it is checked out by another user."; } } + /* ** Deprecated. If the request is a move then delete the source ** // Delete the source if this is a move and the copy was ok if ($del && ($copystat{0} == "2")) { $delstat = $this->DELETE(array("path" => $options["path"])); @@ -2064,6 +2123,7 @@ class KTWebDAVServer extends HTTP_WebDAV_Server return $delstat; } } + */ $this->ktwebdavLog("Final copystat result is: " . $copystat, 'info', true); return $copystat; @@ -2074,16 +2134,30 @@ class KTWebDAVServer extends HTTP_WebDAV_Server /** * COPY method helper for Documents * - * @param array parameter passing array - * @param int Folder ID - * @param int Document ID + * @param $options array parameter passing array + * @param $iFolderID int Folder ID + * @param $iDocumentID int Document ID * @return string HTTP status code or false */ function _COPYDocument($options, $iFolderID, $iDocumentID) { + /* ** Ensure that the destination path exists ** */ if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"])); $this->ktwebdavLog("Entering _COPYDocument. options are " . print_r($options, true), 'info', true); + /* ** Get the relevant paths. Get the basename of the destination path as the destination filename. + Check whether the destination path refers to a folder / document. ** */ + $source_path = $options["path"]; + $dest_path = urldecode($options["dest"]); + $sDestFileName = basename($dest_path); + + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + + if($iDestFolder === false){ + return "409 Conflict - Destination folder does not exist."; + } + + /* ** Depth must be infinity to copy a document ** */ if ($options["depth"] != "infinity") { // RFC 2518 Section 9.2, last paragraph $this->ktwebdavLog("400 Bad request", 'info', true); @@ -2092,17 +2166,20 @@ class KTWebDAVServer extends HTTP_WebDAV_Server global $default; - $source_path = $options["path"]; - $dest_path = urldecode($options["dest"]); - + /* ** Get the source folder object. + If the destination document is null, then the destination is a folder, set the destination filename to empty, continue. + If the destination document returns an id, then the document exists. Check overwrite. + If overwrite is true, then check permissions and delete the document, continue. + If the destination document is false, then continue. ** */ $oSrcFolder = Folder::get($iFolderID); - list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); - + $new = true; if (is_null($iDestDoc)) { // the dest is a folder // $this->ktwebdavLog("400 Bad request", 'info', true); - return "400 Bad request - Destination is a Folder"; + $this->ktwebdavLog("Destination is a folder.", 'info', true); + $sDestFileName = ''; + //return "400 Bad request - Destination is a Folder"; } else if ($iDestDoc !== false) { // Document exists $this->ktwebdavLog("Destination Document exists.", 'info', true); @@ -2123,25 +2200,33 @@ class KTWebDAVServer extends HTTP_WebDAV_Server $new = false; } + /* ** Get the destination folder object and the source document object. + Check if user has permission to write to the document and folder. + Copy the document. ** */ $oDestFolder = Folder::get($iDestFolder); $oSrcDoc = Document::get($iDocumentID); include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'); - $this->ktwebdavLog("Got an oSrcDoc of " . print_r($oSrcDoc, true), 'info', true); - $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true); + $this->ktwebdavLog("Got an oSrcDoc of " .$oSrcDoc->getName() . print_r($oSrcDoc, true), 'info', true); + $this->ktwebdavLog("Got an oDestFolder of " .$oDestFolder->getName() . print_r($oDestFolder, true), 'info', true); // Check if the user has permissions to write in this folder $oPerm =& KTPermission::getByName('ktcore.permissions.write'); $oUser =& User::get($this->userID); - if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oSrcDoc)) { + if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) { return "403 Forbidden - User does not have sufficient permissions"; } - KTDocumentUtil::copy($oSrcDoc, $oDestFolder, $_SERVER['HTTP_REASON']); - // FIXME: Do failure checking here + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy."; + + $oDesDoc = KTDocumentUtil::copy($oSrcDoc, $oDestFolder, $reason, $sDestFileName); + + if(PEAR::isError($oDesDoc)){ + $this->ktwebdavLog("Copy on document failed: ".$oDesDoc->getMessage(), 'info', true); + return "500 Internal Server Error - Copy on document failed."; + } - $new = false; if ($new) { $this->ktwebdavLog("201 Created", 'info', true); return "201 Created"; @@ -2160,37 +2245,52 @@ class KTWebDAVServer extends HTTP_WebDAV_Server */ function _COPYFolder($options, $iFolderID) { + /* ** Ensure that the destination path exists ** */ if ($options['dest'] == '') $options["dest"] = substr($options["dest_url"], strlen($_SERVER["SCRIPT_NAME"])); $this->ktwebdavLog("Entering _COPYFolder. options are " . print_r($options, true), 'info', true); + /* ** RFC 2518 Section 8.8.3. DAV compliant servers must support depth headers of '0' and 'infinity'. + Check the requested depth. If depth is set to '0', set copyall to false. A depth of 0 indicates + that the folder is copied without any children. If depth is set to '1', return a 400 error. ** */ + $copyAll = true; if ($options["depth"] != "infinity") { - // RFC 2518 Section 9.2, last paragraph - $this->ktwebdavLog("400 Bad request", 'info', true); - return "400 Bad request - Depth must be 'infinity'."; + if($options['depth'] == '0'){ + $copyAll = false; + $this->ktwebdavLog("Depth is 0. Copy only the base folder.", 'info', true); + }else{ + $this->ktwebdavLog("400 Bad request. Depth must be infinity or 0.", 'info', true); + return "400 Bad request - Depth must be 'infinity' or '0'."; + } } global $default; $new = true; + /* ** Get the relevant paths. Get the basename of the destination path as the destination path name. + Check whether the destination path refers to a folder / document. ** */ $source_path = $options["path"]; $dest_path = urldecode($options["dest"]); - - $oSrcFolder = Folder::get($iFolderID); + $sDestPathName = basename($dest_path); list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + /* ** Get the source and destination folder objects. + If the destination document is null, then the destination is an existing folder. Check overwrite. + If overwrite is true, then check permissions and delete the folder, continue. + If the destination document returns an id, then the destination is a document, return 409 error. + If the destination document is false, then continue. ** */ + $oSrcFolder = Folder::get($iFolderID); $oDestFolder = Folder::get($iDestFolder); include_once(KT_LIB_DIR . '/foldermanagement/folderutil.inc.php'); - if (is_null($iDestDoc)) { - // the dest is a folder - $this->ktwebdavLog("The Destination is a Folder.", 'info', true); - } else if ($iDestDoc !== false) { - // Folder exists + if(is_null($iDestDoc)) { + // Destination is a folder and exists + //$sDestPathName = ''; $this->ktwebdavLog("Destination Folder exists.", 'info', true); - $oReplaceFolder = Folder::get($iDestDoc); + + $oReplaceFolder = $oDestFolder; if ($options['overwrite'] != 'T') { $this->ktwebdavLog("Overwrite needs to be TRUE.", 'info', true); return "412 Precondition Failed - Destination Folder exists. Overwrite needs to be TRUE."; @@ -2203,10 +2303,21 @@ class KTWebDAVServer extends HTTP_WebDAV_Server if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oReplaceFolder)) { return "403 Forbidden - User does not have sufficient permissions"; } - KTFolderUtil::delete($oReplaceFolder, 'KTWebDAV move overwrites target.'); + KTFolderUtil::delete($oReplaceFolder, $oUser, 'KTWebDAV move overwrites target.'); + + // Destination folder has been deleted - get new object of destination parent folder + list($iDestFolder, $iDestDoc) = $this->_folderOrDocument($dest_path); + $oDestFolder = Folder::get($iDestFolder); + $new = false; + } else if ($iDestDoc !== false) { + // Destination is a document + return "409 Conflict - Can't write a collection to a document"; } + /* ** Get the destination folder object and the source document object. + Check if user has permission to write to the folder. + Copy the document. Pass parameters for the destination folder name and the depth of copy. ** */ $oUser =& User::get($this->userID); $this->ktwebdavLog("Got an oSrcFolder of " . print_r($oSrcFolder, true), 'info', true); $this->ktwebdavLog("Got an oDestFolder of " . print_r($oDestFolder, true), 'info', true); @@ -2218,7 +2329,15 @@ class KTWebDAVServer extends HTTP_WebDAV_Server if (!KTPermissionUtil::userHasPermissionOnItem($oUser, $oPerm, $oDestFolder)) { return "403 Forbidden - User does not have sufficient permissions"; } - KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, 'KTWebDAV Copy.'); + + $reason = (isset($_SERVER['HTTP_REASON']) && !empty($_SERVER['HTTP_REASON'])) ? $_SERVER['HTTP_REASON'] : "KTWebDAV Copy."; + + $res = KTFolderUtil::copy($oSrcFolder, $oDestFolder, $oUser, $reason, $sDestPathName, $copyAll); + + if(PEAR::isError($res)){ + $this->ktwebdavLog("Copy on folder failed: ".$res->getMessage(), 'info', true); + return "500 Internal Server Error - Copy on folder failed."; + } if ($new) { $this->ktwebdavLog("201 Created", 'info', true); diff --git a/ktwebservice/nunit/authentication.cs b/ktwebservice/nunit/authentication.cs index 043ecfe..11dd635 100644 --- a/ktwebservice/nunit/authentication.cs +++ b/ktwebservice/nunit/authentication.cs @@ -14,7 +14,7 @@ namespace MonoTests.KnowledgeTree [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); + this._kt = new KTWebService(); } [TearDown] diff --git a/ktwebservice/nunit/document_add.cs b/ktwebservice/nunit/document_add.cs index 662b0fd..418da26 100644 --- a/ktwebservice/nunit/document_add.cs +++ b/ktwebservice/nunit/document_add.cs @@ -5,55 +5,34 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class AddDocumentTest + public class AddDocumentTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; + private int _docId; private int _folderId; private String _filename; - private String _content; - private bool _verbose; - - public AddDocumentTest() - { - - this._verbose = true; + private String _content; + public AddDocumentTest() : base() + { this._folderId = 1; - } - + } [SetUp] public void SetUp() - { - this._kt = new KnowledgeTreeService(); - //this._kt.Url = "http://ktdms.trunk/ktwebservice/webservice.php"; - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - + { this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; this._content = "hello world!"; - Helper.writeFile(this._filename, this._content); - - - } + Helper.writeFile(this._filename, this._content); } [TearDown] public void TearDown() - { - - Helper.deleteFile(this._filename); - - - this._kt.logout(this._session); - } - - - - + { + Helper.deleteFile(this._filename); + } + [Test] public void FindDocumentBeforeAdd() { @@ -70,8 +49,7 @@ namespace MonoTests.KnowledgeTree { System.Console.WriteLine("document not found. that is ok!"); } - } - + } [Test] public void FindFolderBeforeAdd() @@ -89,8 +67,7 @@ namespace MonoTests.KnowledgeTree { if (this._verbose) System.Console.WriteLine("folder not found. that is ok!"); } - } - + } [Test] public void AddDocument() @@ -121,9 +98,9 @@ namespace MonoTests.KnowledgeTree Assert.AreEqual("Administrator", response1.created_by); //Assert.IsTrue(response1.updated_date == null); - Assert.IsTrue("" != response1.updated_date); + Assert.IsTrue("" != response1.modified_date); - Assert.AreEqual("Administrator", response1.updated_by); + Assert.AreEqual("Administrator", response1.modified_by); Assert.IsTrue(response1.document_id > 0); @@ -185,7 +162,7 @@ namespace MonoTests.KnowledgeTree String filename = "kt unit test31"; if (this._verbose) System.Console.WriteLine("Adding document : " + filename); - FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php"); + FileUploader uploader = new FileUploader(); uploader.upload(this._session, this._filename); String tempname = uploader.getFilename(); @@ -203,10 +180,10 @@ namespace MonoTests.KnowledgeTree Assert.AreEqual("Administrator", response1.created_by); - //Assert.IsTrue(response1.updated_date == null); - Assert.IsTrue("" != response1.updated_date); + //Assert.IsTrue(response1.modified_date == null); + Assert.IsTrue("" != response1.modified_date); - Assert.AreEqual("Administrator", response1.updated_by); + Assert.AreEqual("Administrator", response1.modified_by); Assert.IsTrue(response1.document_id > 0); diff --git a/ktwebservice/nunit/document_checkout.cs b/ktwebservice/nunit/document_checkout.cs index 2816cca..da1ec79 100644 --- a/ktwebservice/nunit/document_checkout.cs +++ b/ktwebservice/nunit/document_checkout.cs @@ -5,24 +5,18 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class CheckoutDocumentTest - { - private String _session; - private KnowledgeTreeService _kt; + public class CheckoutDocumentTest : KTTest + { private int _docId; private int _folderId; private String _filename; - private String _content; - private bool _verbose; + private String _content; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - + this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; String filename = "kt unit test1"; @@ -31,7 +25,7 @@ namespace MonoTests.KnowledgeTree Helper.writeFile(this._filename, this._content); - this._verbose = false; + this._folderId = 1; @@ -56,9 +50,7 @@ namespace MonoTests.KnowledgeTree if (this._verbose && response.status_code != 0) { System.Console.WriteLine("Could not delete file: " + this._filename); - } - - this._kt.logout(this._session); + } } @@ -69,12 +61,15 @@ namespace MonoTests.KnowledgeTree if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); - kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false); + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then undo", false); Assert.AreEqual(0, response.status_code); - + Assert.AreEqual("Administrator",response.checked_out_by); + Assert.IsTrue(null != response.checked_out_date); response = this._kt.undo_document_checkout(this._session, this._docId, "unit test - doing undo"); Assert.AreEqual(0, response.status_code); + Assert.AreEqual("n/a",response.checked_out_by); + Assert.AreEqual("n/a", response.checked_out_date); } [Test] @@ -84,14 +79,16 @@ namespace MonoTests.KnowledgeTree if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); - kt_response response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); + kt_document_detail response = this._kt.checkout_base64_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); Assert.AreEqual(0, response.status_code); + Assert.AreEqual("Administrator",response.checked_out_by); + Assert.IsTrue(null != response.checked_out_date); kt_document_detail checkin = this._kt.checkin_base64_document(this._session, this._docId, filename, "unit test - doing checkin", Helper.ConvertFileToBase64Encoding(this._filename), false); Assert.AreEqual(0, checkin.status_code); - - //assert - check data checkout + Assert.AreEqual("n/a",checkin.checked_out_by); + Assert.AreEqual("n/a", checkin.checked_out_date); } [Test] @@ -101,17 +98,20 @@ namespace MonoTests.KnowledgeTree if (this._verbose) System.Console.WriteLine("Checking out document : " + filename); - kt_response response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); + kt_document_detail response = this._kt.checkout_document(this._session, this._docId, "unit test - going to checkout and then checkin", false); Assert.AreEqual(0, response.status_code); + Assert.AreEqual("Administrator",response.checked_out_by); + Assert.IsTrue(null != response.checked_out_date); - - FileUploader uploader = new FileUploader("http://ktdms.trunk/ktwebservice/upload.php"); + FileUploader uploader = new FileUploader(); uploader.upload(this._session, this._filename); String tempname = uploader.getFilename(); kt_document_detail checkin = this._kt.checkin_document(this._session, this._docId, filename, "unit test - doing checkin", tempname, false); - Assert.AreEqual(0, checkin.status_code); + Assert.AreEqual(0, checkin.status_code); + Assert.AreEqual("n/a",checkin.checked_out_by); + Assert.AreEqual("n/a", checkin.checked_out_date); } diff --git a/ktwebservice/nunit/document_copy.cs b/ktwebservice/nunit/document_copy.cs new file mode 100644 index 0000000..0aecd0f --- /dev/null +++ b/ktwebservice/nunit/document_copy.cs @@ -0,0 +1,82 @@ +using NUnit.Framework; +using System; +using System.IO; + +namespace MonoTests.KnowledgeTree +{ + + + [TestFixture] + public class DocumentCopyTest : KTTest + { + private int _folderId; + private Document _doc1; + + + [SetUp] + public void SetUp() + { + this._folderId = 1; + + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); + this._doc1.createFile(this._folderId); + + + + } + + [TearDown] + public void TearDown() + { + this._doc1.deleteFile(); + } + + [Test] + public void FindDocumentBeforeCopy() + { + String filename = "Root Folder/test123"; + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename); + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, ""); + if (0 == documentDetail.status_code) + { + if (this._verbose) System.Console.WriteLine("Found document - deleting"); + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add"); + Assert.AreEqual(0, response.status_code); + } + else if (this._verbose) + { + System.Console.WriteLine("document not found. that is ok!"); + } + } + + + [Test] + public void CopyTest() + { + kt_document_detail linkresp = this._kt.copy_document(this._session, this._doc1.docId, 1, "copy", "test123", "test123.txt"); + Assert.AreEqual(0, linkresp.status_code); + Assert.AreEqual("test123.txt", linkresp.filename); + Assert.AreEqual("test123", linkresp.title); + + + + } + + [Test] + public void FindDocumentAfterCopy() + { + String filename = "Root Folder/test123"; + if (this._verbose) System.Console.WriteLine("Finding document before add: " + filename); + kt_document_detail documentDetail = this._kt.get_document_detail_by_title(this._session, 1, filename, ""); + Assert.AreEqual(0, documentDetail.status_code); + + if (this._verbose) System.Console.WriteLine("Found document - deleting"); + kt_response response = this._kt.delete_document(this._session, documentDetail.document_id, "Delete - cleaning up before add"); + Assert.AreEqual(0, response.status_code); + + } + + + + } +} diff --git a/ktwebservice/nunit/document_detail.cs b/ktwebservice/nunit/document_detail.cs index 6406f63..85619d7 100644 --- a/ktwebservice/nunit/document_detail.cs +++ b/ktwebservice/nunit/document_detail.cs @@ -5,23 +5,17 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentDetailTest - { - private String _session; - private KnowledgeTreeService _kt; + public class DocumentDetailTest : KTTest + { private int _docId; private int _folderId; private String _filename; - private String _content; - private bool _verbose; + private String _content; [SetUp] public void SetUp() - { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; + { this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; @@ -29,10 +23,7 @@ namespace MonoTests.KnowledgeTree this._content = "hello world!"; - Helper.writeFile(this._filename, this._content); - - this._verbose = false; - + Helper.writeFile(this._filename, this._content); this._folderId = 1; kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); @@ -56,9 +47,7 @@ namespace MonoTests.KnowledgeTree if (this._verbose && response.status_code != 0) { System.Console.WriteLine("Could not delete file: " + this._filename); - } - - this._kt.logout(this._session); + } } diff --git a/ktwebservice/nunit/document_download.cs b/ktwebservice/nunit/document_download.cs index 8c6ab6b..6112020 100644 --- a/ktwebservice/nunit/document_download.cs +++ b/ktwebservice/nunit/document_download.cs @@ -8,40 +8,25 @@ namespace MonoTests.KnowledgeTree [TestFixture] - public class DocumentSystemMetadataTest + public class DocumentSystemMetadataTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; - this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); this._doc1.createFile(this._folderId); - - - this._verbose = true; - } [TearDown] public void TearDown() { this._doc1.deleteFile(); - - this._kt.logout(this._session); - } [Test] diff --git a/ktwebservice/nunit/document_history.cs b/ktwebservice/nunit/document_history.cs index 9302a6c..9838b41 100644 --- a/ktwebservice/nunit/document_history.cs +++ b/ktwebservice/nunit/document_history.cs @@ -5,36 +5,24 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentHistoryTest + public class DocumentHistoryTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); this._doc1.createFile(this._folderId); - - this._verbose = true; - } [TearDown] public void TearDown() { this._doc1.deleteFile(); - - this._kt.logout(this._session); } [Test] diff --git a/ktwebservice/nunit/document_links.cs b/ktwebservice/nunit/document_links.cs index 272a5ff..f7dc767 100644 --- a/ktwebservice/nunit/document_links.cs +++ b/ktwebservice/nunit/document_links.cs @@ -7,12 +7,9 @@ namespace MonoTests.KnowledgeTree [TestFixture] - public class DocumentLinkTest + public class DocumentLinkTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; private Document _doc2; @@ -20,21 +17,12 @@ namespace MonoTests.KnowledgeTree [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; - this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); this._doc1.createFile(this._folderId); this._doc2 = new Document(2, this._session, this._kt, this._verbose, false); this._doc2.createFile(this._folderId); - - - this._verbose = true; - } [TearDown] @@ -42,9 +30,6 @@ namespace MonoTests.KnowledgeTree { this._doc1.deleteFile(); this._doc2.deleteFile(); - - this._kt.logout(this._session); - } [Test] diff --git a/ktwebservice/nunit/document_metadata.cs b/ktwebservice/nunit/document_metadata.cs index b7b265b..3d8a1a2 100644 --- a/ktwebservice/nunit/document_metadata.cs +++ b/ktwebservice/nunit/document_metadata.cs @@ -5,25 +5,17 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentMetadataTest + public class DocumentMetadataTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _docId; private int _folderId; private String _filename; private String _content; - private bool _verbose; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._filename = Helper.isUnix()?"/tmp/kt_unit_test1.txt":"c:\\kt_unit_test1.txt"; String filename = "kt unit test1"; @@ -32,8 +24,6 @@ namespace MonoTests.KnowledgeTree Helper.writeFile(this._filename, this._content); - this._verbose = false; - this._folderId = 1; kt_document_detail response1 = this._kt.add_base64_document(this._session, this._folderId, filename, this._filename, "Default", Helper.ConvertFileToBase64Encoding(this._filename)); @@ -58,9 +48,6 @@ namespace MonoTests.KnowledgeTree { System.Console.WriteLine("Could not delete file: " + this._filename); } - - this._kt.logout(this._session); - } [Test] diff --git a/ktwebservice/nunit/document_owner.cs b/ktwebservice/nunit/document_owner.cs index 56c8677..7512664 100644 --- a/ktwebservice/nunit/document_owner.cs +++ b/ktwebservice/nunit/document_owner.cs @@ -5,38 +5,24 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentOwnerTest + public class DocumentOwnerTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; - this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); this._doc1.createFile(this._folderId); - - this._verbose = true; - } [TearDown] public void TearDown() { this._doc1.deleteFile(); - - this._kt.logout(this._session); - } [Test] diff --git a/ktwebservice/nunit/document_rename.cs b/ktwebservice/nunit/document_rename.cs index b6f8190..656bec0 100644 --- a/ktwebservice/nunit/document_rename.cs +++ b/ktwebservice/nunit/document_rename.cs @@ -5,36 +5,24 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentRenameTest + public class DocumentRenameTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); this._doc1.createFile(this._folderId); - - this._verbose = true; - } [TearDown] public void TearDown() { this._doc1.deleteFile(); - - this._kt.logout(this._session); } [Test] diff --git a/ktwebservice/nunit/document_system_metadata.cs b/ktwebservice/nunit/document_system_metadata.cs index 729b2e2..5c4b419 100644 --- a/ktwebservice/nunit/document_system_metadata.cs +++ b/ktwebservice/nunit/document_system_metadata.cs @@ -7,12 +7,9 @@ namespace MonoTests.KnowledgeTree [TestFixture] - public class DocumentSystemMetadataTest + public class DocumentSystemMetadataTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; private int _folderId; - private bool _verbose; private Document _doc1; private Document _doc2; @@ -20,20 +17,12 @@ namespace MonoTests.KnowledgeTree [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; this._doc1 = new Document(1, this._session, this._kt, this._verbose,false); this._doc1.createFile(this._folderId); this._doc2 = new Document(2, this._session, this._kt, this._verbose,true); - - - this._verbose = true; - } [TearDown] @@ -41,12 +30,9 @@ namespace MonoTests.KnowledgeTree { this._doc1.deleteFile(); this._doc2.deleteFile(); - - this._kt.logout(this._session); - } - [Test] +// [Test] public void UpdateDocumentMetadataTest() { @@ -64,13 +50,16 @@ namespace MonoTests.KnowledgeTree fs[0].fields[2].name = "Media Type"; fs[0].fields[2].value = "Text"; - kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; + kt_sysdata_item[] sysdata = new kt_sysdata_item[3]; sysdata[0] = new kt_sysdata_item(); sysdata[0].name = "created_by"; sysdata[0].value = "Anonymous"; sysdata[1] = new kt_sysdata_item(); sysdata[1].name = "created_date"; sysdata[1].value = "2007-01-17"; + sysdata[2] = new kt_sysdata_item(); + sysdata[2].name = "modified_by"; + sysdata[2].value = "admin"; kt_document_detail update_resp = this._kt.update_document_metadata(this._session, this._doc1.docId, fs, sysdata); @@ -88,9 +77,11 @@ namespace MonoTests.KnowledgeTree Assert.AreEqual("Anonymous", update_resp.created_by); Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); + Assert.AreEqual("Administrator", update_resp.modified_by); + Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); } - [Test] +// [Test] public void AddSmallDocumentWithMetadataTest() { kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; @@ -134,7 +125,7 @@ namespace MonoTests.KnowledgeTree Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); } - [Test] +// [Test] public void CheckinSmallDocumentWithMetadataTest() { kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; @@ -159,7 +150,7 @@ namespace MonoTests.KnowledgeTree sysdata[1].name = "created_date"; sysdata[1].value = "2007-01-17"; - kt_response resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false); + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false); Assert.AreEqual(0, resp.status_code); @@ -181,7 +172,83 @@ namespace MonoTests.KnowledgeTree Assert.AreEqual("Anonymous", update_resp.created_by); Assert.AreEqual("2007-01-17 00:00:00", update_resp.created_date); } + + [Test] + public void AddDocumentWithMetadataTest() + { + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; + fs[0] = new kt_metadata_fieldset(); + fs[0].fieldset = "General information"; + fs[0].fields = new kt_metadata_field[3]; + fs[0].fields[0] = new kt_metadata_field(); + fs[0].fields[0].name = "Document Author"; + fs[0].fields[0].value = "Joe Soap"; + fs[0].fields[1] = new kt_metadata_field(); + fs[0].fields[1].name = "Category"; + fs[0].fields[1].value = "Technical"; + fs[0].fields[2] = new kt_metadata_field(); + fs[0].fields[2].name = "Media Type"; + fs[0].fields[2].value = "Text"; + + kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; + sysdata[0] = new kt_sysdata_item(); + sysdata[0].name = "created_by"; + sysdata[0].value = "Anonymous"; + sysdata[1] = new kt_sysdata_item(); + sysdata[1].name = "created_date"; + sysdata[1].value = "2007-01-17"; + + + + this._doc2.local = true; + this._doc2.createFile(this._folderId); + + + FileUploader uploader = new FileUploader( ); + + uploader.upload(this._session, this._doc2.filename); + + System.Console.WriteLine("uploaded: " + uploader.filename); + kt_document_detail response1 = this._kt.add_document_with_metadata(this._session, this._folderId, this._doc2.title, this._doc2.filename, "Default", uploader.filename,fs, sysdata); + + Assert.AreEqual(0, response1.status_code); + } + [Test] + public void CheckinDocumentWithMetadataTest() + { + kt_metadata_fieldset[] fs = new kt_metadata_fieldset[1]; + fs[0] = new kt_metadata_fieldset(); + fs[0].fieldset = "General information"; + fs[0].fields = new kt_metadata_field[3]; + fs[0].fields[0] = new kt_metadata_field(); + fs[0].fields[0].name = "Document Author"; + fs[0].fields[0].value = "Joe Soap"; + fs[0].fields[1] = new kt_metadata_field(); + fs[0].fields[1].name = "Category"; + fs[0].fields[1].value = "Technical"; + fs[0].fields[2] = new kt_metadata_field(); + fs[0].fields[2].name = "Media Type"; + fs[0].fields[2].value = "Text"; + + kt_sysdata_item[] sysdata = new kt_sysdata_item[2]; + sysdata[0] = new kt_sysdata_item(); + sysdata[0].name = "created_by"; + sysdata[0].value = "Anonymous"; + sysdata[1] = new kt_sysdata_item(); + sysdata[1].name = "created_date"; + sysdata[1].value = "2007-01-17"; + + kt_document_detail resp = this._kt.checkout_base64_document(this._session, this._doc1.docId, "test checkin", false); + Assert.AreEqual(0, resp.status_code); + + FileUploader uploader = new FileUploader( ); + + uploader.upload(this._session, this._doc1.filename); + + kt_document_detail update_resp = this._kt.checkin_document(this._session, this._doc1.docId, this._doc1.filename, "unit test - doing checkin", uploader.filename, false); + Assert.AreEqual(0, update_resp.status_code); + } } } diff --git a/ktwebservice/nunit/document_type.cs b/ktwebservice/nunit/document_type.cs index 404072c..06a97ed 100644 --- a/ktwebservice/nunit/document_type.cs +++ b/ktwebservice/nunit/document_type.cs @@ -5,21 +5,14 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class DocumentOwnerTest + public class DocumentOwnerTest : KTTest { - private String _session; - private KnowledgeTreeService _kt; - private int _folderId; - private bool _verbose; + private int _folderId; private Document _doc1; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - this._folderId = 1; @@ -34,9 +27,6 @@ namespace MonoTests.KnowledgeTree public void TearDown() { this._doc1.deleteFile(); - - this._kt.logout(this._session); - } [Test] diff --git a/ktwebservice/nunit/document_workflow.cs b/ktwebservice/nunit/document_workflow.cs index f184492..1f57848 100644 --- a/ktwebservice/nunit/document_workflow.cs +++ b/ktwebservice/nunit/document_workflow.cs @@ -5,35 +5,24 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class WorkflowTest - { - private String _session; - private KnowledgeTreeService _kt; - private int _folderId; - private bool _verbose; + public class WorkflowTest : KTTest + { + private int _folderId; private Document _doc1; [SetUp] public void SetUp() - { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - - this._folderId = 1; - - + { + this._folderId = 1; + this._doc1 = new Document(1, this._session, this._kt, this._verbose, false); - this._doc1.createFile(this._folderId); - - this._verbose = true; + this._doc1.createFile(this._folderId); } [TearDown] public void TearDown() { - this._doc1.deleteFile(); - this._kt.logout(this._session); + this._doc1.deleteFile(); } [Test] diff --git a/ktwebservice/nunit/folder.cs b/ktwebservice/nunit/folder.cs index 7630489..2cfdb74 100644 --- a/ktwebservice/nunit/folder.cs +++ b/ktwebservice/nunit/folder.cs @@ -5,28 +5,20 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class FolderTest + public class FolderTest : KTTest { - - private String _session; - private KnowledgeTreeService _kt; + private int _folder_id; private int _subfolder_id; [SetUp] public void SetUp() { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - } [TearDown] public void TearDown() - { - - this._kt.logout(this._session); + { } [Test] diff --git a/ktwebservice/nunit/helper.cs b/ktwebservice/nunit/helper.cs index d66ece8..10195e2 100644 --- a/ktwebservice/nunit/helper.cs +++ b/ktwebservice/nunit/helper.cs @@ -1,22 +1,64 @@ using System; using System.Text; using System.Net; -using System.IO; +using System.IO; +using System.Collections; namespace MonoTests.KnowledgeTree { + + + + [System.Web.Services.WebServiceBinding(Name="KnowledgeTreePort", Namespace="urn:KnowledgeTree")] + public class KTWebService : KnowledgeTreeService + { + public KTWebService() : base() + { + this.Url = Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/webservice.php"; + } + } + + public class KTTest + { + protected KTWebService _kt; + protected String _session; + protected bool _verbose; + + public KTTest() + { + this._kt = new KTWebService(); + kt_response response = this._kt.login("admin","admin","127.0.0.1"); + this._session = response.message; + this._verbose = false; + + } + + ~KTTest() + { + this._kt.logout(this._session); + } + } + + + public class FileUploader { private String boundary; private String uri; - private String filename; + public String filename; public FileUploader(String uri) { this.uri = uri; + System.Console.WriteLine("Using upload URL: " + uri); this.boundary = "----" + DateTime.Now.Ticks.ToString("x"); } + + public FileUploader() : this(Environment.GetEnvironmentVariable("KT_ROOT_URL") + "/ktwebservice/upload.php") + { + } + public String getFilename() { @@ -125,6 +167,8 @@ namespace MonoTests.KnowledgeTree } } + + public class Document { diff --git a/ktwebservice/nunit/makefile b/ktwebservice/nunit/makefile index 1af3df6..aa75e12 100644 --- a/ktwebservice/nunit/makefile +++ b/ktwebservice/nunit/makefile @@ -1,8 +1,9 @@ -RESULTS=authentication.result document_detail.result document_links.result document_owner.result document_type.result document_history.result document_rename.result document_workflow.result document_metadata.result folder.result document_add.result document_system_metadata.result document_checkout.result +RESULTS= authentication.result document_detail.result document_add.result document_checkout.result document_type.result document_links.result document_owner.result document_rename.result document_history.result document_workflow.result document_copy.result folder.result document_metadata.result document_system_metadata.result #document_download.result PROXY=KTproxy.cs WSDL=ktdms.wsdl -WSDL_URL=http://ktdms.trunk/ktwebservice/index.php?wsdl +ROOT_URL=http://ktdms.trunk +WSDL_URL=${ROOT_URL}/ktwebservice/index.php?wsdl all: ${RESULTS} @@ -11,6 +12,8 @@ results: clean-results ${RESULTS} KTproxy.dll: KTproxy.cs helper.cs mcs -r:System.Web.Services /target:library KTproxy.cs helper.cs + + KTproxy.cs: ktdms.wsdl wsdl -out:${PROXY} ${WSDL} @@ -23,9 +26,9 @@ clean: clean-results: rm -f ${RESULTS} -%.dll: %.cs KTproxy.dll - mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $< +%.dll: %.cs KTproxy.dll + mcs -r:System.Web.Services -r:nunit.framework /r:KTproxy.dll -debug /target:library -out:$@ $< %.result: %.dll - nunit-console $< + (export KT_ROOT_URL=${ROOT_URL}; nunit-console $<) mv TestResult.xml $@ diff --git a/ktwebservice/nunit/query.cs b/ktwebservice/nunit/query.cs index c3ee009..3e9e0b2 100644 --- a/ktwebservice/nunit/query.cs +++ b/ktwebservice/nunit/query.cs @@ -5,25 +5,18 @@ using System.IO; namespace MonoTests.KnowledgeTree { [TestFixture] - public class QueryTest + public class QueryTest : KTTest { - - private String _session; - private KnowledgeTreeService _kt; + [SetUp] public void SetUp() - { - this._kt = new KnowledgeTreeService(); - kt_response response = this._kt.login("admin","admin","127.0.0.1"); - this._session = response.message; - + { } [TearDown] public void TearDown() - { - this._kt.logout(this._session); + { } [Test] diff --git a/ktwebservice/proxy/proxy.php b/ktwebservice/proxy/proxy.php deleted file mode 100644 index fc6e4f8..0000000 --- a/ktwebservice/proxy/proxy.php +++ /dev/null @@ -1,165 +0,0 @@ -. - * - * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, - * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * - * The interactive user interfaces in modified source and object code versions - * of this program must display Appropriate Legal Notices, as required under - * Section 5 of the GNU General Public License version 3. - * - * In accordance with Section 7(b) of the GNU General Public License version 3, - * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the - * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. - * Contributor( s): ______________________________________ - * - */ - -set_time_limit(0); - -if ($argc < 3) -{ - die('Usage: proxy.php listenport connectaddr connectport'); -} - -$cport = $argv[1]; -$saddress = $argv[2]; -$sport = $argv[2]; - - -print "Listening on port: $cport\n"; -print "Connecting to: $saddress:$sport\n"; - -if (($lsock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) -{ - die('Cannot create socket: '. socket_strerror($res)); -} - -if (($res = @socket_bind($lsock, '127.0.0.2', $cport)) === false) -{ - die('Cannot bind socket: ' . socket_strerror($res)); -} - -if (($res = socket_listen($lsock, 5)) === false) -{ - die('Cannot listen on socket: ' . socket_strerror($res)); -} - -while(true) -{ - if (($csock = socket_accept($lsock)) < 0) - { - print 'Cannot accept socket: ' . socket_strerror($csock) . "\n"; - continue; - } - print "accepting client\n"; - - if (($ssock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) - { - print('Cannot create socket: '. socket_strerror($res)); - continue; - } - - print "connecting\n"; - if (($res = socket_connect($ssock, $saddress, $sport)) < 0) - { - print('Cannot bind socket: ' . socket_strerror($res)); - continue; - } - - - ob_implicit_flush(); - - $clientClose = false; - $serverClose = false; - while(!$clientClose && !$serverClose) - { - $arr = array(); - $carr = array(); - $sarr = array(); - - if (!$clientClose) - { - $arr[]= $csock; - $carr[]= $csock; - } - if (!$serverClose) - { - $arr[]= $ssock; - $sarr[]= $ssock; - } -ob_implicit_flush(); $res = socket_select($arr, $e2=null, $e = null, 5); - if ($res === false) - { - print "problem\n"; - break; - } - else - { - $res = @socket_select($carr, $w = NULL, $e = NULL, 0); - if (!$clientClose && ($res === 1)) - { - $buf = @socket_read($csock, 2048, PHP_NORMAL_READ); - if (strlen($buf) != 0) - { - socket_write($ssock, $buf, strlen($buf)); - print "C>>S: $buf\n"; - } - if ($buf === false) - { - $clientClose = true; - socket_write($ssock, "\n", 1); - print "close connection to client\n"; - } - - } - $res = @socket_select($sarr, $w = NULL, $e = NULL, 0); - if (!$serverClose && ($res === 1)) - { - $buf = @socket_read($ssock, 2048, PHP_NORMAL_READ); - if (strlen($buf) != 0) - { - socket_write($csock, $buf, strlen($buf)); - print "C< \ No newline at end of file diff --git a/ktwebservice/webservice.php b/ktwebservice/webservice.php index 9203031..8f82c04 100644 --- a/ktwebservice/webservice.php +++ b/ktwebservice/webservice.php @@ -1,5 +1,5 @@ . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ - require_once('../config/dmsDefaults.php'); require_once('../ktapi/ktapi.inc.php'); require_once('SOAP/Server.php'); @@ -46,7 +45,19 @@ require_once('SOAP/Disco.php'); require_once('KTDownloadManager.inc.php'); require_once('KTUploadManager.inc.php'); require_once(KT_LIB_DIR . '/storage/storagemanager.inc.php'); -require_once(KT_DIR . '/search2/search/search.inc.php'); + +list($major, $minor, $fix) = explode('.', $default->systemVersion); + +if ($major == 3 && $minor >= 5) +{ + define('HAS_SEARCH_FUNCTIONALITY',1); +} +unset($major); unset($minor); unset($fix); + +if (defined('HAS_SEARCH_FUNCTIONALITY')) +{ + require_once(KT_DIR . '/search2/search/search.inc.php'); +} // TODO: Test getting files/metadata based on versioning works and implementation is consistent. @@ -106,6 +117,8 @@ class KTWebService var $namespace; var $mustDebug; + var $version; + var $ktapi; @@ -114,13 +127,9 @@ class KTWebService // Caching was giving some problems, so disable it. $config = &KTConfig::getSingleton(); + $this->version = $config->get('webservice/version', 2); $this->mustDebug = $config->get('webservice/debug', false); - $cache_enabled = $config->get('cache/cacheEnabled'); - if ($cache_enabled) - { - $this->error('Cache is enabled. This is likely to cause problems!', 'constructor'); - } - $config->setns('cache','cacheEnabled',false); + $this->ktapi = null; $this->namespace = 'KnowledgeTree'; @@ -140,6 +149,11 @@ class KTWebService 'full_path' => 'string', ); + if ($this->version >= 2) + { + $this->__typedef["{urn:$this->namespace}kt_folder_detail"]['created_by'] = 'string'; + } + $this->__typedef["{urn:$this->namespace}kt_folder_item"] = array( 'id' => 'int', @@ -196,10 +210,43 @@ class KTWebService 'workflow_state' => 'string', 'checkout_by' => 'string', 'full_path' => 'string', - // 'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets", - // 'owner' => 'string', ); + if ($this->version >= 2) + { + $this->__typedef["{urn:$this->namespace}kt_document_detail"] = + array( + 'status_code'=>'int', + 'message'=>'string', + 'title' => 'string', + 'document_type' => 'string', + 'version' => 'string', + 'filename' => 'string', + 'created_date' => 'string', + 'created_by' => 'string', + 'modified_date' => 'string', + 'modified_by' => 'string', + 'document_id' => 'int', + 'folder_id' => 'int', + 'workflow' => 'string', + 'workflow_state' => 'string', + //'checkout_by' => 'string', + 'full_path' => 'string', + 'owner'=>'string', + 'is_immutable'=>'boolean', + 'checked_out_date'=>'string', + 'checked_out_by'=>'string', + 'metadata' => "{urn:$this->namespace}kt_metadata_fieldsets", + 'links' => "{urn:$this->namespace}kt_linked_documents", + 'transitions' => "{urn:$this->namespace}kt_workflow_transitions", + 'version_history' => "{urn:$this->namespace}kt_document_version_history", + 'transaction_history' => "{urn:$this->namespace}kt_document_transaction_history", + ); + } + + if (defined('HAS_SEARCH_FUNCTIONALITY')) + { + $this->__typedef["{urn:$this->namespace}kt_search_result_item"] = array( 'document_id' => 'int', @@ -221,7 +268,7 @@ class KTWebService 'modified_date' => 'string', 'checked_out_by' => 'string', 'checked_out_date' => 'string', - 'is_immutable' => 'bool', + 'is_immutable' => 'boolean', 'status' => 'string', ); @@ -238,6 +285,24 @@ class KTWebService 'message' => 'string', 'hits' => "{urn:$this->namespace}kt_search_results" , ); + } + + if ($this->version >= 2) + { + + $this->__typedef["{urn:$this->namespace}kt_sysdata_item"] = + array( + 'name' => 'string', + 'value' => 'string' + ); + + $this->__typedef["{urn:$this->namespace}kt_sysdata"] = + array( + array( + 'item' => "{urn:$this->namespace}kt_sysdata_item" + ) + ); + } $this->__typedef["{urn:$this->namespace}kt_metadata_selection_item"] = array( @@ -314,8 +379,7 @@ class KTWebService 'username'=>'string', 'version' => 'string', 'comment' => 'string', - 'datetime' => 'string', - + 'datetime' => 'string' ); $this->__typedef["{urn:$this->namespace}kt_linked_document"] = @@ -325,8 +389,7 @@ class KTWebService 'size' => 'int', 'workflow' => 'string', 'workflow_state' => 'string', - 'link_type' => 'string', - + 'link_type' => 'string' ); $this->__typedef["{urn:$this->namespace}kt_linked_documents"] = @@ -340,7 +403,7 @@ class KTWebService array( 'status_code'=>'int', 'message'=>'string', - 'parent_document_id' => 'string', + 'parent_document_id' => 'int', 'links' => "{urn:$this->namespace}kt_linked_documents" ); @@ -416,11 +479,14 @@ class KTWebService ); /* methods */ + if (defined('HAS_SEARCH_FUNCTIONALITY')) + { - $this->__dispatch_map['search'] = - array('in' => array('session_id' => 'string', 'search'=>'string' ,'options'=>'string'), - 'out' => array('return' => "{urn:$this->namespace}kt_search_response" ), - ); + $this->__dispatch_map['search'] = array( + 'in' => array('session_id' => 'string', 'search'=>'string' ,'options'=>'string'), + 'out' => array('return' => "{urn:$this->namespace}kt_search_response" ), + ); + } // login $this->__dispatch_map['login'] = @@ -465,6 +531,17 @@ class KTWebService 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"), ); + if ($this->version >=2) + { + // create_folder + $this->__dispatch_map['add_folder'] = + array('in' => array('session_id'=>'string','folder_id'=>'int','folder_name' =>'string'), + 'out' => array('return' => "{urn:$this->namespace}kt_folder_detail"), + 'alias'=>'create_folder' + ); + } + + // delete_folder $this->__dispatch_map['delete_folder'] = array('in' => array('session_id'=>'string','folder_id'=>'int','reason' =>'string'), @@ -509,11 +586,17 @@ class KTWebService ); // get_document_detail - $this->__dispatch_map['get_document_detail'] = - array('in' => array('session_id' => 'string', 'document_id' => 'int' ), - 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"), + $this->__dispatch_map['get_document_detail'] = array( + 'in' => array('session_id' => 'string', 'document_id' => 'int' ), + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"), ); + if ($this->version >= 2) + { + $this->__dispatch_map['get_document_detail']['in'] = array('session_id' => 'string', 'document_id' => 'int', 'detail'=>'string' ); + } + + // checkin_document $this->__dispatch_map['checkin_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean' ), @@ -533,6 +616,20 @@ class KTWebService 'alias' => 'checkin_small_document' ); + if ($this->version >= 2) + { + $this->__dispatch_map['checkin_base64_document_with_metadata'] = + array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','base64' =>'string', 'major_update'=>'boolean', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), + 'alias'=>'checkin_small_document_with_metadata' + ); + $this->__dispatch_map['checkin_document_with_metadata'] = + array('in' => array('session_id'=>'string','document_id'=>'int','filename'=>'string','reason' =>'string','tempfilename' =>'string', 'major_update'=>'boolean', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ) + ); + + } + // add_document $this->__dispatch_map['add_document'] = array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string' ), @@ -553,6 +650,23 @@ class KTWebService ); + if ($this->version >= 2) + { + $this->__dispatch_map['add_base64_document_with_metadata'] = + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','base64' =>'string', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), + 'alias'=>'add_small_document_with_metadata' + ); + + $this->__dispatch_map['add_document_with_metadata'] = + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets",'sysdata'=>"{urn:$this->namespace}kt_sysdata" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ) + ); + + + } + + // get_document_detail_by_name $this->__dispatch_map['get_document_detail_by_name'] = @@ -560,18 +674,48 @@ class KTWebService 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"), ); + if ($this->version >= 2) + { + $this->__dispatch_map['get_document_detail_by_name']['in'] = array('session_id' => 'string', 'folder_id'=>'int', 'document_name' => 'string', 'what'=>'string', 'detail'=>'string' ); + + $this->__dispatch_map['get_document_detail_by_title'] = array( + 'in' => array('session_id' => 'string', 'folder_id'=>'int', 'title' => 'string', 'detail'=>'string' ), + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"), + ); + + $this->__dispatch_map['get_document_detail_by_filename'] = array( + 'in' => array('session_id' => 'string', 'folder_id'=>'int', 'filename' => 'string', 'detail'=>'string' ), + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail"), + ); + } + // checkout_document $this->__dispatch_map['checkout_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'), 'out' => array('return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['checkout_document'] = + array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download'=>'boolean'), + 'out' => array('return' => "{urn:$this->namespace}kt_document_detail" ), + ); + } + + // checkout_small_document $this->__dispatch_map['checkout_small_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'), 'out' => array('return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['checkout_small_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" ); + } + + // checkout_base64_document $this->__dispatch_map['checkout_base64_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string','download' => 'boolean'), @@ -579,12 +723,25 @@ class KTWebService 'alias' => 'checkout_small_document' ); + if ($this->version >= 2) + { + $this->__dispatch_map['checkout_base64_document']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" ); + } + + // undo_document_checkout $this->__dispatch_map['undo_document_checkout'] = array('in' => array('session_id'=>'string','document_id'=>'int','reason' =>'string'), 'out' => array('return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['undo_document_checkout']['out'] = array('return' => "{urn:$this->namespace}kt_document_detail" ); + } + + + // download_document $this->__dispatch_map['download_document'] = array('in' => array('session_id'=>'string','document_id'=>'int' ), @@ -617,28 +774,51 @@ class KTWebService 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['change_document_owner']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + + // copy_document $this->__dispatch_map['copy_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string'), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['copy_document']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } // move_document $this->__dispatch_map['move_document'] = array('in' => array('session_id'=>'string','document_id'=>'int','folder_id'=>'int','reason'=>'string','newtitle'=>'string','newfilename'=>'string'), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['move_document']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + // rename_document_title $this->__dispatch_map['rename_document_title'] = array('in' => array('session_id'=>'string','document_id'=>'int', 'newtitle'=>'string' ), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); - + if ($this->version >= 2) + { + $this->__dispatch_map['rename_document_title']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } // rename_document_filename $this->__dispatch_map['rename_document_filename'] = array('in' => array('session_id'=>'string','document_id'=>'int', 'newfilename'=>'string' ), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['rename_document_filename']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + // change_document_type $this->__dispatch_map['change_document_type'] = @@ -646,23 +826,51 @@ class KTWebService 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['change_document_type']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + // start_document_workflow $this->__dispatch_map['start_document_workflow'] = array('in' => array('session_id'=>'string','document_id'=>'int', 'workflow'=>'string' ), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + + if ($this->version >= 2) + { + $this->__dispatch_map['start_document_workflow']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + // delete_document_workflow $this->__dispatch_map['delete_document_workflow'] = array('in' => array('session_id'=>'string','document_id'=>'int' ), - 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ) ); + if ($this->version >= 2) + { + $this->__dispatch_map['delete_document_workflow']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + + // stop_document_workflow + $this->__dispatch_map['stop_document_workflow'] = + array('in' => array('session_id'=>'string','document_id'=>'int' ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), + 'alias'=>'delete_document_workflow' + ); + } + // perform_document_workflow_transition $this->__dispatch_map['perform_document_workflow_transition'] = array('in' => array('session_id'=>'string','document_id'=>'int','transition'=>'string','reason'=>'string' ), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['perform_document_workflow_transition']['out'] = array( 'return' => "{urn:$this->namespace}kt_document_detail" ); + } + // get_document_metadata $this->__dispatch_map['get_document_metadata'] = array('in' => array('session_id'=>'string','document_id'=>'int' ), @@ -676,10 +884,20 @@ class KTWebService ); //update_document_metadata $this->__dispatch_map['update_document_metadata'] = - array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets" ), + array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets" ), 'out' => array( 'return' => "{urn:$this->namespace}kt_response" ), ); + if ($this->version >= 2) + { + $this->__dispatch_map['update_document_metadata'] = + array('in' => array('session_id'=>'string','document_id'=>'int','metadata'=>"{urn:$this->namespace}kt_metadata_fieldsets", 'sysdata'=>"{urn:$this->namespace}kt_sysdata" ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ) + ); + + + } + //get_document_workflow_transitions $this->__dispatch_map['get_document_workflow_transitions'] = @@ -728,9 +946,10 @@ class KTWebService } - function debug($msg, $function = null) + function debug($msg, $function = null, $level=0) { - if ($this->mustDebug) + if ($this->mustDebug === false) return; + if ($this->mustDebug >= $level) { global $default; if (!is_null($function)) @@ -763,6 +982,11 @@ class KTWebService */ function &get_ktapi($session_id) { + if (!is_null($this->ktapi)) + { + return $this->ktapi; + } + $kt = new KTAPI(); $session = $kt->get_active_session($session_id, null); @@ -776,6 +1000,7 @@ class KTWebService return $response; } + $this->ktapi = $kt; return $kt; } @@ -1368,9 +1593,9 @@ class KTWebService * @param int $document_id * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ - function get_document_detail($session_id, $document_id) + function get_document_detail($session_id, $document_id, $detail='') { - $this->debug("get_document_detail('$session_id',$document_id)"); + $this->debug("get_document_detail('$session_id',$document_id,'$detail')"); $kt = &$this->get_ktapi($session_id ); if (is_array($kt)) { @@ -1389,6 +1614,7 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); } + $detailstr = $detail; $detail = $document->get_detail(); if (PEAR::isError($detail)) { @@ -1402,9 +1628,62 @@ class KTWebService $detail['status_code']=KTWS_SUCCESS; $detail['message']=''; + + if ($this->version >= 2) + { + $detail['metadata'] = array(); + $detail['links'] = array(); + $detail['transitions'] = array(); + $detail['version_history'] = array(); + $detail['transaction_history'] = array(); + + + if (stripos($detailstr,'M') !== false) + { + $response = $this->get_document_metadata($session_id, $document_id); + $detail['metadata'] = $response->value['metadata']; + } + + if (stripos($detailstr,'L') !== false) + { + $response = $this->get_document_metadata($session_id, $document_id); + $detail['links'] = $response->value['links']; + } + + if (stripos($detailstr,'T') !== false) + { + $response = $this->get_document_workflow_transitions($session_id, $document_id); + $detail['transitions'] = $response->value['transitions']; + } + + if (stripos($detailstr,'V') !== false) + { + $response = $this->get_document_version_history($session_id, $document_id); + $detail['version_history'] = $response->value['history']; + } + + if (stripos($detailstr,'H') !== false) + { + $response = $this->get_document_transaction_history($session_id, $document_id); + $detail['transaction_history'] = $response->value['history']; + } + + } + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); } + function get_document_detail_by_filename($session_id, $folder_id, $filename, $detail='') + { + return $this->get_document_detail_by_name($session_id, $folder_id, $filename, 'F', $detail); + } + + function get_document_detail_by_title($session_id, $folder_id, $title, $detail='') + { + return $this->get_document_detail_by_name($session_id, $folder_id, $title, 'T', $detail); + } + + /** * Returns document detail given a document name which could include a full path. * @@ -1413,9 +1692,9 @@ class KTWebService * @param string @what * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ - function get_document_detail_by_name($session_id, $document_name, $what='T') + function get_document_detail_by_name($session_id, $folder_id, $document_name, $what='T', $detail='') { - $this->debug("get_document_detail_by_name('$session_id','$document_name','$what')"); + $this->debug("get_document_detail_by_name('$session_id','$document_name','$what','$detail')"); $response=array( 'status_code'=>KTWS_ERR_INVALID_FOLDER, 'message'=>'' @@ -1439,10 +1718,11 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); } - $root = &$kt->get_root_folder(); + if ($folder_id < 1) $folder_id = 1; + $root = &$kt->get_folder_by_id($folder_id); if (PEAR::isError($root)) { - $this->debug("get_document_detail_by_name - cannot get root folder - " . $root->getMessage(), $session_id); + $this->debug("get_document_detail_by_name - cannot get root folder - folder_id = $folder_id - " . $root->getMessage(), $session_id); return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); } @@ -1466,6 +1746,8 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); } + $detailstr = $detail; + $detail = $document->get_detail(); if (PEAR::isError($detail)) { @@ -1480,6 +1762,47 @@ class KTWebService $detail['status_code']=KTWS_SUCCESS; $detail['message']=''; + + if ($this->version >= 2) + { + + $detail['metadata'] = array(); + $detail['links'] = array(); + $detail['transitions'] = array(); + $detail['version_history'] = array(); + $detail['transaction_history'] = array(); + + if (stripos($detailstr,'M') !== false) + { + $response = $this->get_document_metadata($session_id, $document_id); + $detail['metadata'] = $response->value['metadata']; + } + + if (stripos($detailstr,'L') !== false) + { + $response = $this->get_document_metadata($session_id, $document_id); + $detail['links'] = $response->value['links']; + } + + if (stripos($detailstr,'T') !== false) + { + $response = $this->get_document_workflow_transitions($session_id, $document_id); + $detail['transitions'] = $response->value['transitions']; + } + + if (stripos($detailstr,'V') !== false) + { + $response = $this->get_document_version_history($session_id, $document_id); + $detail['version_history'] = $response->value['history']; + } + + if (stripos($detailstr,'H') !== false) + { + $response = $this->get_document_transaction_history($session_id, $document_id); + $detail['transaction_history'] = $response->value['history']; + } + } + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); } @@ -1552,6 +1875,76 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $detail); } + function add_small_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $base64, $metadata, $sysdata) + { + $add_result = $this->add_small_document($session_id, $folder_id, $title, $filename, $documenttype, $base64); + + $status_code = $add_result->value['status_code']; + if ($status_code != 0) + { + return $add_result; + } + $document_id = $add_result->value['document_id']; + + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata); + $status_code = $update_result->value['status_code']; + if ($status_code != 0) + { + return $update_result; + } + + $kt = &$this->get_ktapi($session_id ); + if (is_array($kt)) + { + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); + } + + $document = $kt->get_document_by_id($document_id); + $result = $document->mergeWithLastMetadataVersion(); + if (PEAR::isError($result)) + { + // not much we can do, maybe just log! + } + + return $update_result; + } + + function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata) + { + $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename); + + $status_code = $add_result->value['status_code']; + if ($status_code != 0) + { + return $add_result; + } + $document_id = $add_result->value['document_id']; + + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata); + $status_code = $update_result->value['status_code']; + if ($status_code != 0) + { + return $update_result; + } + + $kt = &$this->get_ktapi($session_id ); + if (is_array($kt)) + { + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); + } + + $document = $kt->get_document_by_id($document_id); + $result = $document->mergeWithLastMetadataVersion(); + if (PEAR::isError($result)) + { + // not much we can do, maybe just log! + } + + return $update_result; + } + + + /** * Adds a document to the repository. * @@ -1705,11 +2098,78 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); } - $response['status_code'] = KTWS_SUCCESS; - - return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); + // get status after checkin + return $this->get_document_detail($session_id, $document_id); } + + function checkin_small_document_with_metadata($session_id, $document_id, $filename, $reason, $base64, $major_update, $metadata, $sysdata) + { + $add_result = $this->checkin_small_document($session_id, $document_id, $filename, $reason, $base64, $major_update); + + $status_code = $add_result->value['status_code']; + if ($status_code != 0) + { + return $add_result; + } + + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata); + $status_code = $update_result->value['status_code']; + if ($status_code != 0) + { + return $update_result; + } + + $kt = &$this->get_ktapi($session_id ); + if (is_array($kt)) + { + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); + } + + $document = $kt->get_document_by_id($document_id); + $result = $document->mergeWithLastMetadataVersion(); + if (PEAR::isError($result)) + { + // not much we can do, maybe just log! + } + + return $update_result; + } + + function checkin_document_with_metadata($session_id, $document_id, $filename, $reason, $tempfilename, $major_update, $metadata, $sysdata) + { + $add_result = $this->checkin_document($session_id, $document_id, $filename, $reason, $tempfilename, $major_update); + + $status_code = $add_result->value['status_code']; + if ($status_code != 0) + { + return $add_result; + } + + $update_result = $this->update_document_metadata($session_id, $document_id, $metadata, $sysdata); + $status_code = $update_result->value['status_code']; + if ($status_code != 0) + { + return $update_result; + } + + $kt = &$this->get_ktapi($session_id ); + if (is_array($kt)) + { + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $kt); + } + + $document = $kt->get_document_by_id($document_id); + $result = $document->mergeWithLastMetadataVersion(); + if (PEAR::isError($result)) + { + // not much we can do, maybe just log! + } + + return $update_result; + } + + /** * Does a document checkin. * @@ -1795,10 +2255,8 @@ class KTWebService $this->debug("checkin_small_document - cannot checkin document - " . $result->getMessage(), $session_id); return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); } - - $response['status_code'] = KTWS_SUCCESS; - - return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); + // get status after checkin + return $this->get_document_detail($session_id, $document_id); } /** @@ -1807,9 +2265,9 @@ class KTWebService * @param string $session_id * @param int $document_id * @param string $reason - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS */ - function checkout_document($session_id, $document_id, $reason) + function checkout_document($session_id, $document_id, $reason,$download=true) { $this->debug("checkout_document('$session_id',$document_id,'$reason')"); @@ -1842,14 +2300,26 @@ class KTWebService $session = &$kt->get_session(); - $download_manager = new KTDownloadManager(); - $download_manager->set_session($session->session); - $download_manager->cleanup(); - $url = $download_manager->allow_download($document); + $url = ''; + if ($download) + { + $download_manager = new KTDownloadManager(); + $download_manager->set_session($session->session); + $download_manager->cleanup(); + $url = $download_manager->allow_download($document); + } $response['status_code'] = KTWS_SUCCESS; $response['message'] = $url; + if ($this->version >= 2) + { + $result = $this->get_document_detail($session_id, $document_id); + $result->value['message'] = $url; + + return $result; + } + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } @@ -1860,7 +2330,7 @@ class KTWebService * @param int $document_id * @param string $reason * @param boolean $download - * @return kt_response status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS + * @return kt_document_detail status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER or KTWS_SUCCESS */ function checkout_small_document($session_id, $document_id, $reason, $download) { @@ -1916,6 +2386,15 @@ class KTWebService $response['status_code'] = KTWS_SUCCESS; $response['message'] = $content; + if ($this->version >= 2) + { + $result = $this->get_document_detail($session_id, $document_id); + $result->value['message'] = $content; + + return $result; + } + + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } @@ -1925,7 +2404,7 @@ class KTWebService * @param string $session_id * @param int $document_id * @param string $reason - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ function undo_document_checkout($session_id, $document_id, $reason) { @@ -1962,6 +2441,11 @@ class KTWebService $response['status_code'] = KTWS_SUCCESS; + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } @@ -2129,16 +2613,23 @@ class KTWebService * @param string $session_id * @param int $document_id * @param string $documenttype - * @return kt_response + * @return kt_document_detail */ function change_document_type($session_id, $document_id, $documenttype) { $this->debug("change_document_type('$session_id',$document_id,'$documenttype')"); $kt = &$this->get_ktapi($session_id ); + + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2151,7 +2642,7 @@ class KTWebService $response['message'] = $document->getMessage(); $this->debug("change_document_type - cannot get documentid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->change_document_type($documenttype); @@ -2160,11 +2651,16 @@ class KTWebService $response['message'] = $result->getMessage(); $this->debug("change_document_type - cannot change type - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2176,7 +2672,7 @@ class KTWebService * @param string $reason * @param string $newtitle * @param string $newfilename - * @return kt_response + * @return kt_document_detail */ function copy_document($session_id,$document_id,$folder_id,$reason,$newtitle,$newfilename) { @@ -2217,6 +2713,11 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } $response['status_code'] = KTWS_SUCCESS; + if ($this->version >= 2) + { + $new_document_id = $result->documentid; + return $this->get_document_detail($session_id, $new_document_id, ''); + } return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } @@ -2286,9 +2787,16 @@ class KTWebService { $this->debug("rename_document_title('$session_id',$document_id,'$newtitle')"); $kt = &$this->get_ktapi($session_id ); + + $responseType = 'kt_response'; + if ($this->version >=2) + { + $responseType='kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2300,7 +2808,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("rename_document_title - cannot get documentid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->rename($newtitle); @@ -2308,11 +2816,16 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("rename_document_title - cannot rename - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2328,9 +2841,15 @@ class KTWebService $this->debug("rename_document_filename('$session_id',$document_id,'$newfilename')"); $kt = &$this->get_ktapi($session_id ); + $responseType = 'kt_response'; + if ($this->version >=2) + { + $responseType='kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2342,7 +2861,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("rename_document_filename - cannot get documetid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->renameFile($newfilename); @@ -2350,11 +2869,16 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("rename_document_filename - cannot rename - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2364,17 +2888,25 @@ class KTWebService * @param int $document_id * @param string $username * @param string $reason - * @return kt_response. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ function change_document_owner($session_id, $document_id, $username, $reason) { $this->debug("change_document_owner('$session_id',$document_id,'$username','$reason')"); $kt = &$this->get_ktapi($session_id ); + + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } + $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, 'message'=>'' @@ -2385,7 +2917,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("change_document_owner - cannot get documetid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->change_owner($username, $reason); @@ -2393,11 +2925,16 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("change_document_owner - cannot change owner - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2406,16 +2943,22 @@ class KTWebService * @param string $session_id * @param int $document_id * @param string $workflow - * @return kt_response + * @return kt_document_detail */ function start_document_workflow($session_id,$document_id,$workflow) { $this->debug("start_document_workflow('$session_id',$document_id,'$workflow')"); $kt = &$this->get_ktapi($session_id ); + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2427,7 +2970,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("start_document_workflow - cannot get documentid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = &$document->start_workflow($workflow); @@ -2435,11 +2978,16 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("start_document_workflow - cannot start workflow - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2447,15 +2995,20 @@ class KTWebService * * @param string $session_id * @param int $document_id - * @return kt_response + * @return kt_document_detail */ function delete_document_workflow($session_id,$document_id) { $this->debug("delete_document_workflow('$session_id',$document_id)"); $kt = &$this->get_ktapi($session_id ); + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2467,7 +3020,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("delete_document_workflow - cannot get documentid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->delete_workflow(); @@ -2478,8 +3031,12 @@ class KTWebService return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); } $response['status_code'] = KTWS_SUCCESS; + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2496,9 +3053,15 @@ class KTWebService $this->debug("perform_document_workflow_transition('$session_id',$document_id,'$transition','$reason')"); $kt = &$this->get_ktapi($session_id ); + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2510,7 +3073,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("perform_document_workflow_transition - cannot get document - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->perform_workflow_transition($transition,$reason); @@ -2518,11 +3081,16 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("perform_document_workflow_transition - cannot perform transition - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + if ($this->version >= 2) + { + return $this->get_document_detail($session_id, $document_id); + } + + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } /** @@ -2814,16 +3382,22 @@ class KTWebService * @param string $session_id * @param int $document_id * @param array $metadata - * @return kt_response + * @return kt_document_detail */ - function update_document_metadata($session_id,$document_id,$metadata) + function update_document_metadata($session_id,$document_id,$metadata, $sysdata=null) { - $this->debug("update_document_metadata('$session_id',$document_id,$metadata)"); + $this->debug("update_document_metadata('$session_id',$document_id,$metadata, $sysdata)"); $kt = &$this->get_ktapi($session_id ); + $responseType = 'kt_response'; + if ($this->version >= 2) + { + $responseType = 'kt_document_detail'; + } + if (is_array($kt)) { - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $kt); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $kt); } $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, @@ -2835,7 +3409,7 @@ class KTWebService { $response['message'] = $document->getMessage(); $this->debug("update_document_metadata - cannot get documentid $document_id - " . $document->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } $result = $document->update_metadata($metadata); @@ -2843,12 +3417,26 @@ class KTWebService { $response['message'] = $result->getMessage(); $this->debug("update_document_metadata - cannot update metadata - " . $result->getMessage(), $session_id); - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } + + if ($this->version >= 2) + { + $result = $document->update_sysdata($sysdata); + if (PEAR::isError($result)) + { + $response['message'] = $result->getMessage(); + $this->debug("update_document_metadata - cannot update sysdata - " . $result->getMessage(), $session_id); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); + } + + + return $this->get_document_detail($session_id, $document_id, 'M'); + } $response['status_code'] = KTWS_SUCCESS; - return new SOAP_Value('return',"{urn:$this->namespace}kt_response", $response); + return new SOAP_Value('return',"{urn:$this->namespace}$responseType", $response); } @@ -3149,7 +3737,7 @@ class KTWebService $response=array( 'status_code'=>KTWS_ERR_INVALID_DOCUMENT, 'message'=>'', - 'parent_document_id' => $document_id, + 'parent_document_id' => (int) $document_id, 'links'=>array() ); @@ -3162,7 +3750,8 @@ class KTWebService } $links = $document->get_linked_documents(); - $response['links'] = $links; + $response['links'] = new SOAP_Value('links',"{urn:$this->namespace}kt_linked_documents", $links); + $response['status_code'] = KTWS_SUCCESS; return new SOAP_Value('return',"{urn:$this->namespace}kt_linked_document_response", $response); } @@ -3364,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); } @@ -3435,13 +3993,17 @@ class KTWebService */ function run() { + ob_start(); $server = new SOAP_Server(); $server->addObjectMap($this, 'http://schemas.xmlsoap.org/soap/envelope/'); + $request = 'Not Set'; if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST') { - $server->service(file_get_contents("php://input")); + $request = file_get_contents("php://input"); + + $server->service($request); } else { @@ -3457,6 +4019,12 @@ class KTWebService echo $disco->getDISCO(); } } + $capture = ob_get_flush(); + $this->debug($request,'request', 5); + $this->debug($capture,'response',5); + global $_KT_starttime; + $time = number_format(KTUtil::getBenchmarkTime() - $_KT_starttime,2); + $this->debug($time, 'time from start',4); } function __dispatch($methodname) @@ -3470,6 +4038,7 @@ class KTWebService } + $webservice = new KTWebService(); $webservice->run(); diff --git a/lib/browse/browseutil.inc.php b/lib/browse/browseutil.inc.php index 3ea7788..840f588 100644 --- a/lib/browse/browseutil.inc.php +++ b/lib/browse/browseutil.inc.php @@ -7,32 +7,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ */ @@ -381,20 +381,26 @@ class KTBrowseUtil { } $sPermissionDescriptors = DBUtil::paramArray($aPermissionDescriptors); + $oPermission = KTPermission::getByName('ktcore.permissions.read'); + $oPermission2 = KTPermission::getByName('ktcore.permissions.folder_details'); + $aPermissionIds = array($oPermission->getId(), $oPermission->getId(), $oPermission2->getId(), $oPermission2->getId()); + $sFoldersTable = KTUtil::getTableName('folders'); $sPLTable = KTUtil::getTableName('permission_lookups'); $sPLATable = KTUtil::getTableName('permission_lookup_assignments'); - $oPermission = KTPermission::getByName('ktcore.permissions.read'); $sQuery = "SELECT DISTINCT F.id AS id FROM $sFoldersTable AS F - LEFT JOIN $sPLTable AS PL ON F.permission_lookup_id = PL.id LEFT JOIN $sPLATable AS PLA ON PLA.permission_lookup_id = PL.id AND PLA.permission_id = ? + LEFT JOIN $sPLTable AS PL ON F.permission_lookup_id = PL.id + LEFT JOIN $sPLATable AS PLA ON PLA.permission_lookup_id = PL.id AND (PLA.permission_id = ? || PLA.permission_id = ?) + LEFT JOIN $sFoldersTable AS F2 ON F.parent_id = F2.id - LEFT JOIN $sPLTable AS PL2 ON F2.permission_lookup_id = PL2.id LEFT JOIN $sPLATable AS PLA2 ON PLA2.permission_lookup_id = PL2.id AND PLA2.permission_id = ? + LEFT JOIN $sPLTable AS PL2 ON F2.permission_lookup_id = PL2.id + LEFT JOIN $sPLATable AS PLA2 ON PLA2.permission_lookup_id = PL2.id AND (PLA2.permission_id = ? || PLA.permission_id = ?) WHERE PLA.permission_descriptor_id IN ($sPermissionDescriptors) AND F2.id <> 1 AND NOT (PLA2.permission_descriptor_id IN ($sPermissionDescriptors))"; - $aParams = kt_array_merge(array($oPermission->getId(), $oPermission->getId()), $aPermissionDescriptors, $aPermissionDescriptors); + $aParams = kt_array_merge($aPermissionIds, $aPermissionDescriptors, $aPermissionDescriptors); $res = DBUtil::getResultArrayKey(array($sQuery, $aParams), 'id'); if (PEAR::isError($res)) { diff --git a/lib/documentmanagement/documentutil.inc.php b/lib/documentmanagement/documentutil.inc.php index 7e1dbf7..0a21c54 100644 --- a/lib/documentmanagement/documentutil.inc.php +++ b/lib/documentmanagement/documentutil.inc.php @@ -638,14 +638,14 @@ class KTDocumentUtil { return $oDocument; } // }}} - + function generateNewDocumentFilename($sDocFilename){ if(preg_match("/\([0-9]+\)(\.[^\.]+){1,}$/", $sDocFilename)){ preg_match("/\([0-9]+\)\./", $sDocFilename, $matches); $new_one = substr($matches[0], 1); $new_two = explode(')', $new_one); $new = $new_two[0]+1; - + $pattern[0] = '/\([0-9]+\)\./'; $replacement[0] = ' ('.$new.').'; $sFilename = preg_replace($pattern, $replacement, $sDocFilename); @@ -657,27 +657,27 @@ class KTDocumentUtil { } $sFilename = $prefix.$suffix; } - + return $sFilename; } - - function generateNewDocumentName($sDocName){ + + function generateNewDocumentName($sDocName){ if(preg_match("/\([0-9]+\)$/", $sDocName)){ preg_match("/\([0-9]+\)$/", $sDocName, $matches); $new_one = substr($matches[0], 1); $new_two = explode(')', $new_one); $new = $new_two[0]+1; - + $pattern[0] = '/\([0-9]+\)$/'; $replacement[0] = '('.$new.')'; $sName = preg_replace($pattern, $replacement, $sDocName); }else{ $sName = $sDocName.' (2)'; } - + return $sName; } - + // {{{ fileExists function fileExists($oFolder, $sFilename) { return Document::fileExists($sFilename, $oFolder->getID()); @@ -939,7 +939,7 @@ class KTDocumentUtil { } - function copy($oDocument, $oDestinationFolder, $sReason = null) { + function copy($oDocument, $oDestinationFolder, $sReason = null, $sDestinationDocName = null) { // 1. generate a new triad of content, metadata and core objects. // 2. update the storage path. //print '--------------------------------- BEFORE'; @@ -958,23 +958,36 @@ class KTDocumentUtil { // we still have a bogus md_version, but integrity holds, so fix it now. $oCore = KTDocumentCore::get($id); + // Get the metadata version for the source document $sTable = KTUtil::getTableName('document_metadata_version'); $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?'; $aParams = array($oDocument->getMetadataVersionId()); $aMDRow = DBUtil::getOneResult(array($sQuery, $aParams)); unset($aMDRow['id']); + + // Copy the source metadata into the destination document $aMDRow['document_id'] = $oCore->getId(); + if(!empty($sDestinationDocName)){ + $aMDRow['name'] = $sDestinationDocName; + $aMDRow['description'] = $sDestinationDocName; + } $id = DBUtil::autoInsert($sTable, $aMDRow); if (PEAR::isError($id)) { return $id; } $oCore->setMetadataVersionId($id); $oMDV = KTDocumentMetadataVersion::get($id); + // Get the content version for the source document $sTable = KTUtil::getTableName('document_content_version'); $sQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ?'; $aParams = array($oDocument->_oDocumentContentVersion->getId()); $aContentRow = DBUtil::getOneResult(array($sQuery, $aParams)); unset($aContentRow['id']); + + // Copy the source content into the destination document $aContentRow['document_id'] = $oCore->getId(); + if(!empty($sDestinationDocName)){ + $aContentRow['filename'] = $sDestinationDocName; + } $id = DBUtil::autoInsert($sTable, $aContentRow); if (PEAR::isError($id)) { return $id; } $oMDV->setContentVersionId($id); @@ -996,6 +1009,7 @@ class KTDocumentUtil { $res = KTDocumentUtil::copyMetadata($oNewDocument, $oDocument->getMetadataVersionId()); if (PEAR::isError($res)) { return $res; } + // Ensure the copied document is not checked out $oNewDocument->setIsCheckedOut(false); $oNewDocument->setCheckedOutUserID(-1); diff --git a/lib/foldermanagement/folderutil.inc.php b/lib/foldermanagement/folderutil.inc.php index c211726..fab0137 100644 --- a/lib/foldermanagement/folderutil.inc.php +++ b/lib/foldermanagement/folderutil.inc.php @@ -7,32 +7,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ */ @@ -414,8 +414,9 @@ class KTFolderUtil { return true; } - function copy($oSrcFolder, $oDestFolder, $oUser, $sReason) { - if (KTFolderUtil::exists($oDestFolder, $oSrcFolder->getName())) { + function copy($oSrcFolder, $oDestFolder, $oUser, $sReason, $sDestFolderName = NULL, $copyAll = true) { + $sDestFolderName = (empty($sDestFolderName)) ? $oSrcFolder->getName() : $sDestFolderName; + if (KTFolderUtil::exists($oDestFolder, $sDestFolderName)) { return PEAR::raiseError(_kt("Folder with the same name already exists in the new parent folder")); } // @@ -437,7 +438,7 @@ class KTFolderUtil { DBUtil::startTransaction(); - while (!empty($aRemainingFolders)) { + while (!empty($aRemainingFolders) && $copyAll) { $iFolderId = array_pop($aRemainingFolders); $oFolder = Folder::get($iFolderId); if (PEAR::isError($oFolder) || ($oFolder == false)) { @@ -487,15 +488,18 @@ class KTFolderUtil { $aFolderMap = array(); - $sTable = KTUtil::getTableName('folders'); + $sTable = 'folders'; $sGetQuery = 'SELECT * FROM ' . $sTable . ' WHERE id = ? '; $aParams = array($oSrcFolder->getId()); $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams)); unset($aRow['id']); + + $aRow['name'] = $sDestFolderName; + $aRow['description'] = $sDestFolderName; $aRow['parent_id'] = $oDestFolder->getId(); $aRow['parent_folder_ids'] = sprintf('%s,%s', $oDestFolder->getParentFolderIDs(), $oDestFolder->getId()); $aRow['full_path'] = sprintf('%s/%s', $oDestFolder->getFullPath(), $oDestFolder->getName()); - + $id = DBUtil::autoInsert($sTable, $aRow); if (PEAR::isError($id)) { DBUtil::rollback(); @@ -506,7 +510,7 @@ class KTFolderUtil { $aFolderMap[$sSrcFolderId]['parent_folder_ids'] = $aRow['parent_folder_ids']; $aFolderMap[$sSrcFolderId]['full_path'] = $aRow['full_path']; $aFolderMap[$sSrcFolderId]['name'] = $aRow['name']; - + $oNewBaseFolder = Folder::get($id); $res = $oStorage->createFolder($oNewBaseFolder); if (PEAR::isError($res)) { @@ -517,12 +521,13 @@ class KTFolderUtil { $aRemainingFolders = Folder::getList(array('parent_id = ?', array($oSrcFolder->getId())), array('ids' => true)); - while (!empty($aRemainingFolders)) { + while (!empty($aRemainingFolders) && $copyAll) { $iFolderId = array_pop($aRemainingFolders); $aParams = array($iFolderId); $aRow = DBUtil::getOneResult(array($sGetQuery, $aParams)); unset($aRow['id']); + // since we are nested, we will have solved the parent first. $sPrevParentId = $aRow['parent_id']; $aRow['parent_id'] = $aFolderMap[$aRow['parent_id']]['parent_id']; @@ -552,7 +557,7 @@ class KTFolderUtil { $aCFIds = Folder::getList(array('parent_id = ?', array($iFolderId)), array('ids' => true)); $aRemainingFolders = kt_array_merge($aRemainingFolders, $aCFIds); } - + // now we can go ahead. foreach ($aDocuments as $oDocument) { $oChildDestinationFolder = Folder::get($aFolderMap[$oDocument->getFolderID()]['parent_id']); diff --git a/lib/permissions/permissionutil.inc.php b/lib/permissions/permissionutil.inc.php index 9375520..2ffb6e4 100644 --- a/lib/permissions/permissionutil.inc.php +++ b/lib/permissions/permissionutil.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -52,6 +52,9 @@ require_once(KT_LIB_DIR . "/workflow/workflowutil.inc.php"); require_once(KT_LIB_DIR . "/workflow/workflowstatepermissionsassignment.inc.php"); class KTPermissionUtil { + + static $permArr = array(); + // {{{ generateDescriptor /** * Generate a unique textual representation of a specific collection @@ -93,7 +96,7 @@ class KTPermissionUtil { $oDescriptor =& KTPermissionDescriptor::getByDescriptor(md5($sDescriptor)); if (PEAR::isError($oDescriptor)) { $oOriginalDescriptor = $oDescriptor; - + $oDescriptor =& KTPermissionDescriptor::createFromArray(array( "descriptortext" => $sDescriptor, )); @@ -112,7 +115,7 @@ class KTPermissionUtil { exit(0); } $oDescriptor->saveAllowed($aAllowed); - + } return $oDescriptor; } @@ -193,7 +196,7 @@ class KTPermissionUtil { $sWhere = 'permission_object_id = ?'; $aParams = array($oPO->getID()); $aFolders =& Folder::getList(array($sWhere, $aParams)); - if (!PEAR::isError($aFolders)) { + if (!PEAR::isError($aFolders)) { foreach ($aFolders as $oFolder) { KTPermissionUtil::updatePermissionLookup($oFolder); } @@ -253,7 +256,7 @@ class KTPermissionUtil { } } } - + $oChannel =& KTPermissionChannel::getSingleton(); if (is_a($oFolderOrDocument, 'Folder')) { $msg = sprintf("Updating folder %s", join("/", $oFolderOrDocument->getPathArray())); @@ -265,7 +268,7 @@ class KTPermissionUtil { } } $oChannel->sendMessage(new KTPermissionGenericMessage($msg)); - //var_dump($msg); + //var_dump($msg); $iPermissionObjectId = $oFolderOrDocument->getPermissionObjectID(); if (empty($iPermissionObjectId)) { return; @@ -311,7 +314,7 @@ class KTPermissionUtil { foreach ($aWorkflowStatePermissionAssignments as $oAssignment) { $iPermissionId = $oAssignment->getPermissionId(); $iPermissionDescriptorId = $oAssignment->getDescriptorId(); - + $oPD = KTPermissionDescriptor::get($iPermissionDescriptorId); $aGroupIDs = $oPD->getGroups(); $aUserIDs = array(); @@ -330,16 +333,16 @@ class KTPermissionUtil { $iRoleSourceFolder = null; if (is_a($oFolderOrDocument, 'KTDocumentCore') || is_a($oFolderOrDocument, 'Document')) { $iRoleSourceFolder = $oFolderOrDocument->getFolderID(); } else { $iRoleSourceFolder = $oFolderOrDocument->getId(); } - + // very minor perf win: map role_id (in context) to PD. - $_roleCache = array(); - + $_roleCache = array(); + foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { $aAfterRoles = array(); if (array_key_exists('role', $aAllowed)) { foreach ($aAllowed['role'] as $k => $iRoleId) { // store the PD <-> RoleId map - + // special-case "all" or "authenticated". if (($iRoleId == -3) || ($iRoleId == -4)) { $aAfterRoles[] = $iRoleId; @@ -366,15 +369,15 @@ class KTPermissionUtil { unset($aAllowed['role'][$k]); } - + } - unset($aMapPermAllowed[$iPermissionId]['role']); - if (!empty($aAfterRoles)) { + unset($aMapPermAllowed[$iPermissionId]['role']); + if (!empty($aAfterRoles)) { $aMapPermAllowed[$iPermissionId]['role'] = $aAfterRoles; } } - + /* print '
';
         print '=======' . $oFolderOrDocument->getName();
@@ -382,7 +385,7 @@ class KTPermissionUtil {
         var_dump($aMapPermAllowed);
         print '
'; */ - + $aMapPermDesc = array(); foreach ($aMapPermAllowed as $iPermissionId => $aAllowed) { @@ -404,6 +407,7 @@ class KTPermissionUtil { * and so forth. */ function userHasPermissionOnItem($oUser, $oPermission, $oFolderOrDocument) { + if (is_string($oPermission)) { $oPermission =& KTPermission::getByName($oPermission); } @@ -413,20 +417,44 @@ class KTPermissionUtil { if (PEAR::isError($oFolderOrDocument) || $oFolderOrDocument == null) { return false; } + + // Quick fix for multiple permissions look ups. + // For the current lookup, if the permissions have been checked then return their value + $iPermId = $oPermission->getID(); + $iDocId = $oFolderOrDocument->getID(); + $lookup = 'folders'; + if(is_a($oEntity, 'Document') || is_a($oEntity, 'DocumentProxy')){ + $lookup = 'docs'; + } + // check if permission has been set + // $permArr[permId] = array('folders' => array('id' => bool), 'docs' => array('id' => bool)); + if(isset($permArr[$iPermId][$lookup][$iDocId])){ + return $permArr[$iPermId][$lookup][$iDocId]; + } + + + $oPL = KTPermissionLookup::get($oFolderOrDocument->getPermissionLookupID()); $oPLA = KTPermissionLookupAssignment::getByPermissionAndLookup($oPermission, $oPL); if (PEAR::isError($oPLA)) { //print $oPL->getID(); + $permArr[$iPermId][$lookup][$iDocId] = false; return false; } $oPD = KTPermissionDescriptor::get($oPLA->getPermissionDescriptorID()); - + + // set permission array to true + $permArr[$iPermId][$lookup][$iDocId] = true; + + // check for permissions $aGroups = GroupUtil::listGroupsForUserExpand($oUser); if ($oPD->hasRoles(array(-3))) { return true; } // everyone has access. else if ($oPD->hasUsers(array($oUser))) { return true; } else if ($oPD->hasGroups($aGroups)) { return true; } else if ($oPD->hasRoles(array(-4)) && !$oUser->isAnonymous()) { return true; } - + + // permission isn't true, set to false + $permArr[$iPermId][$lookup][$iDocId] = false; return false; } // }}} @@ -496,7 +524,7 @@ class KTPermissionUtil { 'groupid' => $oOrigDC->getGroupId(), 'conditionid' => $oOrigDC->getConditionId(), )); - + $oNewDC->saveAssignment($oOrigDC->getAssignment()); } @@ -582,7 +610,7 @@ class KTPermissionUtil { $iNewPOID = $oFolder->getPermissionObjectID(); $oNewPO =& KTPermissionObject::get($iNewPOID); - + $oDocumentOrFolder->setPermissionObjectID($iNewPOID); $oDocumentOrFolder->update(); @@ -591,7 +619,7 @@ class KTPermissionUtil { KTPermissionUtil::updatePermissionLookup($oDocumentOrFolder); return; } - + $iFolderID = $oDocumentOrFolder->getID(); $sFolderIDs = Folder::generateFolderIDs($iFolderID); $sFolderIDs .= '%'; diff --git a/lib/session/Session.inc b/lib/session/Session.inc index 99cfcde..e453e54 100644 --- a/lib/session/Session.inc +++ b/lib/session/Session.inc @@ -196,7 +196,7 @@ class Session { if ($default->systemVersion != $version) { if (KTLOG_CACHE) $default->log->info("Session::verify : Database not upgraded"); - return PEAR::raiseError(sprintf(_kt('Incompatible database version (%s, expected version %s) - contact the administrator'), $version, $default->systemVersion)); + return PEAR::raiseError(sprintf(_kt('Database incompatibility error:
Please ensure that you have completed the database upgrade procedure.
Please click here to complete.'),'setup/upgrade.php' )); } if (empty($sessionID)) { diff --git a/lib/util/ktutil.inc b/lib/util/ktutil.inc index ab35f64..ddf6227 100644 --- a/lib/util/ktutil.inc +++ b/lib/util/ktutil.inc @@ -175,10 +175,10 @@ class KTUtil { } //this function fudges the strlen. It returns a ? when the character is a multi-byte character. - //str len is therefore measured correctly. + //str len is therefore measured correctly by counting the ?'s. //http://www.phpwact.org/php/i18n/charsets function utf8_strlen($string){ - return strlen(utf8_decode($str)); + return strlen(utf8_decode($string)); } static function &arrayGet($aArray, $sKey, $mDefault = null, $bDefaultIfEmpty = true) { diff --git a/lib/workflow/workflowutil.inc.php b/lib/workflow/workflowutil.inc.php index bc0b332..900d814 100644 --- a/lib/workflow/workflowutil.inc.php +++ b/lib/workflow/workflowutil.inc.php @@ -5,32 +5,32 @@ * KnowledgeTree Open Source Edition * Document Management Made Simple * Copyright (C) 2004 - 2007 The Jam Warehouse Software (Pty) Limited - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 3 as published by the * Free Software Foundation. - * + * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . - * + * * You can contact The Jam Warehouse Software (Pty) Limited, Unit 1, Tramber Place, * Blake Street, Observatory, 7925 South Africa. or email info@knowledgetree.com. - * + * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU General Public License version 3. - * + * * In accordance with Section 7(b) of the GNU General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by - * KnowledgeTree" logo and retain the original copyright notice. If the display of the + * KnowledgeTree" logo and retain the original copyright notice. If the display of the * logo is not reasonably feasible for technical reasons, the Appropriate Legal Notices - * must display the words "Powered by KnowledgeTree" and retain the original - * copyright notice. + * must display the words "Powered by KnowledgeTree" and retain the original + * copyright notice. * Contributor( s): ______________________________________ * */ @@ -837,7 +837,7 @@ class KTWorkflowUtil { if (PEAR::isError($res)) { return $res; } Document::clearAllCaches(); - KTWorkflowTransition::clearAllCaches(); + KTWorkflowTransition::clearCachedGroups(); } } diff --git a/login.php b/login.php index 9e2afce..c8d89ca 100644 --- a/login.php +++ b/login.php @@ -95,14 +95,24 @@ class LoginPageDispatcher extends KTDispatcher { #var_dump($oUser); #var_dump(PEAR::raiseError()); } + $iOldUserID = checkLastSessionUserID(); + + //if the current person logging in isn't the same person who logged out or timed out + //then set the redirect to the dashboard and not the last page that was viewed. + if ($oUser->getId() != $iOldUserID['user_id']) + { + $_REQUEST['redirect'] = generateControllerLink('dashboard'); + + } + $session = new Session(); $sessionID = $session->create($oUser); if (PEAR::isError($sessionID)) { return $sessionID; } - - $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); - + + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); + // DEPRECATED initialise page-level authorisation array $_SESSION["pageAccess"] = NULL; @@ -145,6 +155,10 @@ class LoginPageDispatcher extends KTDispatcher { header('Content-type: text/html; charset=UTF-8'); $errorMessage = KTUtil::arrayGet($_REQUEST, 'errorMessage'); + session_start(); + + $errorMessageConfirm = $_SESSION['errormessage']['login']; + $redirect = KTUtil::arrayGet($_REQUEST, 'redirect'); $oReg =& KTi18nregistry::getSingleton(); @@ -168,6 +182,7 @@ class LoginPageDispatcher extends KTDispatcher { $aTemplateData = array( "context" => $this, 'errorMessage' => $errorMessage, + 'errorMessageConfirm' => $errorMessageConfirm, 'redirect' => $redirect, 'systemVersion' => $default->systemVersion, 'versionName' => $default->versionName, @@ -322,6 +337,14 @@ class LoginPageDispatcher extends KTDispatcher { } } +//FIXME Direct Database Access +//checkLastSessionUserID finds the last user to logout or timeout +function checkLastSessionUserID() +{ + $sQuery = 'SELECT user_id FROM user_history ORDER BY id DESC LIMIT 1'; + $res = DBUtil::getOneResult($sQuery); + return $res; +} $dispatcher =& new LoginPageDispatcher(); $dispatcher->dispatch(); diff --git a/plugins/housekeeper/HouseKeeperPlugin.php b/plugins/housekeeper/HouseKeeperPlugin.php index 57468b9..1baae44 100644 --- a/plugins/housekeeper/HouseKeeperPlugin.php +++ b/plugins/housekeeper/HouseKeeperPlugin.php @@ -53,7 +53,9 @@ class HouseKeeperPlugin extends KTPlugin $cacheDir = $config->get('cache/cacheDirectory'); $logDir = $config->get('urls/logDirectory'); $docsDir = $config->get('urls/documentRoot'); - $luceneDir = $config->get('indexer/luceneDirectory'); + + $indexer = Indexer::get(); + $luceneDir = $indexer->getIndexDirectory(); $systemDir = OS_UNIX?'/tmp':'c:/windows/temp'; @@ -85,6 +87,8 @@ class HouseKeeperPlugin extends KTPlugin 'canClean'=>true ); + if (is_dir($docsDir)) + { $this->folders[] = array( 'name'=>_kt('KnowledgeTree Documents'), @@ -92,6 +96,10 @@ class HouseKeeperPlugin extends KTPlugin 'pattern'=>'', 'canClean'=>false ); + } + + if (is_dir($luceneDir)) + { $this->folders[] = array( 'name'=>_kt('KnowledgeTree Document Index'), @@ -99,6 +107,7 @@ class HouseKeeperPlugin extends KTPlugin 'pattern'=>'', 'canClean'=>false ); + } } diff --git a/plugins/ktcore/admin/managePermissions.php b/plugins/ktcore/admin/managePermissions.php index 765087f..9bedf9e 100755 --- a/plugins/ktcore/admin/managePermissions.php +++ b/plugins/ktcore/admin/managePermissions.php @@ -44,13 +44,25 @@ require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); class ManagePermissionsDispatcher extends KTAdminDispatcher { var $sHelpPage = 'ktcore/admin/manage permissions.html'; function do_main() { + session_start(); $this->oPage->setTitle(_kt('Manage Permissions')); $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _kt('Manage Permissions')); $add_fields = array(); - $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true); - $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true); + $add_fields[] = new KTStringWidget(_kt('System Name'), _kt('The internal name used for the permission. This should never be changed.'), 'name', null, $this->oPage, true, 'name'); + $add_fields[] = new KTStringWidget(_kt('Display Name'), _kt('A short name that is shown to users whenever permissions must be assigned.'), 'human_name', null, $this->oPage, true, 'human_name'); + if($_SESSION['Permission']['NameValue']) + { + $this->sNameVal = $_SESSION['Permission']['NameValue']; + $_SESSION['Permission']['NameValue'] = ''; + } + else if($_SESSION['Permission']['HumanNameValue']) + { + $this->sHumanNameVal = $_SESSION['Permission']['HumanNameValue']; + $_SESSION['Permission']['HumanNameValue'] = ''; + } + $oTemplating =& KTTemplating::getSingleton(); $aPermissions =& KTPermission::getList(); $oTemplate = $oTemplating->loadTemplate("ktcore/manage_permissions"); @@ -63,17 +75,75 @@ class ManagePermissionsDispatcher extends KTAdminDispatcher { } function do_newPermission() { - $name = KTUtil::arrayGet($_REQUEST, 'name'); - $human_name = KTUtil::arrayGet($_REQUEST, 'human_name'); - if (empty($name) || empty($human_name)) { - return $this->errorRedirectToMain(_kt("Both names not given")); + session_start(); + $sName = KTUtil::arrayGet($_REQUEST, 'name'); + $sHumanName = KTUtil::arrayGet($_REQUEST, 'human_name'); + $sError = 'An error occured while creating your permission'; + + //Checking that the System Name and Display Name fields aren't empty + if (empty($sName) && !empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The System Name was not provided.'; + $_SESSION['Permission']['HumanNameValue'] = $sHumanName; + return $this->errorRedirectToMain(_kt($sError)); } - $oPerm = KTPermission::createFromArray(array( - 'name' => $name, - 'humanname' => $human_name, + else if(!empty($sName) && empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The Display Name was not provided.'; + $_SESSION['Permission']['NameValue'] = $sName; + return $this->errorRedirectToMain(_kt($sError)); + } + else if (empty($sName) && empty($sHumanName)) + { + $sError = 'An error occured while creating your permission: The Display Name and System Name weren\'t provided.'; + return $this->errorRedirectToMain(_kt($sError)); + } + + //Checking that the System Name and Display Name aren't already in the database + $aPermissions = KTPermission::getList(); + //$iNameErrorCount and $iHumanNameErrorCount are used to check whether only one name is duplicated or if two names are duplicated. + $iNameErrorCount = 0; + $iHumanNameErrorCount = 0; + foreach ($aPermissions as $aPermission) + { + if($sName == $aPermission->getName()) + { + $iNameErrorCount ++; + } + if ($sHumanName == $aPermission->getHumanName()) + { + $iHumanNameErrorCount ++; + } + } + if ($iNameErrorCount > 0 && $iHumanNameErrorCount > 0) + { + $sError = 'An error occured while creating your permission: The Display Name and System Name you have provided both already exist.'; + return $this->errorRedirectToMain(_kt($sError)); + } + else if ($iNameErrorCount > 0 && $iHumanNameErrorCount == 0) + { + if(!empty($sHumanName)) + { + $_SESSION['Permission']['HumanNameValue'] = $sHumanName; + } + $sError = 'An error occured while creating your permission: A permission with the same System Name already exists.'; + return $this->errorRedirectToMain(_kt($sError)); + } + else if ($iNameErrorCount == 0 && $iHumanNameErrorCount > 0) + { + if(!empty($sName)) + { + $_SESSION['Permission']['NameValue'] = $sName; + } + $sError = 'An error occured while creating your permission: A permission with the same Display Name already exists.'; + return $this->errorRedirectToMain(_kt($sError)); + } + $oPerm = KTPermission::createFromArray(array( + 'name' => $sName, + 'humanname' => $sHumanName, )); if (PEAR::isError($oPerm)) { - return $this->errorRedirectToMain(_kt("Error creating permission")); + return $this->errorRedirectToMain(_kt($sError)); } return $this->successRedirectToMain(_kt("Permission created")); } diff --git a/plugins/rssplugin/loadFeed.inc.php b/plugins/rssplugin/loadFeed.inc.php index ce3a04f..0153137 100644 --- a/plugins/rssplugin/loadFeed.inc.php +++ b/plugins/rssplugin/loadFeed.inc.php @@ -1,6 +1,6 @@ 0){ + for($i=0;$i'; + echo '
'.$response.'
'; + return; + } + } // Prepare response data to be passed back to page - $reposonse = "

".$aRSSArray[channel][title]."

" . + $response = "

".$aRSSArray[channel][title]."

" . "
" . ""; for($i=0;$i @@ -63,7 +69,7 @@ "; } - $reposonse .= "
".$aRSSArray[items][$i][title]."


"; + $response .= "
"; - echo $reposonse; + echo $response; ?> diff --git a/plugins/rssplugin/rss2array.inc.php b/plugins/rssplugin/rss2array.inc.php index a767a1b..e7fa981 100644 --- a/plugins/rssplugin/rss2array.inc.php +++ b/plugins/rssplugin/rss2array.inc.php @@ -1,7 +1,7 @@ optimise(); -print _kt("Done.") . "\n"; +if ($verbose) print _kt("Done.") . "\n"; ?> \ No newline at end of file diff --git a/search2/indexing/indexerCore.inc.php b/search2/indexing/indexerCore.inc.php index f82443d..c04fb25 100644 --- a/search2/indexing/indexerCore.inc.php +++ b/search2/indexing/indexerCore.inc.php @@ -37,7 +37,7 @@ */ require_once('indexing/extractorCore.inc.php'); - +require_once(KT_DIR . '/plugins/ktcore/scheduler/schedulerUtil.php'); class QueryResultItem { @@ -306,16 +306,14 @@ abstract class Indexer */ protected function __construct() { - $this->extractorCache=array(); - $this->debug=true; - $this->hookCache = array(); - $this->generalHookCache = array(); - $config = KTConfig::getSingleton(); - $this->extractorPath = $config->get('indexer/extractorPath', 'extractors'); - $this->hookPath = $config->get('indexer/extractorHookPath','extractorHooks'); - + $this->extractorCache = array(); + $this->debug = $config->get('indexer/debug', true); + $this->hookCache = array(); + $this->generalHookCache = array(); + $this->extractorPath = $config->get('indexer/extractorPath', 'extractors'); + $this->hookPath = $config->get('indexer/extractorHookPath','extractorHooks'); $this->loadExtractorStatus(); } @@ -383,7 +381,7 @@ abstract class Indexer $sql = "delete from mime_extractors"; DBUtil::runQuery($sql); - $default->log->debug('clearExtractors'); + if ($this->debug) $default->log->debug('clearExtractors'); } /** @@ -453,7 +451,7 @@ abstract class Indexer $sql = "INSERT INTO index_files(document_id, user_id, what) VALUES($document_id, $userid, '$what')"; DBUtil::runQuery($sql); -// if ($this->debug) $default->log->debug("index: Queuing indexing of $document_id"); + $default->log->debug("index: Queuing indexing of $document_id"); } @@ -487,7 +485,7 @@ abstract class Indexer );'; DBUtil::runQuery($sql); - // if ($this->debug) $default->log->debug("clearoutDeleted: remove documents"); + $default->log->debug("Indexer::clearoutDeleted: removed documents from indexing queue that have been deleted"); } @@ -679,7 +677,7 @@ abstract class Indexer { return; } - $default->log->info('checkForRegisteredTypes: start'); + if ($this->debug) $default->log->debug('checkForRegisteredTypes: start'); $date = date('Y-m-d H:i'); $sql = "UPDATE scheduler_tasks SET run_time='$date'"; @@ -701,7 +699,7 @@ abstract class Indexer $default->log->info("checkForRegisteredTypes: disabled '$extractor'"); } - $default->log->info('checkForRegisteredTypes: done'); + if ($this->debug) $default->log->debug('checkForRegisteredTypes: done'); KTUtil::setSystemSetting('mimeTypesRegistered', true); } @@ -728,10 +726,11 @@ abstract class Indexer $this->checkForRegisteredTypes(); - $default->log->info('indexDocuments: start'); + if ($this->debug) $default->log->debug('indexDocuments: start'); if (!$this->doesDiagnosticsPass()) { //unlink($indexLockFile); + if ($this->debug) $default->log->debug('indexDocuments: stopping - diagnostics problem. The dashboard will provide more information.'); return; } @@ -764,6 +763,7 @@ abstract class Indexer if (PEAR::isError($result)) { //unlink($indexLockFile); + if ($this->debug) $default->log->debug('indexDocuments: stopping - db error'); return; } @@ -771,6 +771,7 @@ abstract class Indexer if (count($result) == 0) { //unlink($indexLockFile); + if ($this->debug) $default->log->debug('indexDocuments: stopping - no work to be done'); return; } @@ -804,17 +805,12 @@ abstract class Indexer if ($this->debug) { - $default->log->debug(sprintf(_kt("Indexing docid: %d extension: '%s' mimetype: '%s' extractor: '%s'"), $docId, $extension,$mimeType,$extractorClass)); + if ($this->debug) $default->log->debug(sprintf(_kt("Indexing docid: %d extension: '%s' mimetype: '%s' extractor: '%s'"), $docId, $extension,$mimeType,$extractorClass)); } if (empty($extractorClass)) { - if ($this->debug) - { - $default->log->debug(sprintf(_kt("No extractor for docid: %d"),$docId)); - } - - Indexer::unqueueDocument($docId); + Indexer::unqueueDocument($docId, sprintf(_kt("No extractor for docid: %d"),$docId)); continue; } @@ -867,8 +863,7 @@ abstract class Indexer if (empty($sourceFile) || !is_file($sourceFile)) { - $default->log->error(sprintf(_kt("indexDocuments: source file '%s' for document %d does not exist."),$sourceFile,$docId)); - Indexer::unqueueDocument($docId); + Indexer::unqueueDocument($docId,sprintf(_kt("indexDocuments: source file '%s' for document %d does not exist."),$sourceFile,$docId), 'error'); continue; } @@ -896,10 +891,8 @@ abstract class Indexer $extractor->setDocument($document); $extractor->setIndexingStatus(null); $extractor->setExtractionStatus(null); - if ($this->debug) - { - $default->log->debug(sprintf(_kt("Extra Info docid: %d Source File: '%s' Target File: '%s'"),$docId,$sourceFile,$targetFile)); - } + + if ($this->debug) $default->log->debug(sprintf(_kt("Extra Info docid: %d Source File: '%s' Target File: '%s'"),$docId,$sourceFile,$targetFile)); $this->executeHook($extractor, 'pre_extract'); $this->executeHook($extractor, 'pre_extract', $mimeType); @@ -971,22 +964,32 @@ abstract class Indexer if ($removeFromQueue) { - Indexer::unqueueDocument($docId); + Indexer::unqueueDocument($docId, sprintf(_kt("Done indexing docid: %d"),$docId)); + } + else + { + if ($this->debug) $default->log->debug(sprintf(_kt("Document docid: %d was not removed from the queue as it looks like there was a problem with the extraction process"),$docId)); } - if ($this->debug) - { - $default->log->debug(sprintf(_kt("Done indexing docid: %d"),$docId)); - } - } - $default->log->info('indexDocuments: done'); + if ($this->debug) $default->log->debug('indexDocuments: done'); //unlink($indexLockFile); } public function migrateDocuments($max=null) { + global $default; + + $default->log->info(_kt('migrateDocuments: starting')); + if (!$this->doesDiagnosticsPass(true)) { + $default->log->info(_kt('migrateDocuments: stopping - diagnostics problem. The dashboard will provide more information.')); + return; + } + + if (KTUtil::getSystemSetting('migrationComplete') == 'true') + { + $default->log->info(_kt('migrateDocuments: stopping - migration is complete.')); return; } @@ -996,16 +999,13 @@ abstract class Indexer $max = $config->get('indexer/batchMigrateDocument',500); } - global $default; - $lockFile = $config->get('cache/cacheDirectory') . '/migration.lock'; if (is_file($lockFile)) { - $default->log->info(_kt('migrateDocuments: migration lockfile detected. exiting.')); + $default->log->info(_kt('migrateDocuments: stopping - migration lockfile detected.')); return; } touch($lockFile); - $default->log->info(_kt('migrateDocuments: starting!')); $startTime = KTUtil::getSystemSetting('migrationStarted'); if (is_null($startTime)) @@ -1015,7 +1015,7 @@ abstract class Indexer $maxLoops = 5; - $max = floor($max / $maxLoops); + $max = ceil($max / $maxLoops); $start =KTUtil::getBenchmarkTime(); $noDocs = false; @@ -1033,6 +1033,7 @@ abstract class Indexer $result = DBUtil::getResultArray($sql); if (PEAR::isError($result)) { + $default->log->info(_kt('migrateDocuments: db error')); break; } @@ -1053,7 +1054,7 @@ abstract class Indexer { $sql = "DELETE FROM document_text WHERE document_id=$docId"; DBUtil::runQuery($sql); - $default->log->error(sprintf(_kt('migrateDocuments: Could not get document %d\'s document! Removing content!',$docId))); + $default->log->error(sprintf(_kt('migrateDocuments: Could not get document %d\'s document! Removing content!'),$docId)); continue; } @@ -1094,13 +1095,14 @@ abstract class Indexer KTUtil::setSystemSetting('migrationTime', KTUtil::getSystemSetting('migrationTime',0) + $time); KTUtil::setSystemSetting('migratedDocuments', KTUtil::getSystemSetting('migratedDocuments',0) + $numDocs); - $default->log->info(sprintf(_kt('migrateDocuments: done in %d seconds!'), $time)); + $default->log->info(sprintf(_kt('migrateDocuments: stopping - done in %d seconds!'), $time)); if ($noDocs) { $default->log->info(_kt('migrateDocuments: Completed!')); - KTUtil::setSystemSetting('migrationComplete', true); + KTUtil::setSystemSetting('migrationComplete', 'true'); + schedulerUtil::deleteByName('Index Migration'); + $default->log->debug(_kt('migrateDocuments: Disabling \'Index Migration\' task by removing scheduler entry.')); } - } /** @@ -1176,7 +1178,7 @@ abstract class Indexer if (!$this->isExtractorEnabled($class)) { - $default->log->info(sprintf(_kt("diagnose: extractor '%s' is disabled."), $class)); + $default->log->debug(sprintf(_kt("diagnose: extractor '%s' is disabled."), $class)); continue; } @@ -1263,10 +1265,15 @@ abstract class Indexer * * @param int $docid */ - public static function unqueueDocument($docid) + public static function unqueueDocument($docid, $reason=false, $level='debug') { $sql = "DELETE FROM index_files WHERE document_id=$docid"; DBUtil::runQuery($sql); + if ($reason !== false) + { + global $default; + $default->log->$level("Indexer: removing document $docid from the queue - $reason"); + } } /** @@ -1343,6 +1350,18 @@ abstract class Indexer * @return int */ public abstract function getDocumentsInIndex(); + + /** + * Returns the path to the index directory + * + * @return string + */ + public function getIndexDirectory() + { + $config = KTConfig::getSingleton(); + $directory = $config->get('indexer/luceneDirectory'); + return $directory; + } } ?> \ No newline at end of file diff --git a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php index b354531..b1136a7 100644 --- a/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php +++ b/search2/indexing/indexers/JavaXMLRPCLuceneIndexer.inc.php @@ -250,5 +250,20 @@ class JavaXMLRPCLuceneIndexer extends Indexer return $stats->countDocuments; } + /** + * Returns the path to the index directory + * + * @return string + */ + public function getIndexDirectory() + { + $stats = $this->lucene->getStatistics(); + if ($stats === false || !is_object($stats)) + { + return false; + } + return $stats->indexDirectory; + } + } ?> \ No newline at end of file diff --git a/search2/search/fields/AnyMetadataField.inc.php b/search2/search/fields/AnyMetadataField.inc.php index 5f1fa8d..c6f3fff 100644 --- a/search2/search/fields/AnyMetadataField.inc.php +++ b/search2/search/fields/AnyMetadataField.inc.php @@ -40,7 +40,7 @@ class AnyMetadataField extends DBFieldExpr { public function __construct() { - parent::__construct('id', 'document_fields_link', _kt('Any Metadata')); + parent::__construct('value', 'document_fields_link', _kt('Any Metadata')); $this->setAlias('Metadata'); } diff --git a/search2/search/search.inc.php b/search2/search/search.inc.php index 4ae5136..378a437 100644 --- a/search2/search/search.inc.php +++ b/search2/search/search.inc.php @@ -263,6 +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 @@ -532,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 diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index 1dfc12a..a0aef70 100644 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -582,7 +582,7 @@ UNLOCK TABLES; LOCK TABLES `mime_types` WRITE; /*!40000 ALTER TABLE `mime_types` DISABLE KEYS */; -INSERT INTO `mime_types` VALUES (1,'ai','application/postscript','pdf','Postscript Document',NULL,NULL),(2,'aif','audio/x-aiff',NULL,'',NULL,NULL),(3,'aifc','audio/x-aiff',NULL,'',NULL,NULL),(4,'aiff','audio/x-aiff',NULL,'',NULL,NULL),(5,'asc','text/plain','text','Plain Text',NULL,NULL),(6,'au','audio/basic',NULL,'',NULL,NULL),(7,'avi','video/x-msvideo',NULL,'Video File',NULL,NULL),(8,'bcpio','application/x-bcpio',NULL,'',NULL,NULL),(9,'bin','application/octet-stream',NULL,'Binary File',NULL,NULL),(10,'bmp','image/bmp','image','BMP Image',NULL,NULL),(11,'cdf','application/x-netcdf',NULL,'',NULL,NULL),(12,'class','application/octet-stream',NULL,'',NULL,NULL),(13,'cpio','application/x-cpio',NULL,'',NULL,NULL),(14,'cpt','application/mac-compactpro',NULL,'',NULL,NULL),(15,'csh','application/x-csh',NULL,'',NULL,NULL),(16,'css','text/css',NULL,'',NULL,NULL),(17,'dcr','application/x-director',NULL,'',NULL,NULL),(18,'dir','application/x-director',NULL,'',NULL,NULL),(19,'dms','application/octet-stream',NULL,'',NULL,NULL),(20,'doc','application/msword','word','Word Document',NULL,NULL),(21,'dvi','application/x-dvi',NULL,'',NULL,NULL),(22,'dxr','application/x-director',NULL,'',NULL,NULL),(23,'eps','application/postscript','pdf','Encapsulated Postscript',NULL,NULL),(24,'etx','text/x-setext',NULL,'',NULL,NULL),(25,'exe','application/octet-stream',NULL,'',NULL,NULL),(26,'ez','application/andrew-inset',NULL,'',NULL,NULL),(27,'gif','image/gif','image','GIF Image',NULL,NULL),(28,'gtar','application/x-gtar','compressed','',NULL,NULL),(29,'hdf','application/x-hdf',NULL,'',NULL,NULL),(30,'hqx','application/mac-binhex40',NULL,'',NULL,NULL),(31,'htm','text/html','html','HTML Webpage',NULL,NULL),(32,'html','text/html','html','HTML Webpage',NULL,NULL),(33,'ice','x-conference/x-cooltalk',NULL,'',NULL,NULL),(34,'ief','image/ief','image','',NULL,NULL),(35,'iges','model/iges',NULL,'',NULL,NULL),(36,'igs','model/iges',NULL,'',NULL,NULL),(37,'jpe','image/jpeg','image','JPEG Image',NULL,NULL),(38,'jpeg','image/jpeg','image','JPEG Image',NULL,NULL),(39,'jpg','image/jpeg','image','JPEG Image',NULL,NULL),(40,'js','application/x-javascript','html','',NULL,NULL),(41,'kar','audio/midi',NULL,'',NULL,NULL),(42,'latex','application/x-latex',NULL,'',NULL,NULL),(43,'lha','application/octet-stream',NULL,'',NULL,NULL),(44,'lzh','application/octet-stream',NULL,'',NULL,NULL),(45,'man','application/x-troff-man',NULL,'',NULL,NULL),(46,'mdb','application/access','database','Access Database',NULL,NULL),(47,'mdf','application/access','database','Access Database',NULL,NULL),(48,'me','application/x-troff-me',NULL,'',NULL,NULL),(49,'mesh','model/mesh',NULL,'',NULL,NULL),(50,'mid','audio/midi',NULL,'',NULL,NULL),(51,'midi','audio/midi',NULL,'',NULL,NULL),(52,'mif','application/vnd.mif',NULL,'',NULL,NULL),(53,'mov','video/quicktime',NULL,'Video File',NULL,NULL),(54,'movie','video/x-sgi-movie',NULL,'Video File',NULL,NULL),(55,'mp2','audio/mpeg',NULL,'',NULL,NULL),(56,'mp3','audio/mpeg',NULL,'',NULL,NULL),(57,'mpe','video/mpeg',NULL,'Video File',NULL,NULL),(58,'mpeg','video/mpeg',NULL,'Video File',NULL,NULL),(59,'mpg','video/mpeg',NULL,'Video File',NULL,NULL),(60,'mpga','audio/mpeg',NULL,'',NULL,NULL),(61,'mpp','application/vnd.ms-project','office','',NULL,NULL),(62,'ms','application/x-troff-ms',NULL,'',NULL,NULL),(63,'msh','model/mesh',NULL,'',NULL,NULL),(64,'nc','application/x-netcdf',NULL,'',NULL,NULL),(65,'oda','application/oda',NULL,'',NULL,NULL),(66,'pbm','image/x-portable-bitmap','image','',NULL,NULL),(67,'pdb','chemical/x-pdb',NULL,'',NULL,NULL),(68,'pdf','application/pdf','pdf','Acrobat PDF',NULL,NULL),(69,'pgm','image/x-portable-graymap','image','',NULL,NULL),(70,'pgn','application/x-chess-pgn',NULL,'',NULL,NULL),(71,'png','image/png','image','JPEG Image',NULL,NULL),(72,'pnm','image/x-portable-anymap','image','',NULL,NULL),(73,'ppm','image/x-portable-pixmap','image','',NULL,NULL),(74,'ppt','application/vnd.ms-powerpoint','office','Powerpoint Presentation',NULL,NULL),(75,'ps','application/postscript','pdf','Postscript Document',NULL,NULL),(76,'qt','video/quicktime',NULL,'Video File',NULL,NULL),(77,'ra','audio/x-realaudio',NULL,'',NULL,NULL),(78,'ram','audio/x-pn-realaudio',NULL,'',NULL,NULL),(79,'ras','image/x-cmu-raster','image','',NULL,NULL),(80,'rgb','image/x-rgb','image','',NULL,NULL),(81,'rm','audio/x-pn-realaudio',NULL,'',NULL,NULL),(82,'roff','application/x-troff',NULL,'',NULL,NULL),(83,'rpm','audio/x-pn-realaudio-plugin',NULL,'',NULL,NULL),(84,'rtf','text/rtf',NULL,'',NULL,NULL),(85,'rtx','text/richtext',NULL,'',NULL,NULL),(86,'sgm','text/sgml',NULL,'',NULL,NULL),(87,'sgml','text/sgml',NULL,'',NULL,NULL),(88,'sh','application/x-sh',NULL,'',NULL,NULL),(89,'shar','application/x-shar',NULL,'',NULL,NULL),(90,'silo','model/mesh',NULL,'',NULL,NULL),(91,'sit','application/x-stuffit',NULL,'',NULL,NULL),(92,'skd','application/x-koan',NULL,'',NULL,NULL),(93,'skm','application/x-koan',NULL,'',NULL,NULL),(94,'skp','application/x-koan',NULL,'',NULL,NULL),(95,'skt','application/x-koan',NULL,'',NULL,NULL),(96,'smi','application/smil',NULL,'',NULL,NULL),(97,'smil','application/smil',NULL,'',NULL,NULL),(98,'snd','audio/basic',NULL,'',NULL,NULL),(99,'spl','application/x-futuresplash',NULL,'',NULL,NULL),(100,'src','application/x-wais-source',NULL,'',NULL,NULL),(101,'sv4cpio','application/x-sv4cpio',NULL,'',NULL,NULL),(102,'sv4crc','application/x-sv4crc',NULL,'',NULL,NULL),(103,'swf','application/x-shockwave-flash',NULL,'',NULL,NULL),(104,'t','application/x-troff',NULL,'',NULL,NULL),(105,'tar','application/x-tar','compressed','Tar or Compressed Tar File',NULL,NULL),(106,'tcl','application/x-tcl',NULL,'',NULL,NULL),(107,'tex','application/x-tex',NULL,'',NULL,NULL),(108,'texi','application/x-texinfo',NULL,'',NULL,NULL),(109,'texinfo','application/x-texinfo',NULL,'',NULL,NULL),(110,'tif','image/tiff','image','TIFF Image',NULL,NULL),(111,'tiff','image/tiff','image','TIFF Image',NULL,NULL),(112,'tr','application/x-troff',NULL,'',NULL,NULL),(113,'tsv','text/tab-separated-values',NULL,'',NULL,NULL),(114,'txt','text/plain','text','Plain Text',NULL,NULL),(115,'ustar','application/x-ustar',NULL,'',NULL,NULL),(116,'vcd','application/x-cdlink',NULL,'',NULL,NULL),(117,'vrml','model/vrml',NULL,'',NULL,NULL),(118,'vsd','application/vnd.visio','office','',NULL,NULL),(119,'wav','audio/x-wav',NULL,'',NULL,NULL),(120,'wrl','model/vrml',NULL,'',NULL,NULL),(121,'xbm','image/x-xbitmap','image','',NULL,NULL),(122,'xls','application/vnd.ms-excel','excel','Excel Spreadsheet',NULL,NULL),(123,'xml','text/xml',NULL,'',NULL,NULL),(124,'xpm','image/x-xpixmap','image','',NULL,NULL),(125,'xwd','image/x-xwindowdump','image','',NULL,NULL),(126,'xyz','chemical/x-pdb',NULL,'',NULL,NULL),(127,'zip','application/zip','compressed','ZIP Compressed File',NULL,NULL),(128,'gz','application/x-gzip','compressed','GZIP Compressed File',NULL,NULL),(129,'tgz','application/x-gzip','compressed','Tar or Compressed Tar File',NULL,NULL),(130,'sxw','application/vnd.sun.xml.writer','openoffice','OpenOffice.org Writer Document',NULL,NULL),(131,'stw','application/vnd.sun.xml.writer.template','openoffice','OpenOffice.org File',NULL,NULL),(132,'sxc','application/vnd.sun.xml.calc','openoffice','OpenOffice.org Spreadsheet',NULL,NULL),(133,'stc','application/vnd.sun.xml.calc.template','openoffice','OpenOffice.org File',NULL,NULL),(134,'sxd','application/vnd.sun.xml.draw','openoffice','OpenOffice.org File',NULL,NULL),(135,'std','application/vnd.sun.xml.draw.template','openoffice','OpenOffice.org File',NULL,NULL),(136,'sxi','application/vnd.sun.xml.impress','openoffice','OpenOffice.org Presentation',NULL,NULL),(137,'sti','application/vnd.sun.xml.impress.template','openoffice','OpenOffice.org File',NULL,NULL),(138,'sxg','application/vnd.sun.xml.writer.global','openoffice','OpenOffice.org File',NULL,NULL),(139,'sxm','application/vnd.sun.xml.math','openoffice','OpenOffice.org File',NULL,NULL),(140,'xlt','application/vnd.ms-excel','excel','Excel Template',NULL,NULL),(141,'dot','application/msword','word','Word Template',NULL,NULL),(142,'bz2','application/x-bzip2','compressed','BZIP2 Compressed File',NULL,NULL),(143,'diff','text/plain','text','Source Diff File',NULL,NULL),(144,'patch','text/plain','text','Patch File',NULL,NULL),(145,'odt','application/vnd.oasis.opendocument.text','opendocument','OpenDocument Text',NULL,NULL),(146,'ott','application/vnd.oasis.opendocument.text-template','opendocument','OpenDocument Text Template',NULL,NULL),(147,'oth','application/vnd.oasis.opendocument.text-web','opendocument','HTML Document Template',NULL,NULL),(148,'odm','application/vnd.oasis.opendocument.text-master','opendocument','OpenDocument Master Document',NULL,NULL),(149,'odg','application/vnd.oasis.opendocument.graphics','opendocument','OpenDocument Drawing',NULL,NULL),(150,'otg','application/vnd.oasis.opendocument.graphics-template','opendocument','OpenDocument Drawing Template',NULL,NULL),(151,'odp','application/vnd.oasis.opendocument.presentation','opendocument','OpenDocument Presentation',NULL,NULL),(152,'otp','application/vnd.oasis.opendocument.presentation-template','opendocument','OpenDocument Presentation Template',NULL,NULL),(153,'ods','application/vnd.oasis.opendocument.spreadsheet','opendocument','OpenDocument Spreadsheet',NULL,NULL),(154,'ots','application/vnd.oasis.opendocument.spreadsheet-template','opendocument','OpenDocument Spreadsheet Template',NULL,NULL),(155,'odc','application/vnd.oasis.opendocument.chart','opendocument','OpenDocument Chart',NULL,NULL),(156,'odf','application/vnd.oasis.opendocument.formula','opendocument','OpenDocument Formula',NULL,NULL),(157,'odb','application/vnd.oasis.opendocument.database','opendocument','OpenDocument Database',NULL,NULL),(158,'odi','application/vnd.oasis.opendocument.image','opendocument','OpenDocument Image',NULL,NULL),(159,'zip','application/x-zip','compressed','ZIP Compressed File',NULL,NULL),(160,'csv','text/csv','spreadsheet','Comma delimited spreadsheet',NULL,NULL),(161,'msi','application/msword','compressed','MSI Installer file',NULL,NULL),(162,'pps','application/vnd.ms-powerpoint','office','Powerpoint Presentation',NULL,NULL); +INSERT INTO `mime_types` VALUES (1,'ai','application/postscript','pdf','Postscript Document',NULL,NULL),(2,'aif','audio/x-aiff',NULL,'',NULL,NULL),(3,'aifc','audio/x-aiff',NULL,'',NULL,NULL),(4,'aiff','audio/x-aiff',NULL,'',NULL,NULL),(5,'asc','text/plain','text','Plain Text',NULL,NULL),(6,'au','audio/basic',NULL,'',NULL,NULL),(7,'avi','video/x-msvideo',NULL,'Video File',NULL,NULL),(8,'bcpio','application/x-bcpio',NULL,'',NULL,NULL),(9,'bin','application/octet-stream',NULL,'Binary File',NULL,NULL),(10,'bmp','image/bmp','image','BMP Image',NULL,NULL),(11,'cdf','application/x-netcdf',NULL,'',NULL,NULL),(12,'class','application/octet-stream',NULL,'',NULL,NULL),(13,'cpio','application/x-cpio',NULL,'',NULL,NULL),(14,'cpt','application/mac-compactpro',NULL,'',NULL,NULL),(15,'csh','application/x-csh',NULL,'',NULL,NULL),(16,'css','text/css',NULL,'',NULL,NULL),(17,'dcr','application/x-director',NULL,'',NULL,NULL),(18,'dir','application/x-director',NULL,'',NULL,NULL),(19,'dms','application/octet-stream',NULL,'',NULL,NULL),(20,'doc','application/msword','word','Word Document',NULL,NULL),(21,'dvi','application/x-dvi',NULL,'',NULL,NULL),(22,'dxr','application/x-director',NULL,'',NULL,NULL),(23,'eps','application/postscript','pdf','Encapsulated Postscript',NULL,NULL),(24,'etx','text/x-setext',NULL,'',NULL,NULL),(25,'exe','application/octet-stream',NULL,'',NULL,NULL),(26,'ez','application/andrew-inset',NULL,'',NULL,NULL),(27,'gif','image/gif','image','GIF Image',NULL,NULL),(28,'gtar','application/x-gtar','compressed','',NULL,NULL),(29,'hdf','application/x-hdf',NULL,'',NULL,NULL),(30,'hqx','application/mac-binhex40',NULL,'',NULL,NULL),(31,'htm','text/html','html','HTML Webpage',NULL,NULL),(32,'html','text/html','html','HTML Webpage',NULL,NULL),(33,'ice','x-conference/x-cooltalk',NULL,'',NULL,NULL),(34,'ief','image/ief','image','',NULL,NULL),(35,'iges','model/iges',NULL,'',NULL,NULL),(36,'igs','model/iges',NULL,'',NULL,NULL),(37,'jpe','image/jpeg','image','JPEG Image',NULL,NULL),(38,'jpeg','image/jpeg','image','JPEG Image',NULL,NULL),(39,'jpg','image/jpeg','image','JPEG Image',NULL,NULL),(40,'js','application/x-javascript','html','',NULL,NULL),(41,'kar','audio/midi',NULL,'',NULL,NULL),(42,'latex','application/x-latex',NULL,'',NULL,NULL),(43,'lha','application/octet-stream',NULL,'',NULL,NULL),(44,'lzh','application/octet-stream',NULL,'',NULL,NULL),(45,'man','application/x-troff-man',NULL,'',NULL,NULL),(46,'mdb','application/access','database','Access Database',NULL,NULL),(47,'mdf','application/access','database','Access Database',NULL,NULL),(48,'me','application/x-troff-me',NULL,'',NULL,NULL),(49,'mesh','model/mesh',NULL,'',NULL,NULL),(50,'mid','audio/midi',NULL,'',NULL,NULL),(51,'midi','audio/midi',NULL,'',NULL,NULL),(52,'mif','application/vnd.mif',NULL,'',NULL,NULL),(53,'mov','video/quicktime',NULL,'Video File',NULL,NULL),(54,'movie','video/x-sgi-movie',NULL,'Video File',NULL,NULL),(55,'mp2','audio/mpeg',NULL,'',NULL,NULL),(56,'mp3','audio/mpeg',NULL,'',NULL,NULL),(57,'mpe','video/mpeg',NULL,'Video File',NULL,NULL),(58,'mpeg','video/mpeg',NULL,'Video File',NULL,NULL),(59,'mpg','video/mpeg',NULL,'Video File',NULL,NULL),(60,'mpga','audio/mpeg',NULL,'',NULL,NULL),(61,'mpp','application/vnd.ms-project','office','',NULL,NULL),(62,'ms','application/x-troff-ms',NULL,'',NULL,NULL),(63,'msh','model/mesh',NULL,'',NULL,NULL),(64,'nc','application/x-netcdf',NULL,'',NULL,NULL),(65,'oda','application/oda',NULL,'',NULL,NULL),(66,'pbm','image/x-portable-bitmap','image','',NULL,NULL),(67,'pdb','chemical/x-pdb',NULL,'',NULL,NULL),(68,'pdf','application/pdf','pdf','Acrobat PDF',NULL,NULL),(69,'pgm','image/x-portable-graymap','image','',NULL,NULL),(70,'pgn','application/x-chess-pgn',NULL,'',NULL,NULL),(71,'png','image/png','image','PNG Image',NULL,NULL),(72,'pnm','image/x-portable-anymap','image','',NULL,NULL),(73,'ppm','image/x-portable-pixmap','image','',NULL,NULL),(74,'ppt','application/vnd.ms-powerpoint','office','Powerpoint Presentation',NULL,NULL),(75,'ps','application/postscript','pdf','Postscript Document',NULL,NULL),(76,'qt','video/quicktime',NULL,'Video File',NULL,NULL),(77,'ra','audio/x-realaudio',NULL,'',NULL,NULL),(78,'ram','audio/x-pn-realaudio',NULL,'',NULL,NULL),(79,'ras','image/x-cmu-raster','image','',NULL,NULL),(80,'rgb','image/x-rgb','image','',NULL,NULL),(81,'rm','audio/x-pn-realaudio',NULL,'',NULL,NULL),(82,'roff','application/x-troff',NULL,'',NULL,NULL),(83,'rpm','audio/x-pn-realaudio-plugin',NULL,'',NULL,NULL),(84,'rtf','text/rtf',NULL,'',NULL,NULL),(85,'rtx','text/richtext',NULL,'',NULL,NULL),(86,'sgm','text/sgml',NULL,'',NULL,NULL),(87,'sgml','text/sgml',NULL,'',NULL,NULL),(88,'sh','application/x-sh',NULL,'',NULL,NULL),(89,'shar','application/x-shar',NULL,'',NULL,NULL),(90,'silo','model/mesh',NULL,'',NULL,NULL),(91,'sit','application/x-stuffit',NULL,'',NULL,NULL),(92,'skd','application/x-koan',NULL,'',NULL,NULL),(93,'skm','application/x-koan',NULL,'',NULL,NULL),(94,'skp','application/x-koan',NULL,'',NULL,NULL),(95,'skt','application/x-koan',NULL,'',NULL,NULL),(96,'smi','application/smil',NULL,'',NULL,NULL),(97,'smil','application/smil',NULL,'',NULL,NULL),(98,'snd','audio/basic',NULL,'',NULL,NULL),(99,'spl','application/x-futuresplash',NULL,'',NULL,NULL),(100,'src','application/x-wais-source',NULL,'',NULL,NULL),(101,'sv4cpio','application/x-sv4cpio',NULL,'',NULL,NULL),(102,'sv4crc','application/x-sv4crc',NULL,'',NULL,NULL),(103,'swf','application/x-shockwave-flash',NULL,'',NULL,NULL),(104,'t','application/x-troff',NULL,'',NULL,NULL),(105,'tar','application/x-tar','compressed','Tar or Compressed Tar File',NULL,NULL),(106,'tcl','application/x-tcl',NULL,'',NULL,NULL),(107,'tex','application/x-tex',NULL,'',NULL,NULL),(108,'texi','application/x-texinfo',NULL,'',NULL,NULL),(109,'texinfo','application/x-texinfo',NULL,'',NULL,NULL),(110,'tif','image/tiff','image','TIFF Image',NULL,NULL),(111,'tiff','image/tiff','image','TIFF Image',NULL,NULL),(112,'tr','application/x-troff',NULL,'',NULL,NULL),(113,'tsv','text/tab-separated-values',NULL,'',NULL,NULL),(114,'txt','text/plain','text','Plain Text',NULL,NULL),(115,'ustar','application/x-ustar',NULL,'',NULL,NULL),(116,'vcd','application/x-cdlink',NULL,'',NULL,NULL),(117,'vrml','model/vrml',NULL,'',NULL,NULL),(118,'vsd','application/vnd.visio','office','',NULL,NULL),(119,'wav','audio/x-wav',NULL,'',NULL,NULL),(120,'wrl','model/vrml',NULL,'',NULL,NULL),(121,'xbm','image/x-xbitmap','image','',NULL,NULL),(122,'xls','application/vnd.ms-excel','excel','Excel Spreadsheet',NULL,NULL),(123,'xml','text/xml',NULL,'',NULL,NULL),(124,'xpm','image/x-xpixmap','image','',NULL,NULL),(125,'xwd','image/x-xwindowdump','image','',NULL,NULL),(126,'xyz','chemical/x-pdb',NULL,'',NULL,NULL),(127,'zip','application/zip','compressed','ZIP Compressed File',NULL,NULL),(128,'gz','application/x-gzip','compressed','GZIP Compressed File',NULL,NULL),(129,'tgz','application/x-gzip','compressed','Tar or Compressed Tar File',NULL,NULL),(130,'sxw','application/vnd.sun.xml.writer','openoffice','OpenOffice.org Writer Document',NULL,NULL),(131,'stw','application/vnd.sun.xml.writer.template','openoffice','OpenOffice.org File',NULL,NULL),(132,'sxc','application/vnd.sun.xml.calc','openoffice','OpenOffice.org Spreadsheet',NULL,NULL),(133,'stc','application/vnd.sun.xml.calc.template','openoffice','OpenOffice.org File',NULL,NULL),(134,'sxd','application/vnd.sun.xml.draw','openoffice','OpenOffice.org File',NULL,NULL),(135,'std','application/vnd.sun.xml.draw.template','openoffice','OpenOffice.org File',NULL,NULL),(136,'sxi','application/vnd.sun.xml.impress','openoffice','OpenOffice.org Presentation',NULL,NULL),(137,'sti','application/vnd.sun.xml.impress.template','openoffice','OpenOffice.org File',NULL,NULL),(138,'sxg','application/vnd.sun.xml.writer.global','openoffice','OpenOffice.org File',NULL,NULL),(139,'sxm','application/vnd.sun.xml.math','openoffice','OpenOffice.org File',NULL,NULL),(140,'xlt','application/vnd.ms-excel','excel','Excel Template',NULL,NULL),(141,'dot','application/msword','word','Word Template',NULL,NULL),(142,'bz2','application/x-bzip2','compressed','BZIP2 Compressed File',NULL,NULL),(143,'diff','text/plain','text','Source Diff File',NULL,NULL),(144,'patch','text/plain','text','Patch File',NULL,NULL),(145,'odt','application/vnd.oasis.opendocument.text','opendocument','OpenDocument Text',NULL,NULL),(146,'ott','application/vnd.oasis.opendocument.text-template','opendocument','OpenDocument Text Template',NULL,NULL),(147,'oth','application/vnd.oasis.opendocument.text-web','opendocument','HTML Document Template',NULL,NULL),(148,'odm','application/vnd.oasis.opendocument.text-master','opendocument','OpenDocument Master Document',NULL,NULL),(149,'odg','application/vnd.oasis.opendocument.graphics','opendocument','OpenDocument Drawing',NULL,NULL),(150,'otg','application/vnd.oasis.opendocument.graphics-template','opendocument','OpenDocument Drawing Template',NULL,NULL),(151,'odp','application/vnd.oasis.opendocument.presentation','opendocument','OpenDocument Presentation',NULL,NULL),(152,'otp','application/vnd.oasis.opendocument.presentation-template','opendocument','OpenDocument Presentation Template',NULL,NULL),(153,'ods','application/vnd.oasis.opendocument.spreadsheet','opendocument','OpenDocument Spreadsheet',NULL,NULL),(154,'ots','application/vnd.oasis.opendocument.spreadsheet-template','opendocument','OpenDocument Spreadsheet Template',NULL,NULL),(155,'odc','application/vnd.oasis.opendocument.chart','opendocument','OpenDocument Chart',NULL,NULL),(156,'odf','application/vnd.oasis.opendocument.formula','opendocument','OpenDocument Formula',NULL,NULL),(157,'odb','application/vnd.oasis.opendocument.database','opendocument','OpenDocument Database',NULL,NULL),(158,'odi','application/vnd.oasis.opendocument.image','opendocument','OpenDocument Image',NULL,NULL),(159,'zip','application/x-zip','compressed','ZIP Compressed File',NULL,NULL),(160,'csv','text/csv','spreadsheet','Comma delimited spreadsheet',NULL,NULL),(161,'msi','application/msword','compressed','MSI Installer file',NULL,NULL),(162,'pps','application/vnd.ms-powerpoint','office','Powerpoint Presentation',NULL,NULL); /*!40000 ALTER TABLE `mime_types` ENABLE KEYS */; UNLOCK TABLES; @@ -794,7 +794,10 @@ UNLOCK TABLES; LOCK TABLES `scheduler_tasks` WRITE; /*!40000 ALTER TABLE `scheduler_tasks` DISABLE KEYS */; -INSERT INTO `scheduler_tasks` VALUES (1,'Indexing','../bin/indexingTask.sh','',0,'1min','2007-10-01',NULL,0),(2,'Index Migration','../bin/indexMigrationTask.sh','',0,'5mins','2007-10-01',NULL,0),(3,'Index Optimisation','../bin/optimizeIndexes.sh','',0,'weekly','2007-10-01',NULL,0); +INSERT INTO `scheduler_tasks` VALUES +(1,'Indexing','search2/indexing/bin/cronIndexer.php','',0,'1min','2007-10-01',NULL,0), +(2,'Index Migration','search2/indexing/bin/cronMigration.php','',0,'5mins','2007-10-01',NULL,0), +(3,'Index Optimisation','search2/indexing/bin/optimise.php','',0,'weekly','2007-10-01',NULL,0); /*!40000 ALTER TABLE `scheduler_tasks` ENABLE KEYS */; UNLOCK TABLES; diff --git a/templates/ktcore/login.smarty b/templates/ktcore/login.smarty index 3779a09..b996414 100644 --- a/templates/ktcore/login.smarty +++ b/templates/ktcore/login.smarty @@ -30,7 +30,13 @@ {if ($errorMessage == null)}

{i18n}Please enter your details below to login.{/i18n}

{else} -
{$errorMessage|sanitize}
+
+ {if ($errorMessage == $errorMessageConfirm)} + {$errorMessage} + {else} + {$errorMessage|sanitize} + {/if} +
{/if} @@ -54,9 +60,15 @@ {/if}

- {i18n}Access to this service is subject to the KnowledgeTreeLive Terms and Conditions of use.{/i18n}
- {i18n}© 2007 The Jam Warehouse Software (Pty) Ltd. All Rights Reserved{/i18n} -

+ {i18n arg_appname="$appname"}#appname# Version{/i18n} {$versionName}
+ {i18n}Document Management Software{/i18n}
+ {i18n}© 2007 The Jam Warehouse Software (Pty) Ltd.{/i18n}

+ {if ($smallVersion == 'OSS')} + {i18n}This program is free software and published under the GNU General Public License version 3{/i18n}
+ {else} + {i18n}All rights reserved.{/i18n}
+ {/if} +

diff --git a/templates/ktcore/manage_permissions.smarty b/templates/ktcore/manage_permissions.smarty index 7ccc6b6..08e4671 100644 --- a/templates/ktcore/manage_permissions.smarty +++ b/templates/ktcore/manage_permissions.smarty @@ -1,3 +1,11 @@ +{literal} + +{/literal}

{i18n}Existing permissions{/i18n}

{i18n}Permissions are descriptors used to ascertain whether groups of users have access to certain functionality. The built-in permissions below facilitate the default functionality of the DMS and can't be changed. Plugin developers may choose to add additional permissions below that manage access to their plugins functionality.{/i18n}

@@ -54,4 +62,13 @@ class="ktAction ktDelete">{i18n}Delete Permission{/i18n} { /foreach } - +{if $context->sNameVal != ''} + +{/if} +{if $context->sHumanNameVal != ''} + +{/if} \ No newline at end of file diff --git a/templates/ktcore/search2/adv_query_builder.smarty b/templates/ktcore/search2/adv_query_builder.smarty index 7ae92ec..540a5e1 100644 --- a/templates/ktcore/search2/adv_query_builder.smarty +++ b/templates/ktcore/search2/adv_query_builder.smarty @@ -219,7 +219,7 @@ function initInt(groupid, fid) var nf = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: startname}); nf.render(startname); - var nf2 = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: startname}); + var nf2 = new Ext.form.NumberField( {allowNegative: false, decimalPrecision : 0, name: endname}); nf2.render(endname); } @@ -721,6 +721,7 @@ function buildExpression() var expr = expr = fieldname + ' ' + fieldop + ' "' + start.value + '"'; switch (fieldop) { + case 'between': case 'BETWEEN': expr += ' AND "' + end.value + '"'; break; diff --git a/templates/ktcore/search2/lucene_statistics.smarty b/templates/ktcore/search2/lucene_statistics.smarty index 1fc1c54..7bb15e0 100644 --- a/templates/ktcore/search2/lucene_statistics.smarty +++ b/templates/ktcore/search2/lucene_statistics.smarty @@ -1,26 +1,117 @@ -

-{i18n}This dashlet provides some basic statistics from the KnowledgeTree Document Indexer.{/i18n} -

+ + +{literal} + +{/literal} + + + - - - - - - - - - + + + + + + + + + + + + +
{i18n}Last optimisation date:{/i18n}{$stats.optimisationDate}
{i18n}Period since last optimisation:{/i18n}{$stats.optimisationPeriod}
{i18n}Last indexing date:{/i18n}{$stats.indexingDate}
{i18n}Period since last indexing:{/i18n}{$stats.indexingPeriod}
{i18n}Total documents in repository:{/i18n}{$stats.docsInRepository}
{i18n}Documents in index:{/i18n}{$stats.docsInIndex}
{i18n}Documents in indexing queue:{/i18n}{$stats.docsInQueue}
{i18n}Indexing coverage:{/i18n}{$stats.indexingCoverage}
{i18n}Queue coverage:{/i18n}{$stats.queueCoverage}
{i18n}Last Optimization Date:{/i18n}{$stats.optimisationDate}
{i18n}Period Since Last Optimization:{/i18n}{$stats.optimisationPeriod}
{i18n}Last Indexing Date:{/i18n}{$stats.indexingDate}
{i18n}Period Since Last Indexing:{/i18n}{$stats.indexingPeriod}
{i18n}Total # Documents in Repository:{/i18n}{$stats.docsInRepository}
{i18n}Documents Indexed:{/i18n}{$stats.docsInIndex}
{i18n}Documents in Indexing Queue:{/i18n}{$stats.docsInQueue}
+

+ +Index Coverage: +

+

+ +Index Coverage: +

+
+
{$stats.indexingCoverage}
+

+ +Queue Coverage: +

+

+ +Queue Coverage: +

+
+ +
{$stats.queueCoverage}
-{i18n}Notes:{/i18n}
+ -
*{i18n}Not all documents contain text. This will explain why the indexing coverage percentage my vary.{/i18n} -
*{i18n}The queue coverage indicates how many documents are in the queue in relation to the repository size.{/i18n} + {if $stats.noOptimisation}
*{i18n}To get the best performance out of Document Indexer, the indexes must be optimised periodically. This is managed by a background task.{/i18n} {/if}
-
{i18n}Refresh{/i18n}
\ No newline at end of file + + + + + + \ No newline at end of file -- libgit2 0.21.4