PHRAS-2797 retrieve available subdef in event record.sub_definitions_created

This commit is contained in:
aynsix
2019-10-30 14:19:13 +04:00
parent a318e7c004
commit 2163f0452d

View File

@@ -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,6 +171,27 @@ class SubdefGenerator
unset($this->tmpFilePath);
}
// 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(
@@ -178,6 +200,7 @@ class SubdefGenerator
)
);
}
}
/**
* set a logger to use
@@ -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);
}
}