/** * Get File Revisions * * @param fileId - required - * The id of the file. * * @return A File object is return with all the revisions * or the error code and message returned by the server. */ public function getFileRevisions($fileId) { $urld = 'dpi/v1/folder/file/' . $fileId . '/revisions'; $parameters = array(); $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_GET, $this->authToken); $responseBody = simplexml_load_string($this->response); $returnObject = new File(); if ($responseBody === false) { $errorCode = 'N/A'; $errorMessage = 'The server has encountered an error, please try again.'; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } else { $errorStatus = $responseBody->errorStatus; if (empty($errorStatus)) { $returnObject->setRevision((string) $responseBody->attributes()->revision); $returnObject->setId((string) $responseBody->attributes()->id); $returnObject->setStatus((string) $responseBody->status); $returnObject->setCreatedOn((string) $responseBody->createdOn); $returnObject->setName((string) $responseBody->name); $returnObject->setOwnedByStorage((string) $responseBody->ownedByStorage); $returnObject->setParentId((string) $responseBody->parentid); $returnObject->setRevisionCount((string) $responseBody->revisionCount); $returnObject->setSize((string) $responseBody->size); $revisions = array(); $revisionsTag = (string) $responseBody->revisions->count(); if ($revisionsTag > 0) { foreach ($responseBody->revisions->children() as $currentRevision) { if ($currentRevision->count() > 0) { $revision = new Revision(); $revision->setId((string) $currentRevision->attributes()->id); $revision->setCurrent((string) $currentRevision->current); $revision->setDownloadUrl((string) $currentRevision->downloadUrl); $revision->setSize((string) $currentRevision->size); array_push($revisions, $revision); } } $returnObject->setRevisions($revisions); } } else { $errorCode = (string) $responseBody->errorStatus->code; $errorMessage = (string) $responseBody->errorStatus->message; $errorObject = new ErrorStatus($errorCode, $errorMessage); $returnObject->setErrorStatus($errorObject); } } return $returnObject; }
/** * Upload single file * * @param void * @return null */ function upload_single() { if ($this->request->isSubmitted()) { if (!File::canAdd($this->logged_user, $this->active_project)) { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_FORBIDDEN, null, true, true); } else { die('error - upload not permitted'); } // if } // if $file_data = $this->request->post('file'); if (!is_array($file_data)) { $file_data = array('milestone_id' => $this->request->get('milestone_id'), 'visibility' => $this->active_project->getDefaultVisibility()); if (instance_of($this->active_category, 'Category')) { $file_data['parent_id'] = $this->active_category->getId(); } // if } // if $this->smarty->assign('file_data', $file_data); if ($this->request->isSubmitted()) { db_begin_work(); $this->active_file = new File(); $attached = attach_from_files($this->active_file, $this->logged_user); // Do we have an upload error? if (is_error($attached) || $attached != 1) { if ($this->request->isApiCall()) { $this->serveData(is_error($attached) ? $attached : new Error('0 files uploaded')); } else { die('error - nothing uploaded'); } // if } // if $this->active_file->setAttributes($file_data); if ($this->active_file->getName() == '') { $this->active_file->setName($this->active_file->pending_files[0]['name']); } // if $this->active_file->setRevision(1); $this->active_file->setProjectId($this->active_project->getId()); if (trim($this->active_file->getCreatedByName()) == '' || trim($this->active_file->getCreatedByEmail()) == '') { $this->active_file->setCreatedBy($this->logged_user); } // if $this->active_file->setState(STATE_VISIBLE); $save = $this->active_file->save(); if ($save && !is_error($save)) { if ($this->active_file->countRevisions() > 0) { $subscribers = array($this->logged_user->getId()); if (is_foreachable($this->request->post('notify_users'))) { $subscribers = array_merge($subscribers, $this->request->post('notify_users')); } else { $subscribers[] = $this->active_project->getLeaderId(); } // if if (!in_array($this->active_project->getLeaderId(), $subscribers)) { $subscribers[] = $this->active_project->getLeaderId(); } // if Subscriptions::subscribeUsers($subscribers, $this->active_file); db_commit(); $this->active_file->ready(); if ($this->request->isApiCall()) { $this->serveData($this->active_file, 'file'); } else { die('success'); // async } // if } else { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED, null, true, true); } else { die('error - unable to attach file'); } // if } // if } else { if ($this->request->isApiCall()) { $this->serveData($save); } else { die('error - could not save file object'); // async } // if } // if } // if } else { if ($this->request->isApiCall()) { $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true); } else { die('error - request is not POST request'); // async } // if } // if }