/** * @see Action::execute() */ public function execute() { parent::execute(); // check permission WCF::getUser()->checkPermission('admin.attachment.canDeleteAttachment'); // delete warning $this->attachment->delete(); $this->executed(); // forward to list page if (!empty($this->url)) { HeaderUtil::redirect($this->url . '&deletedAttachmentID=' . $this->attachmentID . SID_ARG_2ND_NOT_ENCODED); } else { HeaderUtil::redirect('index.php?page=AdminAttachmentListPage&deletedAttachmentID=' . $this->attachmentID . '&packageID=' . PACKAGE_ID . SID_ARG_2ND_NOT_ENCODED); } exit; }
/** * @see Action::execute() */ public function execute() { parent::execute(); // count threads $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\tisImage = 1"; $row = WCF::getDB()->getFirstRow($sql); $count = $row['count']; // get attachments $threadIDs = ''; $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tisImage = 1\n\t\t\tORDER BY\tattachmentID"; $result = WCF::getDB()->sendQuery($sql, $this->limit, $this->limit * $this->loop); if (!WCF::getDB()->countRows($result)) { $this->calcProgress(); $this->finish(); } while ($row = WCF::getDB()->fetchArray($result)) { $attachment = new AttachmentEditor(null, $row); $attachment->createThumbnail(); } $this->executed(); $this->calcProgress($this->limit * $this->loop, $count); $this->nextLoop(); }
/** * Creates a new attachments. * * @param string $file * @param array $attachmentData * @return AttachmentEditor */ public static function create($file, $attachmentData) { $attachmentData['isBinary'] = 1; if (!$attachmentData['isImage']) { $attachmentData['isBinary'] = (int) FileUtil::isBinary($file); } // insert attachment $attachmentID = self::insert($attachmentData); $attachmentData['attachmentID'] = $attachmentID; $attachment = new AttachmentEditor(null, $attachmentData); // copy tmp file to /attachments folders try { $path = WCF_DIR . 'attachments/attachment-' . $attachmentID; if (!@move_uploaded_file($file, $path)) { throw new SystemException(); } @chmod($path, 0777); } catch (SystemException $e) { // could not copy uploaded file, rollback insert statement $attachment->delete(); return null; } return $attachment; }
/** * @see PackageInstallationPlugin::uninstall() */ public function uninstall() { // call uninstall event EventHandler::fireAction($this, 'uninstall'); // get container types $containerTypes = array(); $sql = "SELECT\tcontainerType\n\t\t\tFROM\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\tWHERE\tpackageID = " . $this->installation->getPackageID(); $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $containerTypes[] = $row['containerType']; } if (count($containerTypes)) { require_once WCF_DIR . 'lib/data/attachment/AttachmentEditor.class.php'; // delete attachments (files) $sql = "SELECT\t*\n\t\t\t\tFROM\twcf" . WCF_N . "_attachment\n\t\t\t\tWHERE\tpackageID = " . $this->installation->getPackageID() . "\n\t\t\t\t\tAND containerType IN ('" . implode("','", array_map('escapeString', $containerTypes)) . "')"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { $attachment = new AttachmentEditor(null, $row); $attachment->deleteFile(); } // delete attachments (rows) $sql = "DELETE FROM\twcf" . WCF_N . "_attachment\n\t\t\t\tWHERE\t\tpackageID = " . $this->installation->getPackageID() . "\n\t\t\t\t\t\tAND containerType IN ('" . implode("','", array_map('escapeString', $containerTypes)) . "')"; WCF::getDB()->sendQuery($sql); // delete container $sql = "DELETE FROM\twcf" . WCF_N . "_" . $this->tableName . "\n\t\t\t\tWHERE\t\tpackageID = " . $this->installation->getPackageID(); WCF::getDB()->sendQuery($sql); } }
/** * @see AbstractLostAndFounDatabaseItem::delete */ public function delete() { $editor = new AttachmentEditor($this->objectID); $editor->delete(); }
/** * Copies the selected attachments. * * @param array $messageMapping * @return array $attachmentMapping */ public function copyAll(&$messageMapping) { $attachmentMapping = array(); foreach ($this->attachments as $oldContainerID => $attachments) { foreach ($attachments as $attachment) { $newAttachment = AttachmentEditor::create(array('attachmentName' => $attachment->attachmentName, 'packageID' => $this->packageID, 'containerID' => $messageMapping[$oldContainerID], 'containerType' => $this->containerType, 'userID' => $attachment->userID, 'attachmentSize' => $attachment->attachmentSize, 'isImage' => $attachment->isImage, 'thumbnailType' => $attachment->thumbnailType, 'thumbnailSize' => $attachment->thumbnailSize, 'downloads' => $attachment->downloads, 'sha1Hash' => $attachment->sha1Hash, 'uploadTime' => $attachment->uploadTime, 'fileType' => $attachment->fileType, 'isBinary' => $attachment->isBinary, 'lastDownloadTime' => $attachment->lastDownloadTime, 'embedded' => $attachment->embedded, 'width' => $attachment->width, 'height' => $attachment->height)); if (!isset($attachmentMapping[$messageMapping[$oldContainerID]])) { $attachmentMapping[$messageMapping[$oldContainerID]] = array(); } $attachmentMapping[$messageMapping[$oldContainerID]][$attachment->attachmentID] = $newAttachment->attachmentID; @copy(WCF_DIR . 'attachments/attachment-' . $attachment->attachmentID, WCF_DIR . 'attachments/attachment-' . $newAttachment->attachmentID); if (!empty($attachment->thumbnailType)) { @copy(WCF_DIR . 'attachments/thumbnail-' . $attachment->attachmentID, WCF_DIR . 'attachments/thumbnail-' . $newAttachment->attachmentID); } } } return $attachmentMapping; }