buildsubdef with worker

This commit is contained in:
aynsix
2019-09-20 16:01:48 +04:00
parent 861785e7ab
commit 7541885637
11 changed files with 90 additions and 15 deletions

View File

@@ -133,9 +133,9 @@ $cli->command(new QueryParseCommand());
$cli->command(new QuerySampleCommand());
$cli->command(new FindConceptsCommand());
$cli->command($cli['alchemy_worker.commands.run_dispatcher_command']);
$cli->command($cli['alchemy_worker.commands.run_worker_command']);
$cli->command($cli['alchemy_worker.commands.show_configuration']);
//$cli->command($cli['alchemy_worker.commands.run_dispatcher_command']);
//$cli->command($cli['alchemy_worker.commands.run_worker_command']);
//$cli->command($cli['alchemy_worker.commands.show_configuration']);
$cli->loadPlugins();

View File

@@ -14,6 +14,8 @@ namespace Alchemy\Phrasea\Border;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
use Alchemy\Phrasea\Border\Attribute\AttributeInterface;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Metadata\Tag\TfArchivedate;
use Alchemy\Phrasea\Metadata\Tag\TfQuarantine;
@@ -333,7 +335,7 @@ class Manager
$this->app['phraseanet.metadata-setter']->replaceMetadata($newMetadata, $element);
if(!$nosubdef) {
$element->rebuild_subdefs();
$this->app['dispatcher']->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($element, true));
}
return $element;

View File

@@ -14,6 +14,8 @@ use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Controller\Exception as ControllerException;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Core\Event\RecordEdit;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Model\Entities\StoryWZ;
@@ -68,7 +70,9 @@ class StoryController extends Controller
break;
}
$story->set_metadatas($metadatas)->rebuild_subdefs();
$recordAdapter = $story->set_metadatas($metadatas);
// tell phraseanet to rebuild subdef
$this->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($recordAdapter));
$storyWZ = new StoryWZ();
$storyWZ->setUser($this->getAuthenticatedUser());

View File

@@ -16,6 +16,7 @@ use Alchemy\Phrasea\Application\Helper\SubDefinitionSubstituerAware;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Controller\RecordsRequest;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Metadata\PhraseanetMetadataReader;
use Alchemy\Phrasea\Metadata\PhraseanetMetadataSetter;
@@ -156,7 +157,7 @@ class ToolsController extends Controller
}
if (!$substituted || $force) {
$record->rebuild_subdefs();
$this->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($record));
}
}

View File

@@ -29,6 +29,8 @@ final class RecordEvents
const SUB_DEFINITIONS_CREATED = 'record.sub_definitions_created';
const SUB_DEFINITION_CREATION_FAILED = 'record.sub_definition_creation_failed';
const SUBDEFINITION_BUILD = 'record.subdefinition_build';
const MEDIA_SUBSTITUTED = 'record.media_substituted';
const STORY_COVER_CHANGED = 'record.story_cover_changed';

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Event\Record;
use Alchemy\Phrasea\Model\RecordInterface;
class SubdefinitionBuildEvent extends RecordEvent
{
private $isNewRecord;
public function __construct(RecordInterface $record, $isNewRecord = false)
{
parent::__construct($record);
$this->isNewRecord = $isNewRecord;
}
/**
* @return bool
*/
public function isNewRecord()
{
return $this->isNewRecord;
}
}

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Core\Event\Subscriber;
use Alchemy\Phrasea\Core\Event\Record\CollectionChangedEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Core\Event\RecordEdit;
use Alchemy\Phrasea\Core\PhraseaEvents;
use Alchemy\Phrasea\Metadata\Tag\TfEditdate;
@@ -26,10 +27,11 @@ class RecordEditSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents()
{
return array(
PhraseaEvents::RECORD_EDIT => 'onEdit',
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
RecordEvents::ROTATE => 'onRecordChange',
RecordEvents::COLLECTION_CHANGED => 'onCollectionChanged',
PhraseaEvents::RECORD_EDIT => 'onEdit',
PhraseaEvents::RECORD_UPLOAD => 'onEdit',
RecordEvents::ROTATE => 'onRecordChange',
RecordEvents::COLLECTION_CHANGED => 'onCollectionChanged',
RecordEvents::SUBDEFINITION_BUILD => 'onBuildSubdefs',
);
}
@@ -49,6 +51,12 @@ class RecordEditSubscriber implements EventSubscriberInterface
$recordAdapter->clearStampCache();
}
public function onBuildSubdefs(SubdefinitionBuildEvent $event)
{
$recordAdapter = $this->convertToRecordAdapter($event->getRecord());
$recordAdapter->rebuild_subdefs();
}
public function onEdit(RecordEdit $event)
{
static $into = false;

View File

@@ -167,6 +167,24 @@ class SubdefGenerator
);
}
/**
* set a logger to use
* @param LoggerInterface $logger
*/
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
/**
* to get the logger
* @return LoggerInterface
*/
public function getLogger()
{
return $this->logger;
}
private function generateSubdef(\record_adapter $record, \databox_subdef $subdef_class, $pathdest)
{
$start = microtime(true);

View File

@@ -13,6 +13,7 @@ namespace Alchemy\Phrasea\Media;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\Record\MediaSubstitutedEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Filesystem\FilesystemService;
use MediaAlchemyst\Alchemyst;
use MediaAlchemyst\Exception\ExceptionInterface as MediaAlchemystException;
@@ -79,7 +80,7 @@ class SubdefSubstituer
$record->write_metas();
if ($shouldSubdefsBeRebuilt) {
$record->rebuild_subdefs();
$this->dispatcher->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($record));
}
$this->dispatcher->dispatch(RecordEvents::MEDIA_SUBSTITUTED, new MediaSubstitutedEvent($record));

View File

@@ -12,6 +12,8 @@
namespace Alchemy\Phrasea\TaskManager\Job;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Exception\RuntimeException;
use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\Border\Manager as borderManager;
@@ -1001,7 +1003,7 @@ class ArchiveJob extends AbstractJob
{
// quick fix to reconnect if mysql is lost
$app->getApplicationBox()->get_connection();
$databox->get_connection();
$collection->get_connection();
$status = \databox_status::operation_or($stat0, $stat1);
@@ -1032,7 +1034,8 @@ class ArchiveJob extends AbstractJob
}
$story->setStatus(\databox_status::operation_or($stat0, $stat1));
$story->rebuild_subdefs();
$app['dispatcher']->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($story));
unset($media);

View File

@@ -19,6 +19,7 @@ use Alchemy\Phrasea\Core\Event\Record\OriginalNameChangedEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvents;
use Alchemy\Phrasea\Core\Event\Record\StatusChangedEvent;
use Alchemy\Phrasea\Core\Event\Record\SubdefinitionBuildEvent;
use Alchemy\Phrasea\Core\PhraseaTokens;
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
use Alchemy\Phrasea\Filesystem\FilesystemService;
@@ -284,7 +285,7 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
$this->getDataboxConnection()->executeUpdate($sql, ['type' => $type, 'record_id' => $this->getRecordId()]);
if ($old_type !== $type) {
$this->rebuild_subdefs();
$this->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($this));
}
$this->type = $type;
@@ -341,7 +342,8 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
array(':mime' => $mime, ':record_id' => $this->getRecordId())
)) {
$this->rebuild_subdefs();
$this->dispatch(RecordEvents::SUBDEFINITION_BUILD, new SubdefinitionBuildEvent($this));
$this->delete_data_from_cache();
}