/** * {@inheritdoc} * * @param \Dms\Document\Document $document * * @see \Dms\Storage\StorageInterface::write() */ public function write(\Dms\Document\Document $document) { $ret = null; $name = $document->getId(); $nameMod = substr($name, 4); $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/'; $path = $this->getBasePath() . $f; if (!is_dir($path)) { mkdir($path, 0777, true); } $p = $path . $nameMod . '.dat'; if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) { $fileInput = new FileInput(key($document->getDatas())); $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]); $inputFilter = new InputFilter(); $inputFilter->add($fileInput); $form = new Form(); $form->setInputFilter($inputFilter); $form->setData($document->getDatas()); if ($form->isValid()) { $form->getData(); } } else { $fp = fopen($p, 'w'); fwrite($fp, $document->getDatas()); $document->setWeight(strlen($document->getDatas())); fclose($fp); } $conf_storage = $this->options->getStorage(); if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') { print_r($_FILES); $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']); } $document->setSupport(Document::SUPPORT_FILE_STR); $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name)); $serialize = serialize($document); $fp = fopen($path . $nameMod . '.inf', 'w'); $ret += fwrite($fp, $serialize); fclose($fp); $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name)); return $ret; }
/** * Record a document to the Dms. * * @param int $id * * @throws \Exception * * @return \Dms\Document\Manager */ public function writeFile($id = null) { if (null === $this->document) { throw new \Exception('Document does not exist'); } $obj_mime_type = new MimeType(); $is_video = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'video') === 0 || strpos($this->document->getType(), 'video') === 0; if ($is_video && (null !== $this->getFormat() || null !== $this->getSize() || null !== $this->getPage())) { $this->createPicture(); $this->document = $this->new_document; $this->new_document = null; } // si que resize // si format n'est pas une image ou IN non compatible // convertire d'abort avec uniconv en format compatible imagick puis par defaut mettre un numéro de page 1 si non existant // puis resize imagick avec format de sortie par default (jpeg) if (null !== $this->getSize() && null === $this->getFormat()) { // si format n'est pas une image ou IN non compatible $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if ($is_img && Resize::isCompatible($this->document->getFormat())) { $this->resize(); } else { // convertire d'abort avec uniconv en format compatible imagick puis par defaut mettre un numéro de page 1 si non existant if (!$is_img && $this->page == null) { $this->setPage(1); } $this->setFormat('jpg'); $this->convert(); $this->resize(); } // si que format // vérifier que le format n'est pas le même. // sinonuniconv (voir imagmagick selon le suport est quelité) } elseif (null === $this->getSize() && null !== $this->getFormat()) { if ($this->getFormat() !== $this->getDocument()->getFormat()) { $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); } // si resize + format } elseif (null !== $this->getSize() && null !== $this->getFormat()) { // si format compatible IN et OUT avec imagik on utilise imagik pour les deux if (Resize::isCompatible($this->format) && Resize::isCompatible($this->getDocument()->getFormat())) { $this->resize(); $this->getNewDocument()->setId($id); $document_write = $this->getNewDocument(); // si format IN et OUT non compatible avec Imagick // Convertion avec uniconv en format compatible Imagick (jpg) // Resize avec imagick // Convertion OUT avec uniconv } elseif (!Resize::isCompatible($this->format) && !Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); $this->resize(); $this->setFormat($tmp_fmt); $this->convert(); // si que format IN compatible Imagick // resize avec imagick (jpg) // convertie uniconv } elseif (!Resize::isCompatible($this->format) && Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $this->resize(); $this->setFormat($tmp_fmt); $this->convert(); // si que OUT compatible // convertie uniconv en (jpeg) // resize et format avec imagick } elseif (Resize::isCompatible($this->format) && !Resize::isCompatible($this->getDocument()->getFormat())) { $tmp_fmt = $this->getFormat(); $this->setFormat('jpg'); $obj_mime_type = new MimeType(); $is_img = strpos($obj_mime_type->getMimeTypeByExtension($this->document->getFormat()), 'image') === 0; if (!$is_img) { $this->setPage(1); } $this->convert(); $this->setFormat($tmp_fmt); $this->resize(); } } if ($this->new_document !== null) { $this->document = $this->new_document; } if (null !== $id) { $this->document->setId($id); } $this->document->setStorage($this->getStorage()); $this->document->write(); return $this; }