Commit fb13f7c9a796b2f29ed46ee1e0bc6c784a74e4dc

Authored by Megan Watson
1 parent ac19c27b

Added new functions to add_document_with_key for file uploads without the tempfilename.

Committed by: Megan Watson
Showing 1 changed file with 51 additions and 15 deletions
ktwebservice/webservice.php
... ... @@ -957,11 +957,25 @@ class KTWebService
957 957 {
958 958 // add_document
959 959 $this->__dispatch_map['add_document'] =
960   - array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'unique_file_id' => 'string' ),
  960 + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string'),
961 961 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ),
962 962 );
963 963  
964 964 $this->__dispatch_map['add_document_with_metadata'] =
  965 + 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"),
  966 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
  967 + );
  968 + }
  969 +
  970 + if($this->version >= 2)
  971 + {
  972 + // add_document
  973 + $this->__dispatch_map['add_document_with_key'] =
  974 + array('in' => array('session_id'=>'string','folder_id'=>'int','title'=>'string','filename'=>'string','documentype' =>'string','tempfilename' =>'string', 'unique_file_id' => 'string' ),
  975 + 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" ),
  976 + );
  977 +
  978 + $this->__dispatch_map['add_document_with_key_with_metadata'] =
965 979 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' ),
966 980 'out' => array( 'return' => "{urn:$this->namespace}kt_document_detail" )
967 981 );
... ... @@ -2266,18 +2280,7 @@ class KTWebService
2266 2280  
2267 2281 }
2268 2282  
2269   - /**
2270   - * Adds a document to the repository.
2271   - *
2272   - * @param string $session_id
2273   - * @param int $folder_id
2274   - * @param string $title
2275   - * @param string $filename
2276   - * @param string $documenttype
2277   - * @param string $tempfilename
2278   - * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
2279   - */
2280   - function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id = null)
  2283 + function add_document_with_key($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id = null)
2281 2284 {
2282 2285 if(empty($tempfilename) && !empty($unique_file_id)){
2283 2286 $upload_manager = new KTUploadManager();
... ... @@ -2291,6 +2294,22 @@ class KTWebService
2291 2294 }
2292 2295 }
2293 2296  
  2297 + return $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename);
  2298 + }
  2299 +
  2300 + /**
  2301 + * Adds a document to the repository.
  2302 + *
  2303 + * @param string $session_id
  2304 + * @param int $folder_id
  2305 + * @param string $title
  2306 + * @param string $filename
  2307 + * @param string $documenttype
  2308 + * @param string $tempfilename
  2309 + * @return kt_document_detail. status_code can be KTWS_ERR_INVALID_SESSION, KTWS_ERR_INVALID_FOLDER, KTWS_ERR_INVALID_DOCUMENT or KTWS_SUCCESS
  2310 + */
  2311 + function add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename)
  2312 + {
2294 2313 $this->debug("add_document('$session_id',$folder_id,'$title','$filename','$documenttype','$tempfilename')");
2295 2314 $kt = &$this->get_ktapi($session_id );
2296 2315 if (is_array($kt))
... ... @@ -2376,9 +2395,26 @@ class KTWebService
2376 2395 return $update_result;
2377 2396 }
2378 2397  
2379   - function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata, $unique_file_id = null)
  2398 + function add_document_with_key_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata, $unique_file_id = null)
  2399 + {
  2400 + if(empty($tempfilename) && !empty($unique_file_id)){
  2401 + $upload_manager = new KTUploadManager();
  2402 + $tempfilename = $upload_manager->get_tempfile_from_unique_id($unique_file_id);
  2403 +
  2404 + if (PEAR::isError($tempfilename))
  2405 + {
  2406 + $response = KTWebService::_status(KTWS_ERR_INVALID_DOCUMENT, "Invalid unique file id: {$tempfilename->getMessage()}.");
  2407 + $this->debug("add_document - cannot add document - " . $tempfilename->getMessage(), $session_id);
  2408 + return new SOAP_Value('return',"{urn:$this->namespace}kt_document_detail", $response);
  2409 + }
  2410 + }
  2411 +
  2412 + return $this->add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata);
  2413 + }
  2414 +
  2415 + function add_document_with_metadata($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $metadata, $sysdata)
2380 2416 {
2381   - $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename, $unique_file_id);
  2417 + $add_result = $this->add_document($session_id, $folder_id, $title, $filename, $documenttype, $tempfilename);
2382 2418  
2383 2419 $status_code = $add_result->value['status_code'];
2384 2420 if ($status_code != 0)
... ...