diff --git a/config/dmsDefaults.php b/config/dmsDefaults.php index 81fdf00..0715aa3 100644 --- a/config/dmsDefaults.php +++ b/config/dmsDefaults.php @@ -7,7 +7,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * 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 @@ -47,7 +47,7 @@ if (defined('DMS_DEFAULTS_INCLUDED')) } define('DMS_DEFAULTS_INCLUDED',1); -define('LATEST_WEBSERVICE_VERSION',2); +define('LATEST_WEBSERVICE_VERSION',3); if (function_exists('apd_set_pprof_trace')) { @@ -483,7 +483,7 @@ class KTInit { function initConfig() { global $default; $oKTConfig = KTConfig::getSingleton(); - + // Override the config setting - KT_DIR is resolved on page load $oKTConfig->setdefaultns('KnowledgeTree', 'fileSystemRoot', KT_DIR); diff --git a/ktwebservice/KTUploadManager.inc.php b/ktwebservice/KTUploadManager.inc.php index eb1b7cd..546ca47 100644 --- a/ktwebservice/KTUploadManager.inc.php +++ b/ktwebservice/KTUploadManager.inc.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * 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 @@ -110,7 +110,7 @@ class KTUploadManager return ($tempdir == $this->temp_dir); */ } - + function store_base64_file($base64, $prefix= 'sa_') { $tempfilename = $this->get_temp_filename($prefix); @@ -134,9 +134,9 @@ class KTUploadManager return $tempfilename; } - + /** - * + * * @param string $content file content NOT base64 encoded (may be string, may be binary) * @param string $prefix [optional] * @return $tempfilename the name of the temporary file created @@ -172,7 +172,7 @@ class KTUploadManager * @param string $tempfile * @param string $action */ - function uploaded($filename, $tempfile, $action, $relatedid = null) + function uploaded($filename, $tempfile, $action, $unique_file_id = null) { $filename=basename($filename); $now=date('Y-m-d H:i:s'); @@ -190,6 +190,11 @@ class KTUploadManager $newtempfile = str_replace('\\','/',$newtempfile); } + if(!empty($unique_file_id) && !$this->check_unique_id($unique_file_id)){ + // If the unique_file_id is not unique then return an error + return PEAR::raiseError(_kt('Unique file id already exists.')); + } + DBUtil::startTransaction(); $id = DBUtil::autoInsert('uploaded_files', array( @@ -198,7 +203,7 @@ class KTUploadManager 'userid'=>$_SESSION['userID'], 'uploaddate'=>$now, 'action'=>$action, - // 'related_uploadid'=>$relatedid + 'unique_file_id'=>$unique_file_id ), array('noid'=>true) ); @@ -232,6 +237,42 @@ class KTUploadManager } /** + * Ensure the unique file id is unique for the uploaded file + * + * @param string $unique_file_id + * @return bool + */ + private function check_unique_id($unique_file_id) + { + $unique = addslashes($unique_file_id); + $sql = "SELECT tempfilename FROM uploaded_files WHERE unique_file_id = '$unique'"; + $result = DBUtil::getResultArray($sql); + + if(PEAR::isError($result) || empty($result)){ + return true; + } + + return false; + } + + function get_tempfile_from_unique_id($unique_file_id) + { + $unique = addslashes($unique_file_id); + $sql = "SELECT tempfilename FROM uploaded_files WHERE unique_file_id = '$unique'"; + $result = DBUtil::getResultArray($sql); + + if(PEAR::isError($result)){ + return $result; + } + + if(empty($result)){ + PEAR::raiseError(_kt('No file has been uploaded with the unique file id: ').$unique_file_id); + } + + return $result[0]['tempfilename']; + } + + /** * This is a list of all all managed files. * * @param string $action diff --git a/ktwebservice/upload.php b/ktwebservice/upload.php index 94430da..b164f70 100644 --- a/ktwebservice/upload.php +++ b/ktwebservice/upload.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * 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 @@ -70,6 +70,11 @@ if (!array_key_exists('action',$_POST)) respond(2, 'Action not specified.'); } +$unique_file_id = false; +if(array_key_exists('unique_file_id', $_POST)){ + $unique_file_id = $_POST['unique_file_id']; +} + $action = $_POST['action']; if (!in_array($action,array('C','A'))) { @@ -77,11 +82,16 @@ if (!in_array($action,array('C','A'))) } //$session_id = $_POST['session_id']; -if (count($_FILES) == 0) +$file_count = count($_FILES); +if ($file_count == 0) { respond(5, 'No files have been uploaded.'); } +if($file_count > 1 && $unique_file_id !== false){ + respond(5, 'Only one file can be uploaded with a unique file id.'); +} + if ($action == 'C') { if (!array_key_exists('document_id',$_POST)) @@ -120,7 +130,7 @@ foreach($_FILES as $key =>$file) $extra = $filename.'-'.$tempfile.'-'.$error; if ($error == UPLOAD_ERR_OK) { - $result = $upload_manager->uploaded($filename, $tempfile, $action); + $result = $upload_manager->uploaded($filename, $tempfile, $action, $unique_file_id); if (PEAR::isError($result)) { $lastMessage=$result->getMessage(); diff --git a/ktwebservice/webservice.php b/ktwebservice/webservice.php index a803c94..3226c1f 100644 --- a/ktwebservice/webservice.php +++ b/ktwebservice/webservice.php @@ -9,7 +9,7 @@ * KnowledgeTree Community Edition * Document Management Made Simple * Copyright (C) 2008, 2009 KnowledgeTree Inc. - * + * * * 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 @@ -97,7 +97,7 @@ define('KTWS_ERR_DB_PROBLEM', 99); if (!defined('LATEST_WEBSERVICE_VERSION')) { - define('LATEST_WEBSERVICE_VERSION',2); + define('LATEST_WEBSERVICE_VERSION', 3); } function bool2str($bool) @@ -435,7 +435,7 @@ class KTWebService 'item' => "{urn:$this->namespace}kt_metadata_selection_item" ) ); - + $this->__typedef["{urn:$this->namespace}kt_metadata_options"] = array( 'ishtml' => 'string', @@ -950,6 +950,20 @@ class KTWebService ); } + if($this->version >= 3) + { + // add_document + $this->__dispatch_map['add_document'] = + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'unique_file_id' => 'string' ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ), + ); + + $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", 'unique_file_id' => 'string' ), + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ) + ); + } + // get_document_detail_by_name $this->__dispatch_map['get_document_detail_by_name'] = array('in' => array('session_id' => 'string', 'document_name' => 'string', 'what'=>'string' ), @@ -2260,8 +2274,20 @@ class KTWebService * @param string $tempfilename * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS */ - function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename) + function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id = null) { + if(empty($tempfilename)){ + $upload_manager = new KTUploadManager(); + $tempfilename = $upload_manager->get_tempfile_from_unique_id($unique_file_id); + + if (PEAR::isError($tempfilename)) + { + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT, "Invalid unique file id: {$tempfilename->getMessage()}."); + $this->debug("add_document - cannot add document - " . $tempfilename->getMessage(), $session_id); + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response); + } + } + $this->debug("add_document('$session_id',$folder_id,'$title','$filename','$documenttype','$tempfilename')"); $kt = &$this->get_ktapi($session_id ); if (is_array($kt)) @@ -2347,9 +2373,9 @@ class KTWebService return $update_result; } - function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata) + function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata, $unique_file_id = null) { - $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename); + $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id); $status_code = $add_result->value['status_code']; if ($status_code != 0) diff --git a/sql/mysql/install/data.sql b/sql/mysql/install/data.sql index bbb0673..f88e3e6 100755 --- a/sql/mysql/install/data.sql +++ b/sql/mysql/install/data.sql @@ -1778,7 +1778,8 @@ INSERT INTO `upgrades` VALUES (232,'upgrade*3.7.0.1*99*upgrade3.7.0.1','Upgrade from version 3.6.3 to 3.7.0.1','2009-11-13 00:00:00',1,'upgrade*3.7.0.1*99*upgrade3.7.0.1'), (233,'sql*3.7.0.2*0*3.7.0.2/processor_queue.sql','Database upgrade to version 3.7.0.1: Processor Queue','2009-09-01 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'), (234,'upgrade*3.7.0.2*99*upgrade3.7.0.2','Upgrade from version 3.7.0.1 to 3.7.0.2','2009-11-19 00:00:00',1,'upgrade*3.7.0.2*99*upgrade3.7.0.2'), -(233,'sql*3.7.0.3*0*3.7.0.3/clienttools_config.sql','Database upgrade to version 3.7.0.3: Clienttools Config','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'); +(235,'sql*3.7.0.3*0*3.7.0.3/clienttools_config.sql','Database upgrade to version 3.7.0.3: Clienttools Config','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'), +(236,'sql*3.7.0.3*0*3.7.0.3/uploaded_files.sql','Database upgrade to version 3.7.0.3: Uploaded Files','2009-12-10 00:00:00',1,'upgrade*3.7.0.3*99*upgrade3.7.0.3'); /*!40000 ALTER TABLE `upgrades` ENABLE KEYS */; UNLOCK TABLES; diff --git a/sql/mysql/install/structure.sql b/sql/mysql/install/structure.sql index e4a604d..bac4f5a 100644 --- a/sql/mysql/install/structure.sql +++ b/sql/mysql/install/structure.sql @@ -1591,6 +1591,7 @@ CREATE TABLE `uploaded_files` ( `uploaddate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `action` char(1) NOT NULL COMMENT 'A = Add, C = Checkin', `document_id` int(11) default NULL, + `unique_file_id` varchar(30), PRIMARY KEY (`tempfilename`), KEY `userid` (`userid`), KEY `document_id` (`document_id`), diff --git a/sql/mysql/upgrade/3.7.0.3/uploaded_files.sql b/sql/mysql/upgrade/3.7.0.3/uploaded_files.sql new file mode 100644 index 0000000..8c67327 --- /dev/null +++ b/sql/mysql/upgrade/3.7.0.3/uploaded_files.sql @@ -0,0 +1 @@ +ALTER TABLE `uploaded_files` ADD COLUMN `unique_file_id` varchar(30); \ No newline at end of file