/** * Get the field data for artifact submission * * @param string the soap field value * * @return String the field data corresponding to the soap_value for artifact submision */ public function getFieldData($soap_value) { if (!$soap_value instanceof stdClass) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "Invalid submitted value for file field"); } if (!isset($soap_value->file_info) || !is_array($soap_value->file_info)) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "A File FieldValue must have a 'file_info' array (ArrayOfFieldValueFileInfo)"); } $field_data = array(); foreach ($soap_value->file_info as $fileinfo) { if (!$fileinfo instanceof stdClass) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "Fileinfo must be an array of FieldValueFileInfo"); } if (!(isset($fileinfo->description) && isset($fileinfo->filename) && isset($fileinfo->filetype) && isset($fileinfo->filesize))) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "Fileinfo must be an array of FieldValueFileInfo"); } if (!(isset($fileinfo->id) && $fileinfo->id)) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "FieldValueFileInfo must have an id of a temporary file"); } if (isset($fileinfo->action) && $fileinfo->action == 'delete') { $field_data['delete'][] = $fileinfo->id; } else { $temporary_file = new Tracker_SOAP_TemporaryFile($this->getCurrentUser(), $fileinfo->id); if (!$temporary_file->exists($fileinfo->id)) { throw new SoapFault(self::SOAP_FAULT_INVALID_REQUEST_FORMAT, "Invalid FieldValueFileInfo->id, file doesn't exist"); } $field_data[] = array('id' => $fileinfo->id, 'description' => $fileinfo->description, 'name' => $fileinfo->filename, 'type' => $fileinfo->filetype, 'size' => $fileinfo->filesize, 'error' => UPLOAD_ERR_OK, 'tmp_name' => $temporary_file->getPath($fileinfo->id)); } } return $field_data; }
public function itCreatesAndDeleteInTheSameTime() { $description1 = "Purchase Order"; $filename1 = 'my_file.ods'; $filesize1 = 1234; $filetype1 = 'application/vnd.oasis.opendocument.spreadsheet'; $file_id1 = 'sdfsdfaz'; $temp_file1 = new Tracker_SOAP_TemporaryFile($this->current_user, $file_id1); $temp_file_path1 = $temp_file1->getPath(); touch($temp_file_path1); $file_id2 = 12; $field_value = $this->createFakeSoapFieldValue($this->createFakeSoapFileRequest($file_id1, $description1, $filename1, $filesize1, $filetype1), $this->createFakeSoapFileRequest($file_id2, '', '', '', '', 'delete')); $this->assertEqual($this->field->getFieldData($field_value), array('delete' => array($file_id2), array('id' => $file_id1, 'description' => $description1, 'name' => $filename1, 'type' => $filetype1, 'tmp_name' => $temp_file_path1, 'error' => UPLOAD_ERR_OK, 'size' => $filesize1))); }