delete() публичный Метод

constructor
public delete ( )
 /**
  * Delete attachment
  * 
  * @param void
  * @return null
  */
 function delete()
 {
     if ($this->active_attachment->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $parent = $this->active_attachment->getParent();
     if (!instance_of($parent, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (!$this->request->isSubmitted()) {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
     // if
     $delete = $this->active_attachment->delete();
     if ($delete && !is_error($delete)) {
         if ($this->request->isAsyncCall()) {
             $this->httpOk();
         } else {
             $this->redirectToReferer($parent->getViewUrl());
         }
         // if
     } else {
         if ($this->request->isAsyncCall()) {
             $this->httpError(HTTP_ERR_OPERATION_FAILED, $delete->getMessage());
         } else {
             flash_error($delete->getMessage());
             $this->redirectToReferer($parent->getViewUrl());
         }
         // if
     }
     // if
 }
 public function store($notebookId, $noteId, $versionId)
 {
     $note = self::getNote($notebookId, $noteId, $versionId);
     if ($note->pivot->umask < PaperworkHelpers::UMASK_READWRITE) {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Permission Error'));
     }
     if (Input::hasFile('file') && Input::file('file')->isValid() || Input::json() != null && Input::json() != "") {
         $fileUpload = null;
         $newAttachment = null;
         if (Input::hasFile('file')) {
             $fileUpload = Input::file('file');
             $newAttachment = new Attachment(array('filename' => $fileUpload->getClientOriginalName(), 'fileextension' => $fileUpload->getClientOriginalExtension(), 'mimetype' => $fileUpload->getMimeType(), 'filesize' => $fileUpload->getSize()));
         } else {
             $fileUploadJson = Input::json();
             $fileUpload = base64_decode($fileUploadJson->get('file'));
             $newAttachment = new Attachment(array('filename' => $fileUploadJson->get('clientOriginalName'), 'fileextension' => $fileUploadJson->get('clientOriginalExtension'), 'mimetype' => $fileUploadJson->get('mimeType'), 'filesize' => count($fileUpload)));
         }
         $newAttachment->save();
         // Move file to (default) /app/storage/attachments/$newAttachment->id/$newAttachment->filename
         $destinationFolder = Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
         if (!File::makeDirectory($destinationFolder, 0700)) {
             $newAttachment->delete();
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Internal Error'));
         }
         // Get Version with versionId
         //$note = self::getNote($notebookId, $noteId, $versionId);
         $tmp = $note ? $note->version()->first() : null;
         $version = null;
         if (is_null($tmp)) {
             $newAttachment->delete();
             File::deleteDirectory($destinationFolder);
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version->first'));
         }
         while (!is_null($tmp)) {
             if ($tmp->id == $versionId || $versionId == 0) {
                 $version = $tmp;
                 break;
             }
             $tmp = $tmp->previous()->first();
         }
         if (is_null($version)) {
             $newAttachment->delete();
             File::deleteDirectory($destinationFolder);
             return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, array('message' => 'version'));
         }
         if (Input::hasFile('file')) {
             $fileUpload->move($destinationFolder, $fileUpload->getClientOriginalName());
         } else {
             file_put_contents($destinationFolder . '/' . $fileUploadJson->get('clientOriginalName'), $fileUpload);
         }
         $version->attachments()->attach($newAttachment);
         // Let's push that parsing job, which analyzes the document, converts it if needed and parses the crap out of it.
         Queue::push('DocumentParserWorker', array('user_id' => Auth::user()->id, 'document_id' => $newAttachment->id));
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $newAttachment);
     } else {
         return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_ERROR, array('message' => 'Invalid input'));
     }
 }
Пример #3
0
 public function deleteSelection($attachments)
 {
     $return = 1;
     foreach ($attachments as $id_attachment) {
         $attachment = new Attachment((int) $id_attachment);
         $return &= $attachment->delete();
     }
     return $return;
 }
Пример #4
0
 public function main_delete_attachment()
 {
     if (!isset($_GET['id'])) {
         error(__("No ID Specified"), __("An ID is required to delete an attachment.", "attachments"));
     }
     $attachment = new Attachment($_GET['id']);
     if ($attachment->no_results) {
         error(__("Error"), __("Invalid attachment ID specified.", "attachments"));
     }
     if (!$attachment->deletable()) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this attachment.", "attachments"));
     }
     Attachment::delete($attachment->id);
     Flash::notice(__("Attachment deleted.", "attachments"), $_SESSION['redirect_to']);
 }
Пример #5
0
 /**
  * Create Attachment instance and move file to attachmentsDirectory
  *
  * @param $data
  * @param $fileName
  * @param string $mime
  * @return \Attachment
  * @throws \Exception
  */
 protected function createAttachment($data, $fileName, $mime = '')
 {
     if (empty($mime)) {
         $f = finfo_open();
         $mime = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
     }
     $newAttachment = new \Attachment(array('filename' => $fileName, 'fileextension' => pathinfo($fileName, PATHINFO_EXTENSION), 'mimetype' => $mime, 'filesize' => strlen($data)));
     $newAttachment->save();
     $destinationFolder = \Config::get('paperwork.attachmentsDirectory') . '/' . $newAttachment->id;
     if (!\File::makeDirectory($destinationFolder, 0700)) {
         $newAttachment->delete();
         throw new \Exception('Error creating directory');
     }
     file_put_contents($destinationFolder . '/' . $fileName, $data);
     return $newAttachment;
 }
Пример #6
0
 /**
  * This function should be called when an attachment is uploaded.  It will
  * save the attachment to the appropriate place on the disk, and create a
  * database entry for the file.
  *
  * @param array $p_fileVar
  *     <pre>
  * 		The variable from the $_FILES array.  The array specifies the following:
  *		$a["name"] = original name of the file.
  * 		$a["type"] = the MIME type of the file
  *		$a["tmp_name"] = the temporary storage location on disk of the file
  *		$a["size"] = size of the file, in bytes (not required)
  *		$a["error"] = 0 (zero) if there was no error
  *     </pre>
  *
  * @param array $p_attributes
  *		Optional attributes which are stored in the database.
  *		Indexes can be the following: 'content_disposition', 'fk_language_id', 'http_charset', 'fk_user_id'
  *
  * @param int $p_id
  *		If the attachment already exists and we just want to update it, specify the
  *		current ID here.
  *
  * @param bool $p_uploaded
  *      If the attachment was uploaded with other mechanism (ex: plUploader)
  *      this is set so that the single upload file from article functionality is still secured.
  *
  * @return mixed
  *		The Attachment object that was created or updated.
  *		Return a PEAR_Error on failure.
  */
 public static function OnFileUpload($p_fileVar, $p_attributes, $p_id = null, $p_uploaded = false)
 {
     if (!is_array($p_fileVar)) {
         return null;
     }
     // Verify its a valid file.
     $filesize = filesize($p_fileVar['tmp_name']);
     if ($filesize === false) {
         return new PEAR_Error("Attachment::OnFileUpload(): invalid parameters received.");
     }
     // Are we updating or creating?
     if (!is_null($p_id)) {
         // Updating the attachment
         $attachment = new Attachment($p_id);
         $attachment->update($p_attributes);
         // Remove the old file because
         // the new file may have a different file extension.
         if (file_exists($attachment->getStorageLocation())) {
             unlink($attachment->getStorageLocation());
         }
     } else {
         // Creating the attachment
         $attachment = new Attachment();
         $attachment->create($p_attributes);
         $attachment->setProperty('time_created', 'NULL', true, true);
     }
     $attachment->setProperty('file_name', $p_fileVar['name'], false);
     $attachment->setProperty('mime_type', $p_fileVar['type'], false);
     $attachment->setProperty('size_in_bytes', $p_fileVar['size'], false);
     $extension = "";
     $fileParts = explode('.', $p_fileVar['name']);
     if (count($fileParts) > 1) {
         $extension = array_pop($fileParts);
         $attachment->setProperty('extension', $extension, false);
     }
     $target = $attachment->getStorageLocation();
     $attachment->makeDirectories();
     ob_start();
     var_dump(is_uploaded_file($p_fileVar['tmp_name']));
     $dump = ob_get_clean();
     /**
      * for security reason
      *  for file uploaded normal not with other mechanism (ex: plUploader)
      *  we still need the move_uploaded_file functionality
      */
     if (!$p_uploaded && !move_uploaded_file($p_fileVar['tmp_name'], $target)) {
         $attachment->delete();
         return new PEAR_Error(camp_get_error_message(CAMP_ERROR_CREATE_FILE, $target), CAMP_ERROR_CREATE_FILE);
     }
     // if the file was uploaded with other mechanism (ex: plUploader) use rename(move) functionality
     if ($p_uploaded && !rename($p_fileVar['tmp_name'], $target)) {
         $attachment->delete();
         return new PEAR_Error(camp_get_error_message(CAMP_ERROR_CREATE_FILE, $target), CAMP_ERROR_CREATE_FILE);
     }
     chmod($target, 0644);
     $attachment->commit();
     return $attachment;
 }
Пример #7
0
 public function removeLicense()
 {
     //delete all documents and associated expressions and SFX providers
     $document = new Document();
     foreach ($this->getDocuments() as $document) {
         //delete all expressions and expression notes
         $expression = new Expression();
         foreach ($document->getExpressions() as $expression) {
             $expressionNote = new ExpressionNote();
             foreach ($expression->getExpressionNotes() as $expressionNote) {
                 $expressionNote->delete();
             }
             $expression->removeQualifiers();
             $expression->delete();
         }
         $sfxProvider = new SFXProvider();
         foreach ($document->getSFXProviders() as $sfxProvider) {
             $sfxProvider->delete();
         }
         $signature = new Signature();
         foreach ($document->getSignatures() as $signature) {
             $signature->delete();
         }
         $document->delete();
     }
     //delete all attachments
     $attachment = new Attachment();
     foreach ($this->getAttachments() as $attachment) {
         $attachmentFile = new AttachmentFile();
         foreach ($attachment->getAttachmentFiles() as $attachmentFile) {
             $attachmentFile->delete();
         }
         $attachment->delete();
     }
     $this->delete();
 }
     $attachmentFile->attachmentURL = $_GET['attachmentURL'];
     try {
         $attachmentFile->save();
         echo $attachmentFile->primaryKey;
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
 case 'deleteAttachment':
     $attachment = new Attachment(new NamedArguments(array('primaryKey' => $_GET['attachmentID'])));
     //first delete attachments
     foreach ($attachment->getAttachmentFiles() as $attachmentFile) {
         $attachmentFile->delete();
     }
     try {
         $attachment->delete();
         echo "Attachment successfully deleted";
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
 case 'deleteAttachmentFile':
     $attachmentFile = new AttachmentFile(new NamedArguments(array('primaryKey' => $_GET['attachmentFileID'])));
     try {
         $attachmentFile->delete();
         echo "Attachment file successfully deleted";
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     break;
     //updates license status when a new one is selected in dropdown box
Пример #9
0
 public function removeResource()
 {
     //delete data from child linked tables
     $this->removeResourceRelationships();
     $this->removePurchaseSites();
     $this->removeAuthorizedSites();
     $this->removeAdministeringSites();
     $this->removeResourceLicenses();
     $this->removeResourceLicenseStatuses();
     $this->removeResourceOrganizations();
     $this->removeResourcePayments();
     $this->removeAllSubjects();
     $this->removeAllIsbnOrIssn();
     $instance = new Contact();
     foreach ($this->getContacts() as $instance) {
         $instance->removeContactRoles();
         $instance->delete();
     }
     $instance = new ExternalLogin();
     foreach ($this->getExternalLogins() as $instance) {
         $instance->delete();
     }
     $instance = new ResourceNote();
     foreach ($this->getNotes() as $instance) {
         $instance->delete();
     }
     $instance = new Attachment();
     foreach ($this->getAttachments() as $instance) {
         $instance->delete();
     }
     $instance = new Alias();
     foreach ($this->getAliases() as $instance) {
         $instance->delete();
     }
     $this->delete();
 }
Пример #10
0
$f_fk_language_id = Input::Get('f_fk_language_id', 'int', 0);
$f_attachment_id = Input::Get('f_attachment_id', 'int', 0);
$attachmentObj = new Attachment($f_attachment_id);
if (!$attachmentObj->exists()) {
    camp_html_display_error(getGS('Attachment does not exist.'), null, true);
    exit;
}
$filePath = dirname($attachmentObj->getStorageLocation()) . '/' . $attachmentObj->getFileName();
if (!is_writable(dirname($filePath))) {
    camp_html_add_msg(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $filePath, basename($attachmentObj->getStorageLocation())));
    //camp_html_goto_page(camp_html_article_url($articleObj, $f_language_id, 'edit.php'));
    exit;
}
$DebateAnswerAttachment = new DebateAnswerAttachment($f_debate_nr, $f_debateanswer_nr, $f_attachment_id);
$DebateAnswerAttachment->delete();
// Go back to upload screen.
camp_html_add_msg(getGS("File '\$1' deleted.", $attachmentObj->getFileName()), "ok");
$attachmentObj->delete();
?>
<script>
location.href="popup.php?f_debate_nr=<?php 
p($f_debate_nr);
?>
&f_debateanswer_nr=<?php 
p($f_debateanswer_nr);
?>
&f_fk_language_id=<?php 
p($f_fk_language_id);
?>
";
</script>
Пример #11
0
 /**
  * Function: delete
  * Deletes the given version, including its notes. Calls the "delete_version" trigger and passes the <Version> as an argument.
  *
  * Parameters:
  *     $id - The version to delete.
  */
 static function delete($id)
 {
     $version = new self($id);
     foreach ($version->notes as $note) {
         Note::delete($note->id);
     }
     foreach ($version->attachments as $attachment) {
         Attachment::delete($attachment->id);
     }
     @unlink(uploaded($version->filename, false));
     @unlink(uploaded($version->preview, false));
     parent::destroy(get_class(), $id);
     if (module_enabled("cacher")) {
         Modules::$instances["cacher"]->regenerate();
     }
 }
Пример #12
0
 function execute()
 {
     if (!$this->hasRights($_SESSION['access'], 'delete', $this->attachment)) {
         return array('Attachment Error', VoodooError::displayError('Permission Denied'));
     }
     if (!isset($_REQUEST['confirm'])) {
         $av = new AttachmentView($this->dispatcher, $this->attachment, $this->al);
         list(, $content) = $av->execute();
         $t =& VoodooTemplate::getInstance();
         $t->setDir(ATTACHMENT_TEMPLATES);
         $path = '/attachment/' . $this->dispatcher->cont . '/' . $this->dispatcher->action . '/' . $this->attachment;
         $buttons = '';
         $args = array('prepath' => PATH_TO_DOCROOT);
         $args['button_action'] = $path . '?action=delete&confirm=true';
         $args['button'] = 'Yes, Delete Attachment';
         $args['class'] = 'buttonmargin';
         $buttons .= $t->parse('button', $args);
         $args['button_action'] = $path . '?action=view';
         $args['button'] = 'No';
         $buttons .= $t->parse('button', $args);
         $args = array('prepath' => PATH_TO_DOCROOT, 'content' => $content, 'buttons' => $buttons);
         return array('', $t->parse('delete', $args));
     }
     $attachment = new Attachment($this->dispatcher->controller->DBConnect());
     $attachment->setByName($this->attachment);
     $this->al->delete($attachment->id, $this->dispatcher->action);
     $attachment->delete();
     header(sprintf('Location: %s/%s/%s', PATH_TO_DOCROOT, strtolower($this->dispatcher->cont), $this->dispatcher->action));
     exit;
 }