/** * Unpin document * * @param void * @return void */ function unpin() { if ($this->active_document->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_document->canPinUnpin($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if if ($this->request->isSubmitted()) { db_begin_work(); $this->active_document->setIsPinned(0); $save = $this->active_document->save(); if ($save && !is_error($save)) { db_commit(); if ($this->request->isAsyncCall()) { die($this->active_document->getPinUrl()); } else { flash_success('Document ":document_name" has been unpinned', array('document_name' => $this->active_document->getName())); } // if } else { db_rollback(); if ($this->request->isAsyncCall()) { $this->httpError(HTTP_ERR_OPERATION_FAILED); } else { flash_error('Failed to unpin document ":document_name"', array('document_name' => $this->active_document->getName())); } // if } // if $this->redirectToReferer(assemble_url('documents')); } else { $this->httpError(HTTP_ERR_BAD_REQUEST); } // if }