/**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // check file location
     if (!@file_exists($additionalData['fileLocation'])) {
         return 0;
     }
     // get file hash
     if (empty($data['fileHash'])) {
         $data['fileHash'] = sha1_file($additionalData['fileLocation']);
     }
     // get image size
     if (!empty($data['isImage'])) {
         $imageData = @getimagesize($additionalData['fileLocation']);
         if ($imageData !== false) {
             $data['width'] = $imageData[0];
             $data['height'] = $imageData[1];
         }
     }
     // get user id
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     // check existing attachment id
     if (is_numeric($oldID)) {
         $attachment = new Attachment($oldID);
         if (!$attachment->attachmentID) {
             $data['attachmentID'] = $oldID;
         }
     }
     // save attachment
     $attachment = AttachmentEditor::create(array_merge($data, array('objectTypeID' => $this->objectTypeID)));
     // check attachment directory
     // and create subdirectory if necessary
     $dir = dirname($attachment->getLocation());
     if (!@file_exists($dir)) {
         @mkdir($dir, 0777);
     }
     // copy file
     try {
         if (!copy($additionalData['fileLocation'], $attachment->getLocation())) {
             throw new SystemException();
         }
         return $attachment->attachmentID;
     } catch (SystemException $e) {
         // copy failed; delete attachment
         $editor = new AttachmentEditor($attachment);
         $editor->delete();
     }
     return 0;
 }
 /**
  * Copies attachments from one object id to another.
  */
 public function copy()
 {
     $sourceObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', $this->parameters['sourceObjectType']);
     $targetObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', $this->parameters['targetObjectType']);
     $attachmentList = new AttachmentList();
     $attachmentList->getConditionBuilder()->add("attachment.objectTypeID = ?", array($sourceObjectType->objectTypeID));
     $attachmentList->getConditionBuilder()->add("attachment.objectID = ?", array($this->parameters['sourceObjectID']));
     $attachmentList->readObjects();
     $newAttachmentIDs = array();
     foreach ($attachmentList as $attachment) {
         $newAttachment = AttachmentEditor::create(array('objectTypeID' => $targetObjectType->objectTypeID, 'objectID' => $this->parameters['targetObjectID'], 'userID' => $attachment->userID, 'filename' => $attachment->filename, 'filesize' => $attachment->filesize, 'fileType' => $attachment->fileType, 'fileHash' => $attachment->fileHash, 'isImage' => $attachment->isImage, 'width' => $attachment->width, 'height' => $attachment->height, 'tinyThumbnailType' => $attachment->tinyThumbnailType, 'tinyThumbnailSize' => $attachment->tinyThumbnailSize, 'tinyThumbnailWidth' => $attachment->tinyThumbnailWidth, 'tinyThumbnailHeight' => $attachment->tinyThumbnailHeight, 'thumbnailType' => $attachment->thumbnailType, 'thumbnailSize' => $attachment->thumbnailSize, 'thumbnailWidth' => $attachment->thumbnailWidth, 'thumbnailHeight' => $attachment->thumbnailHeight, 'downloads' => $attachment->downloads, 'lastDownloadTime' => $attachment->lastDownloadTime, 'uploadTime' => $attachment->uploadTime, 'showOrder' => $attachment->showOrder));
         // copy attachment
         @copy($attachment->getLocation(), $newAttachment->getLocation());
         if ($attachment->tinyThumbnailSize) {
             @copy($attachment->getTinyThumbnailLocation(), $newAttachment->getTinyThumbnailLocation());
         }
         if ($attachment->thumbnailSize) {
             @copy($attachment->getThumbnailLocation(), $newAttachment->getThumbnailLocation());
         }
         $newAttachmentIDs[$attachment->attachmentID] = $newAttachment->attachmentID;
     }
     return array('attachmentIDs' => $newAttachmentIDs);
 }