Update Phrasea Border to the latest service

This commit is contained in:
Romain Neutron
2012-09-11 23:15:22 +02:00
parent cf7fcf490c
commit eb9600b19e
32 changed files with 357 additions and 274 deletions

View File

@@ -11,10 +11,12 @@
namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application;
/**
* File attribute interface
*/
interface Attribute
interface AttributeInterface
{
const NAME_METADATA = 'metadata';
const NAME_METAFIELD = 'metafield';
@@ -43,7 +45,10 @@ interface Attribute
/**
* Build the current object with is string value
*
* @param Application $app the application context
* @param string $string the serialized string
*
* @throws \InvalidArgumentException
*/
public static function loadFromString($string);
public static function loadFromString(Application $app, $string);
}

View File

@@ -11,6 +11,8 @@
namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application;
/**
* This factory is intended to create Attribute based on their name and
* serialized values. This is mostly used when reading Lazaret tables
@@ -21,27 +23,28 @@ class Factory
/**
* Build a file package Attribute
*
* @param string $name The name of the attribute, one of the
* @param Application $app Application context
* @param string $name The name of the attribute, one of the
* Attribute::NAME_* constants
* @param string $serialized The serialized value of the attribute
* (Attribute::asString result)
* @return Attribute The attribute
* @return AttributeInterface The attribute
* @throws \InvalidArgumentException
*/
public static function getFileAttribute($name, $serialized)
public static function getFileAttribute(Application $app, $name, $serialized)
{
switch ($name) {
case Attribute::NAME_METADATA:
return Metadata::loadFromString($serialized);
case AttributeInterface::NAME_METADATA:
return Metadata::loadFromString($app, $serialized);
break;
case Attribute::NAME_STORY:
return Story::loadFromString($serialized);
case AttributeInterface::NAME_STORY:
return Story::loadFromString($app, $serialized);
break;
case Attribute::NAME_METAFIELD:
return MetaField::loadFromString($serialized);
case AttributeInterface::NAME_METAFIELD:
return MetaField::loadFromString($app, $serialized);
break;
case Attribute::NAME_STATUS:
return Status::loadFromString($serialized);
case AttributeInterface::NAME_STATUS:
return Status::loadFromString($app, $serialized);
break;
}

View File

@@ -11,13 +11,15 @@
namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application;
/**
* Phraseanet Border MetaField Attribute
*
* This attribute is used to store a value related to a fieldname for a file
* prior to their record creation
*/
class MetaField implements Attribute
class MetaField implements AttributeInterface
{
/**
*
@@ -35,13 +37,13 @@ class MetaField implements Attribute
* Constructor
*
* @param \databox_field $databox_field The databox field
* @param type $value A scalar value
* @param string $value A scalar value
*
* @throws \InvalidArgumentException When value is not scalar
*/
public function __construct(\databox_field $databox_field, $value)
{
if ( ! is_scalar($value)) {
if (!is_scalar($value)) {
throw new \InvalidArgumentException('Databox field only accept scalar values');
}
$this->databox_field = $databox_field;
@@ -101,20 +103,18 @@ class MetaField implements Attribute
*
* @return MetaField
*/
public static function loadFromString($string)
public static function loadFromString(Application $app, $string)
{
if ( ! $datas = @unserialize($string)) {
if (!$datas = @unserialize($string)) {
throw new \InvalidArgumentException('Unable to load metadata from string');
}
try {
$appbox = \appbox::get_instance(\bootstrap::getCore());
$databox = $appbox->get_databox($datas['sbas_id']);
$field = $databox->get_meta_structure()->get_element($datas['id']);
return new static($app['phraseanet.appbox']
->get_databox($datas['sbas_id'])
->get_meta_structure()->get_element($datas['id']), $datas['value']);
} catch (\Exception_NotFound $e) {
throw new \InvalidArgumentException('Field does not exist anymore');
}
return new static($field, $datas['value']);
}
}

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application;
use PHPExiftool\Driver\Metadata\Metadata as ExiftoolMeta;
/**
@@ -19,7 +20,7 @@ use PHPExiftool\Driver\Metadata\Metadata as ExiftoolMeta;
* This attribute is used to store a PHPExiftool metadatas with file prior to
* their record creation
*/
class Metadata implements Attribute
class Metadata implements AttributeInterface
{
protected $metadata;
@@ -72,13 +73,13 @@ class Metadata implements Attribute
*
* @return Metadata
*/
public static function loadFromString($string)
public static function loadFromString(Application $app, $string)
{
if ( ! $metadata = @unserialize($string)) {
throw new \InvalidArgumentException('Unable to load metadata from string');
}
if ( ! $metadata instanceof ExiftoolMeta) {
if (! $metadata instanceof ExiftoolMeta) {
throw new \InvalidArgumentException('Unable to load metadata from string');
}

View File

@@ -11,7 +11,9 @@
namespace Alchemy\Phrasea\Border\Attribute;
class Status implements Attribute
use Alchemy\Phrasea\Application;
class Status implements AttributeInterface
{
protected $status;
@@ -54,7 +56,7 @@ class Status implements Attribute
return $this->status;
}
public static function loadFromString($string)
public static function loadFromString(Application $app, $string)
{
return new static($string);
}

View File

@@ -11,13 +11,15 @@
namespace Alchemy\Phrasea\Border\Attribute;
use Alchemy\Phrasea\Application;
/**
* Phraseanet Border Story Attribute
*
* This attribute is used to store a destination story for a file, prior to
* their record creation
*/
class Story implements Attribute
class Story implements AttributeInterface
{
protected $story;
@@ -74,12 +76,12 @@ class Story implements Attribute
*
* @return Story
*/
public static function loadFromString($string)
public static function loadFromString(Application $app, $string)
{
$ids = explode('_', $string);
try {
$story = new \record_adapter($ids[0], $ids[1]);
$story = new \record_adapter($app, $ids[0], $ids[1]);
} catch (\Exception_NotFound $e) {
throw new \InvalidArgumentException('Unable to fetch a story from string');
}

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
/**
@@ -18,9 +19,15 @@ use Alchemy\Phrasea\Border\File;
*/
abstract class AbstractChecker implements CheckerInterface
{
protected $app;
protected $databoxes = array();
protected $collections = array();
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Restrict the checker to a set of databoxes.
* Warning, you can not restrict on both databoxes and collections
@@ -40,7 +47,7 @@ abstract class AbstractChecker implements CheckerInterface
$this->databoxes = array();
foreach ($this->toIterator($databoxes) as $databox) {
if ( ! $databox instanceof \databox) {
if (! $databox instanceof \databox) {
throw new \InvalidArgumentException('Restrict to databoxes only accept databoxes as argument');
}
$this->databoxes[] = $databox;
@@ -68,7 +75,7 @@ abstract class AbstractChecker implements CheckerInterface
$this->collections = array();
foreach ($this->toIterator($collections) as $collection) {
if ( ! $collection instanceof \collection) {
if (! $collection instanceof \collection) {
throw new \InvalidArgumentException('Restrict to collections only accept collections as argument');
}
$this->collections[] = $collection;

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -22,13 +23,14 @@ class Colorspace extends AbstractChecker
const COLORSPACE_CMYK = 'cmyk';
const COLORSPACE_GRAYSCALE = 'grayscale';
public function __construct(array $options)
public function __construct(Application $app, array $options)
{
if ( ! isset($options['colorspaces'])) {
throw new \InvalidArgumentException('Missing "colorspaces" options');
}
$this->colorspaces = array_map('strtolower', (array) $options['colorspaces']);
parent::__construct($app);
}
public function check(EntityManager $em, File $file)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -19,7 +20,7 @@ class Dimension extends AbstractChecker
protected $width;
protected $height;
public function __construct(array $options)
public function __construct(Application $app, array $options)
{
if ( ! isset($options['width'])) {
throw new \InvalidArgumentException('Missing "width" option');
@@ -35,6 +36,7 @@ class Dimension extends AbstractChecker
$this->width = $options['width'];
$this->height = $options['height'];
parent::__construct($app);
}
public function check(EntityManager $em, File $file)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -18,13 +19,14 @@ class Extension extends AbstractChecker
{
protected $extensions;
public function __construct(array $options)
public function __construct(Application $app, array $options)
{
if ( ! isset($options['extensions'])) {
throw new \InvalidArgumentException('Missing "extensions" options');
}
$this->extensions = array_map('strtolower', (array) $options['extensions']);
parent::__construct($app);
}
public function check(EntityManager $em, File $file)

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -26,13 +27,14 @@ class Filename extends AbstractChecker
*
* @param boolean $sensitive Toggle case-sensitive mode, default : false
*/
public function __construct(array $options = array())
public function __construct(Application $app, array $options = array())
{
if ( ! isset($options['sensitive'])) {
$options['sensitive'] = false;
}
$this->sensitive = (boolean) $options['sensitive'];
parent::__construct($app);
}
/**

View File

@@ -11,31 +11,35 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
use MediaVorus\Media\MediaInterface;
class MediaType extends AbstractChecker
{
protected $mediaTypes;
const TYPE_AUDIO = \MediaVorus\Media\Media::TYPE_AUDIO;
const TYPE_DOCUMENT = \MediaVorus\Media\Media::TYPE_DOCUMENT;
const TYPE_FLASH = \MediaVorus\Media\Media::TYPE_FLASH;
const TYPE_IMAGE = \MediaVorus\Media\Media::TYPE_IMAGE;
const TYPE_VIDEO = \MediaVorus\Media\Media::TYPE_VIDEO;
const TYPE_AUDIO = MediaInterface::TYPE_AUDIO;
const TYPE_DOCUMENT = MediaInterface::TYPE_DOCUMENT;
const TYPE_FLASH = MediaInterface::TYPE_FLASH;
const TYPE_IMAGE = MediaInterface::TYPE_IMAGE;
const TYPE_VIDEO = MediaInterface::TYPE_VIDEO;
public function __construct(array $options)
public function __construct(Application $app, array $options)
{
if ( ! isset($options['mediatypes'])) {
throw new \InvalidArgumentException('Missing "mediatypes" options');
}
$this->mediaTypes = (array) $options['mediatypes'];
parent::__construct($app);
}
public function check(EntityManager $em, File $file)
{
if (0 === count($this->mediaTypes)) { //if empty authorize all mediative
// if empty authorize all mediative
if (0 === count($this->mediaTypes)) {
$boolean = true;
} else {
$boolean = in_array($file->getMedia()->getType(), $this->mediaTypes);

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -21,13 +22,18 @@ use Doctrine\ORM\EntityManager;
class Sha256 extends AbstractChecker
{
public function __construct(Application $app)
{
parent::__construct($app);
}
/**
* {@inheritdoc}
*/
public function check(EntityManager $em, File $file)
{
$boolean = ! count(\record_adapter::get_record_by_sha(
$file->getCollection()->get_databox()->get_sbas_id(), $file->getSha256()
$this->app, $file->getCollection()->get_databox()->get_sbas_id(), $file->getSha256()
));
return new Response($boolean, $this);

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Border\Checker;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\File;
use Doctrine\ORM\EntityManager;
@@ -20,13 +21,18 @@ use Doctrine\ORM\EntityManager;
class UUID extends AbstractChecker
{
public function __construct(Application $app)
{
parent::__construct($app);
}
/**
* {@inheritdoc}
*/
public function check(EntityManager $em, File $file)
{
$boolean = ! count(\record_adapter::get_record_by_uuid(
$file->getCollection()->get_databox(), $file->getUUID()
$this->app, $file->getCollection()->get_databox(), $file->getUUID()
));
return new Response($boolean, $this);

View File

@@ -11,14 +11,21 @@
namespace Alchemy\Phrasea\Border;
use Alchemy\Phrasea\Media\Type as MediaType;
use MediaVorus\Media\Media;
use Alchemy\Phrasea\Media\Type\Audio;
use Alchemy\Phrasea\Media\Type\Document;
use Alchemy\Phrasea\Media\Type\Flash;
use Alchemy\Phrasea\Media\Type\Image;
use Alchemy\Phrasea\Media\Type\Video;
use MediaVorus\Media\MediaInterface;
use MediaVorus\MediaVorus;
use MediaVorus\Exception\FileNotFoundException;
use PHPExiftool\Writer;
use PHPExiftool\Driver\TagFactory;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Metadata\MetadataBag;
use PHPExiftool\Driver\Value\Mono as MonoValue;
use PHPExiftool\Exiftool;
use PHPExiftool\Exception\ExceptionInterface as PHPExiftoolException;
/**
* Phraseanet candidate File package
@@ -33,7 +40,7 @@ class File
/**
*
* @var \MediaVorus\Media\Media
* @var \MediaVorus\Media\MediaInterface
*/
protected $media;
protected $uuid;
@@ -45,13 +52,13 @@ class File
/**
* Constructor
*
* @param Media $media The media
* @param \collection $collection The destination collection
* @param string $originalName The original name of the file
* @param MediaInterface $media The media
* @param \collection $collection The destination collection
* @param string $originalName The original name of the file
* (if not provided, original name is
* extracted from the pathfile)
*/
public function __construct(Media $media, \collection $collection, $originalName = null)
public function __construct(MediaInterface $media, \collection $collection, $originalName = null)
{
$this->media = $media;
$this->collection = $collection;
@@ -94,8 +101,8 @@ class File
'Canon:ImageUniqueID',
);
if ( ! $this->uuid) {
$metadatas = $this->media->getEntity()->getMetadatas();
if (! $this->uuid) {
$metadatas = $this->media->getMetadatas();
$uuid = null;
@@ -109,7 +116,7 @@ class File
}
}
if ( ! $uuid && $generate) {
if (! $uuid && $generate) {
/**
* @todo Check if a file exists with the same checksum
*/
@@ -120,7 +127,7 @@ class File
}
if ($write) {
$writer = new Writer();
$writer = new Writer(new Exiftool());
$value = new MonoValue($this->uuid);
$metadatas = new MetadataBag();
@@ -134,7 +141,7 @@ class File
*/
try {
$writer->write($this->getFile()->getRealPath(), $metadatas);
} catch (\PHPExiftool\Exception\Exception $e) {
} catch (PHPExiftoolException $e) {
}
}
@@ -151,20 +158,20 @@ class File
public function getType()
{
switch ($this->media->getType()) {
case Media::TYPE_AUDIO:
return new MediaType\Audio();
case MediaInterface::TYPE_AUDIO:
return new Audio();
break;
case Media::TYPE_DOCUMENT:
return new MediaType\Document();
case MediaInterface::TYPE_DOCUMENT:
return new Document();
break;
case Media::TYPE_FLASH:
return new MediaType\Flash();
case MediaInterface::TYPE_FLASH:
return new Flash();
break;
case Media::TYPE_IMAGE:
return new MediaType\Image();
case MediaInterface::TYPE_IMAGE:
return new Image();
break;
case Media::TYPE_VIDEO:
return new MediaType\Video();
case MediaInterface::TYPE_VIDEO:
return new Video();
break;
}
@@ -178,7 +185,7 @@ class File
*/
public function getSha256()
{
if ( ! $this->sha256) {
if (! $this->sha256) {
$this->sha256 = $this->media->getHash('sha256');
}
@@ -192,7 +199,7 @@ class File
*/
public function getMD5()
{
if ( ! $this->md5) {
if (! $this->md5) {
$this->md5 = $this->media->getHash('md5');
}
@@ -220,9 +227,9 @@ class File
}
/**
* Returns an instance of MediaVorus\Media\Media corresponding to the file
* Returns an instance of MediaVorus\Media\MediaInterface corresponding to the file
*
* @return MediaVorus\Media\Media
* @return MediaVorus\Media\MediaInterface
*/
public function getMedia()
{
@@ -240,7 +247,7 @@ class File
}
/**
* Returns an array of Attribute\Attribute associated to the file
* Returns an array of AttributeInterface associated to the file
*
* @return array
*/
@@ -252,10 +259,10 @@ class File
/**
* Adds an attribute to the file package
*
* @param Attribute\Attribute $attribute The attribute
* @param AttributeInterface $attribute The attribute
* @return File
*/
public function addAttribute(Attribute\Attribute $attribute)
public function addAttribute(AttributeInterface $attribute)
{
array_push($this->attributes, $attribute);
@@ -267,19 +274,18 @@ class File
*
* @param string $pathfile The path to the file
* @param \collection $collection The destination collection
* @param MediaVorus $mediavorus A MediaVorus object
* @param string $originalName An optionnal original name (if
* different from the $pathfile filename)
* @throws \InvalidArgumentException
*
* @return \Alchemy\Phrasea\Border\File
*/
public function buildFromPathfile($pathfile, \collection $collection, $originalName = null)
public function buildFromPathfile($pathfile, \collection $collection, MediaVorus $mediavorus, $originalName = null)
{
$core = \bootstrap::getCore();
try {
$media = $core['mediavorus']->guess(new \SplFileInfo($pathfile));
} catch (\MediaVorus\Exception\FileNotFoundException $e) {
$media = $mediavorus->guess($pathfile);
} catch (FileNotFoundException $e) {
throw new \InvalidArgumentException(sprintf('Unable to build media file from non existant %s', $pathfile));
}

View File

@@ -11,18 +11,31 @@
namespace Alchemy\Phrasea\Border;
use Alchemy\Phrasea\Metadata\Tag as PhraseaTag;
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
use Alchemy\Phrasea\Metadata\Tag\PdfText;
use Alchemy\Phrasea\Metadata\Tag\TfArchivedate;
use Alchemy\Phrasea\Metadata\Tag\TfBasename;
use Alchemy\Phrasea\Metadata\Tag\TfBits;
use Alchemy\Phrasea\Metadata\Tag\TfChannels;
use Alchemy\Phrasea\Metadata\Tag\TfDuration;
use Alchemy\Phrasea\Metadata\Tag\TfExtension;
use Alchemy\Phrasea\Metadata\Tag\TfFilename;
use Alchemy\Phrasea\Metadata\Tag\TfHeight;
use Alchemy\Phrasea\Metadata\Tag\TfMimetype;
use Alchemy\Phrasea\Metadata\Tag\TfQuarantine;
use Alchemy\Phrasea\Metadata\Tag\TfRecordid;
use Alchemy\Phrasea\Metadata\Tag\TfSize;
use Alchemy\Phrasea\Metadata\Tag\TfWidth;
use Alchemy\Phrasea\Border\Attribute\Metadata as MetadataAttr;
use Doctrine\ORM\EntityManager;
use Entities\LazaretAttribute;
use Entities\LazaretFile;
use Entities\LazaretSession;
use MediaAlchemyst\Exception\Exception as MediaAlchemystException;
use MediaAlchemyst\Specification\Image as ImageSpec;
use Monolog\Logger;
use PHPExiftool\Driver\Metadata\Metadata;
use PHPExiftool\Driver\Value\Mono as MonoValue;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use XPDF\PdfToText;
@@ -36,7 +49,7 @@ use XPDF\PdfToText;
class Manager
{
protected $checkers = array();
protected $em;
protected $app;
protected $filesystem;
protected $pdfToText;
@@ -48,13 +61,11 @@ class Manager
/**
* Constructor
*
* @param \Doctrine\ORM\EntityManager $em Entity manager
* @param \Monolog\Logger $logger A logger
* @param Application $app The application context
*/
public function __construct(EntityManager $em, Filesystem $filesystem)
public function __construct(Application $app)
{
$this->em = $em;
$this->filesystem = $filesystem;
$this->app = $app;
}
/**
@@ -63,7 +74,7 @@ class Manager
*/
public function __destruct()
{
$this->em = $this->filesystem = null;
$this->app = null;
}
/**
@@ -135,7 +146,7 @@ class Manager
$visa = new Visa();
foreach ($this->checkers as $checker) {
$visa->addResponse($checker->check($this->em, $file));
$visa->addResponse($checker->check($this->app['EM'], $file));
}
return $visa;
@@ -144,10 +155,10 @@ class Manager
/**
* Registers a checker
*
* @param Checker\CheckerInterface $checker The checker to register
* @param CheckerInterface $checker The checker to register
* @return Manager
*/
public function registerChecker(Checker\CheckerInterface $checker)
public function registerChecker(CheckerInterface $checker)
{
$this->checkers[] = $checker;
@@ -172,10 +183,10 @@ class Manager
/**
* Unregister a checker
*
* @param Checker\CheckerInterface $checker The checker to unregister
* @param CheckerInterface $checker The checker to unregister
* @return Manager
*/
public function unregisterChecker(Checker\CheckerInterface $checker)
public function unregisterChecker(CheckerInterface $checker)
{
$checkers = $this->checkers;
foreach ($this->checkers as $offset => $registered) {
@@ -202,8 +213,8 @@ class Manager
/**
* Find an available Lazaret filename and creates the empty file.
*
* @param string $filename The desired filename
* @param string $suffix A suffix to the filename
* @param string $filename The desired filename
* @param string $suffix A suffix to the filename
* @return string The available filename to use
*/
protected function bookLazaretPathfile($filename, $suffix = '')
@@ -212,14 +223,14 @@ class Manager
$infos = pathinfo($output);
$n = 0;
$this->filesystem->mkdir(__DIR__ . '/../../../../tmp/lazaret');
$this->app['filesystem']->mkdir(__DIR__ . '/../../../../tmp/lazaret');
while (true) {
$output = sprintf('%s/%s-%d%s', $infos['dirname'], $infos['filename'], ++ $n, (isset($infos['extension']) ? '.' . $infos['extension'] : ''));
try {
if ( ! $this->filesystem->exists($output)) {
$this->filesystem->touch($output);
if ( ! $this->app['filesystem']->exists($output)) {
$this->app['filesystem']->touch($output);
break;
}
} catch (IOException $e) {
@@ -238,35 +249,33 @@ class Manager
*/
protected function createRecord(File $file)
{
$element = \record_adapter::createFromFile($file, $this->filesystem);
$element = \record_adapter::createFromFile($file, $this->app);
$date = new \DateTime();
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfArchivedate(), new MonoValue($date->format('Y/m/d H:i:s'))
new TfArchivedate(), new MonoValue($date->format('Y/m/d H:i:s'))
)
)
);
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfRecordid(), new MonoValue($element->get_record_id())
new TfRecordid(), new MonoValue($element->get_record_id())
)
)
);
$metadatas = array();
$fileEntity = $file->getMedia()->getEntity();
/**
* @todo $key is not tagname but fieldname
*/
$fieldToKeyMap = array();
if ( ! $fieldToKeyMap) {
if (! $fieldToKeyMap) {
foreach ($file->getCollection()->get_databox()->get_meta_structure() as $databox_field) {
$tagname = $databox_field->get_tag()->getTagname();
@@ -279,7 +288,7 @@ class Manager
}
}
foreach ($fileEntity->getMetadatas() as $metadata) {
foreach ($file->getMedia()->getMetadatas() as $metadata) {
$key = $metadata->getTag()->getTagname();
@@ -303,7 +312,7 @@ class Manager
* @todo implement METATAG aka metadata by fieldname (where as
* current metadata is metadata by source.
*/
case Attribute\Attribute::NAME_METAFIELD:
case AttributeInterface::NAME_METAFIELD:
$key = $attribute->getField()->get_name();
@@ -314,7 +323,7 @@ class Manager
$metadatas[$key] = array_merge($metadatas[$key], array($attribute->getValue()));
break;
case Attribute\Attribute::NAME_METADATA:
case AttributeInterface::NAME_METADATA:
$key = $attribute->getValue()->getTag()->getTagname();
@@ -330,12 +339,12 @@ class Manager
$metadatas[$k] = array_merge($metadatas[$k], $attribute->getValue()->getValue()->asArray());
}
break;
case Attribute\Attribute::NAME_STATUS:
case AttributeInterface::NAME_STATUS:
$element->set_binary_status($element->get_status() | $attribute->getValue());
break;
case Attribute\Attribute::NAME_STORY:
case AttributeInterface::NAME_STORY:
$story = $attribute->getValue();
@@ -418,7 +427,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfQuarantine(), new MonoValue($date->format('Y/m/d H:i:s'))
new TfQuarantine(), new MonoValue($date->format('Y/m/d H:i:s'))
)
)
);
@@ -426,17 +435,15 @@ class Manager
$lazaretPathname = $this->bookLazaretPathfile($file->getOriginalName());
$lazaretPathnameThumb = $this->bookLazaretPathfile($file->getOriginalName(), 'thumb');
$this->filesystem->copy($file->getFile()->getRealPath(), $lazaretPathname, true);
$this->app['filesystem']->copy($file->getFile()->getRealPath(), $lazaretPathname, true);
$spec = new ImageSpec();
$spec->setResizeMode(ImageSpec::RESIZE_MODE_INBOUND_FIXEDRATIO);
$spec->setDimensions(375, 275);
$core = \bootstrap::getCore();
try {
$core['media-alchemyst']
$this->app['media-alchemyst']
->open($file->getFile()->getPathname())
->turnInto($lazaretPathnameThumb, $spec)
->close();
@@ -457,7 +464,7 @@ class Manager
$lazaretFile->setSession($session);
$this->em->persist($lazaretFile);
$this->app['EM']->persist($lazaretFile);
foreach ($file->getAttributes() as $fileAttribute) {
$attribute = new LazaretAttribute();
@@ -467,7 +474,7 @@ class Manager
$lazaretFile->addLazaretAttribute($attribute);
$this->em->persist($attribute);
$this->app['EM']->persist($attribute);
}
foreach ($visa->getResponses() as $response) {
@@ -479,11 +486,11 @@ class Manager
$lazaretFile->addLazaretCheck($check);
$this->em->persist($check);
$this->app['EM']->persist($check);
}
}
$this->em->flush();
$this->app['EM']->flush();
return $lazaretFile;
}
@@ -502,7 +509,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfWidth(), new MonoValue($file->getMedia()->getWidth())
new TfWidth(), new MonoValue($file->getMedia()->getWidth())
)
)
);
@@ -511,7 +518,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfHeight(), new MonoValue($file->getMedia()->getHeight())
new TfHeight(), new MonoValue($file->getMedia()->getHeight())
)
)
);
@@ -520,7 +527,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfChannels(), new MonoValue($file->getMedia()->getChannels())
new TfChannels(), new MonoValue($file->getMedia()->getChannels())
)
)
);
@@ -529,7 +536,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfBits(), new MonoValue($file->getMedia()->getColorDepth())
new TfBits(), new MonoValue($file->getMedia()->getColorDepth())
)
)
);
@@ -538,7 +545,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfDuration(), new MonoValue($file->getMedia()->getDuration())
new TfDuration(), new MonoValue($file->getMedia()->getDuration())
)
)
);
@@ -554,7 +561,7 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\PdfText(), new MonoValue($text)
new PdfText(), new MonoValue($text)
)
)
);
@@ -569,29 +576,29 @@ class Manager
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfMimetype(), new MonoValue($file->getFile()->getMimeType()))));
new TfMimetype(), new MonoValue($file->getFile()->getMimeType()))));
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfSize(), new MonoValue($file->getFile()->getSize()))));
new TfSize(), new MonoValue($file->getFile()->getSize()))));
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME))
new TfBasename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_BASENAME))
)
)
);
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME))
new TfFilename(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_FILENAME))
)
)
);
$file->addAttribute(
new MetadataAttr(
new Metadata(
new PhraseaTag\TfExtension(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_EXTENSION))
new TfExtension(), new MonoValue(pathinfo($file->getOriginalName(), PATHINFO_EXTENSION))
)
)
);