/** * Upload new file version * * @param void * @return null */ function new_version() { if ($this->active_file->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_file->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { $attached = attach_from_files($this->active_file, $this->logged_user); if ($attached && !is_error($attached)) { $this->active_file->setRevision($this->active_file->getRevision() + 1); $save = $this->active_file->save(); if ($save && !is_error($save)) { $last_revision = $this->active_file->getLastRevision(); if (instance_of($last_revision, 'Attachment')) { $last_revision->setCreatedBy($this->logged_user); $last_revision->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION); $last_revision->save(); event_trigger('on_new_revision', array(&$this->active_file, &$last_revision, &$this->logged_user)); $activity_log = new NewFileVersionActivityLog(); $activity_log->log($this->active_file, $this->logged_user, $last_revision->getId()); } // if Subscriptions::subscribe($this->logged_user, $this->active_file); db_commit(); flash_success('File ":name" has been updated', array('name' => $this->active_file->getName())); $this->redirectToUrl($this->active_file->getViewUrl()); } else { db_rollback(); $this->smarty->assign('errors', $save); } // if } else { if (is_error($attached)) { $errors = new ValidationErrors(array('file' => $attached->getMessage())); } else { $errors = new ValidationErrors(array('file' => lang('File not uploaded'))); } // if $this->smarty->assign('errors', $errors); } // if } // if }