mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
PHRAS-2797 retrieve available subdef in event record.sub_definitions_created
This commit is contained in:
@@ -18,6 +18,7 @@ use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreationEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\SubDefinitionCreationFailedEvent;
|
||||
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
|
||||
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
|
||||
use Alchemy\Phrasea\Filesystem\FilesystemService;
|
||||
use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification;
|
||||
use MediaAlchemyst\Alchemyst;
|
||||
@@ -170,13 +171,35 @@ class SubdefGenerator
|
||||
unset($this->tmpFilePath);
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$mediaCreated
|
||||
)
|
||||
);
|
||||
// if we created subdef one by one
|
||||
if (count($wanted_subdefs) == 1) {
|
||||
$mediaSubdefRepository = $this->getMediaSubdefRepository($record->getDataboxId());
|
||||
$mediaSubdefs = $mediaSubdefRepository->findByRecordIdsAndNames([$record->getRecordId()]);
|
||||
$medias = [];
|
||||
foreach ($mediaSubdefs as $subdef) {
|
||||
try {
|
||||
$medias[$subdef->get_name()] = $this->mediavorus->guess($subdef->getRealPath());
|
||||
} catch (MediaVorusFileNotFoundException $e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$medias
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->dispatch(
|
||||
RecordEvents::SUB_DEFINITIONS_CREATED,
|
||||
new SubDefinitionsCreatedEvent(
|
||||
$record,
|
||||
$mediaCreated
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,4 +317,14 @@ class SubdefGenerator
|
||||
$i = floor(log($bytes, 1024));
|
||||
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','kB','MB','GB'][$i];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $databoxId
|
||||
*
|
||||
* @return MediaSubdefRepository|Object
|
||||
*/
|
||||
private function getMediaSubdefRepository($databoxId)
|
||||
{
|
||||
return $this->app['provider.repo.media_subdef']->getRepositoryForDatabox($databoxId);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user