/** * Get New Document. * * @return \Dms\Document\Document */ public function getNewDocument() { if (null === $this->new_document) { $this->new_document = new Document(); if (null !== $this->document) { $this->new_document->setName($this->document->getName()); } } return $this->new_document; }
/** * {@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; }