Skip to content

Commit

Permalink
PHRAS-4033 Log_docs - log subdefinition build and write metadata - Wo…
Browse files Browse the repository at this point in the history
…rkerRunningJobs (#4482)

* workerRunningJob to logDocs

* add patch for alter table log_docs

* writemetadata log_docs from workingrunningjob and add icon

* generate translation

* update icon

* change size to 20px

---------

Co-authored-by: Nicolas Maillat <[email protected]>
  • Loading branch information
aynsix and nmaillat authored Mar 19, 2024
1 parent a3160ff commit 8a48978
Show file tree
Hide file tree
Showing 31 changed files with 856 additions and 433 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ PHRASEANET_DOCKER_REGISTRY=local

# Docker images tag.
# @run
PHRASEANET_DOCKER_TAG=4.1.8-rc9
PHRASEANET_DOCKER_TAG=4.1.8-rc10

# Stack Name
# An optionnal Name for the stack
Expand Down
2 changes: 1 addition & 1 deletion Phraseanet-production-client/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ module.exports = {
setupDir: _root + 'tests/setup/node.js',
karmaConf: _root + 'config/karma.conf.js',
// change this version when you change JS file for lazy loading
assetFileVersion: 102
assetFileVersion: 103
};
2 changes: 1 addition & 1 deletion Phraseanet-production-client/dist/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=102";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=103";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
Expand Down
2 changes: 1 addition & 1 deletion Phraseanet-production-client/dist/authenticate.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=102";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=103";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
Expand Down
2 changes: 1 addition & 1 deletion Phraseanet-production-client/dist/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=102";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".js?v=103";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
Expand Down
2 changes: 1 addition & 1 deletion Phraseanet-production-client/dist/commons.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=102";
/******/ script.src = __webpack_require__.p + "lazy-" + ({}[chunkId]||chunkId) + ".min.js?v=103";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
Expand Down
16 changes: 14 additions & 2 deletions Phraseanet-production-client/dist/production.css
Original file line number Diff line number Diff line change
Expand Up @@ -4405,6 +4405,14 @@ input.checkbox {
background-image: url("/assets/common/images/icons/ppen_history.png");
}

.history-subdefCreation {
background-image: url("/assets/common/images/icons/subdefCreation.png");
}

.history-writeMetadatas {
background-image: url("/assets/common/images/icons/writeMetadatas.png");
}

.history-validate {
background-image: url("/assets/common/images/icons/basket_validation.png");
}
Expand Down Expand Up @@ -4432,6 +4440,8 @@ input.checkbox {
background-image: url('/assets/common/images/icons/add.png');
}*/

.history-writeMetadatas,
.history-subdefCreation,
.history-collection,
.history-status,
.history-print,
Expand All @@ -4446,7 +4456,7 @@ input.checkbox {
.history-add {
background-repeat: no-repeat;
background-position: 3px center;
background-size: 24px;
background-size: 20px;
padding-left: 37px;
min-height: 16px;
}
Expand Down Expand Up @@ -4660,6 +4670,8 @@ td span.text_block_bold {
}

@media only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 13 / 10), only screen and (min-resolution: 120dpi) {
.history-writeMetadatas,
.history-subdefCreation,
.history-collection,
.history-status,
.history-print,
Expand All @@ -4671,7 +4683,7 @@ td span.text_block_bold {
.history-edit,
.history-validate,
.history-push {
background-size: 16px 16px;
background-size: 20px 20px;
}
}

Expand Down
2 changes: 1 addition & 1 deletion Phraseanet-production-client/dist/production.min.css

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions Phraseanet-production-client/src/prod/style/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@
background-image: url('#{$iconsPath}ppen_history.png');
}

.history-subdefCreation {
background-image: url('#{$iconsPath}subdefCreation.png');
}

.history-writeMetadatas {
background-image: url('#{$iconsPath}writeMetadatas.png');
}

.history-validate {
background-image: url('#{$iconsPath}basket_validation.png');
}
Expand All @@ -186,6 +194,8 @@
background-image: url('#{$iconsPath}add.png');
}*/

.history-writeMetadatas,
.history-subdefCreation,
.history-collection,
.history-status,
.history-print,
Expand All @@ -200,7 +210,7 @@
.history-add {
background-repeat: no-repeat;
background-position: 3px center;
background-size: 24px;
background-size: 20px;
padding-left: 37px;
min-height: 16px;
}
Expand Down Expand Up @@ -401,6 +411,8 @@ td span.text_block_bold {
@media only screen and (-webkit-min-device-pixel-ratio: 1.3),
only screen and (-o-min-device-pixel-ratio: 13/10),
only screen and (min-resolution: 120dpi) {
.history-writeMetadatas,
.history-subdefCreation,
.history-collection,
.history-status,
.history-print,
Expand All @@ -412,7 +424,7 @@ td span.text_block_bold {
.history-edit,
.history-validate,
.history-push {
background-size: 16px 16px;
background-size: 20px 20px;
}
}
.humane.humane-libnotify-info.humane-large {
Expand Down
2 changes: 1 addition & 1 deletion lib/Alchemy/Phrasea/Core/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Version
* @var string
*/

private $number = '4.1.8-rc9';
private $number = '4.1.8-rc10';

/**
* @var string
Expand Down
8 changes: 7 additions & 1 deletion lib/Alchemy/Phrasea/Twig/PhraseanetExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function getFilters()
return array(
new \Twig_SimpleFilter('sort_collections', array(CollectionHelper::class, 'sort')),
new \Twig_SimpleFilter('date_duration', array($this, 'getDuration')),
new \Twig_SimpleFilter('json_to_array', array($this, 'jsonToArray')),
);
}

Expand Down Expand Up @@ -62,7 +63,7 @@ public function getGlobals()
{
return [
// change this version when you change JS file to force the navigation to reload js file
'assetFileVersion' => 102
'assetFileVersion' => 103
];

}
Expand Down Expand Up @@ -397,6 +398,11 @@ public function getSubdefSize(RecordInterface $record, $subdefName)
return $ret;
}

public function jsonToArray($string)
{
return json_decode($string, true);
}

public function getUserSetting($setting, $default = null)
{
if (false === ($this->app->getAuthenticatedUser() instanceof User)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function register(Application $app)
$app['elasticsearch.indexer']
))
->setApplicationBox($app['phraseanet.appbox'])
->setDataboxLoggerLocator($app['phraseanet.logger'])
;
}));

Expand All @@ -100,6 +101,7 @@ public function register(Application $app)
->setApplicationBox($app['phraseanet.appbox'])
->setDispatcher($app['dispatcher'])
->setEntityManagerLocator(new LazyLocator($app, 'orm.em'))
->setDataboxLoggerLocator($app['phraseanet.logger'])
;
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function register(Application $app)
$app->extend('dispatcher', function (EventDispatcherInterface $dispatcher, Application $app) {

$dispatcher->addSubscriber(
new RecordSubscriber($app, new LazyLocator($app, 'phraseanet.appbox'))
(new RecordSubscriber($app, new LazyLocator($app, 'phraseanet.appbox')))
->setDataboxLoggerLocator($app['phraseanet.logger'])
);
$dispatcher->addSubscriber(new ExportSubscriber($app['alchemy_worker.message.publisher']));
$dispatcher->addSubscriber(new AssetsIngestSubscriber($app['alchemy_worker.message.publisher'], new LazyLocator($app, 'repo.worker-running-job')));
Expand Down
13 changes: 13 additions & 0 deletions lib/Alchemy/Phrasea/WorkerManager/Subscriber/RecordSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Alchemy\Phrasea\WorkerManager\Subscriber;

use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
use Alchemy\Phrasea\Core\Event\Record\DeletedEvent;
use Alchemy\Phrasea\Core\Event\Record\DeleteEvent;
use Alchemy\Phrasea\Core\Event\Record\RecordEvent;
Expand All @@ -27,6 +28,8 @@

class RecordSubscriber implements EventSubscriberInterface
{
use DataboxLoggerAware;

/** @var MessagePublisher $messagePublisher */
private $messagePublisher;

Expand Down Expand Up @@ -115,6 +118,9 @@ public function onSubdefinitionCreationFailure(SubdefinitionCreationFailureEvent
/** @var WorkerRunningJob $workerRunningJob */
$workerRunningJob = $repoWorker->find($event->getWorkerJobId());

$databox = $this->getApplicationBox()->get_databox($event->getRecord()->getDataboxId());
$record = $databox->getRecordRepository()->find($event->getRecord()->getRecordId());

if ($workerRunningJob) {
$em->beginTransaction();
try {
Expand All @@ -133,6 +139,8 @@ public function onSubdefinitionCreationFailure(SubdefinitionCreationFailureEvent
catch (Exception $e) {
$em->rollback();
}

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $event->getSubdefName(), \Session_Logger::EVENT_SUBDEFCREATION, new \DateTime('now'), WorkerRunningJob::ERROR);
}

$this->messagePublisher->publishRetryMessage(
Expand Down Expand Up @@ -274,6 +282,11 @@ public function onSubdefinitionWritemeta(SubdefinitionWritemetaEvent $event)
catch (Exception $e) {
$em->rollback();
}

$databox = $this->getApplicationBox()->get_databox($event->getRecord()->getDataboxId());
$record = $databox->getRecordRepository()->find($event->getRecord()->getRecordId());

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $event->getSubdefName(), \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::ERROR);
}

$this->messagePublisher->publishRetryMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Alchemy\Phrasea\WorkerManager\Worker;

use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
use Alchemy\Phrasea\Core\PhraseaTokens;
use Alchemy\Phrasea\Filesystem\FilesystemService;
use Alchemy\Phrasea\Media\SubdefGenerator;
use Alchemy\Phrasea\Model\Entities\WorkerRunningJob;
use Alchemy\Phrasea\Model\Repositories\WorkerRunningJobRepository;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer;
use Alchemy\Phrasea\WorkerManager\Event\StoryCreateCoverEvent;
Expand All @@ -21,6 +23,7 @@
class SubdefCreationWorker implements WorkerInterface
{
use ApplicationBoxAware;
use DataboxLoggerAware;

private $subdefGenerator;

Expand Down Expand Up @@ -98,6 +101,11 @@ public function process(array $payload)

// here we can work

/** @var WorkerRunningJob $workerRunningJob */
$workerRunningJob = $this->repoWorker->find($workerRunningJobId);

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_SUBDEFCREATION);

$this->subdefGenerator->setLogger($this->logger);

try {
Expand Down Expand Up @@ -193,6 +201,7 @@ public function process(array $payload)
// tell that we have finished to work on this file (=unlock)
$this->repoWorker->markFinished($workerRunningJobId);

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_SUBDEFCREATION, new \DateTime('now'), WorkerRunningJob::FINISHED);
}

public static function checkIfFirstChild(\record_adapter $story, \record_adapter $record)
Expand Down
14 changes: 14 additions & 0 deletions lib/Alchemy/Phrasea/WorkerManager/Worker/WriteMetadatasWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
namespace Alchemy\Phrasea\WorkerManager\Worker;

use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
use Alchemy\Phrasea\Application\Helper\DispatcherAware;
use Alchemy\Phrasea\Application\Helper\EntityManagerAware;
use Alchemy\Phrasea\Core\PhraseaTokens;
use Alchemy\Phrasea\Media\Subdef\Subdef;
use Alchemy\Phrasea\Metadata\TagFactory;
use Alchemy\Phrasea\Model\Entities\WorkerRunningJob;
use Alchemy\Phrasea\Model\Repositories\WorkerRunningJobRepository;
use Alchemy\Phrasea\WorkerManager\Event\SubdefinitionWritemetaEvent;
use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents;
Expand All @@ -30,6 +32,7 @@ class WriteMetadatasWorker implements WorkerInterface
use ApplicationBoxAware;
use DispatcherAware;
use EntityManagerAware;
use DataboxLoggerAware;

/** @var Logger */
private $logger;
Expand Down Expand Up @@ -98,13 +101,21 @@ public function process(array $payload)
return;
}

/** @var WorkerRunningJob $workerRunningJob */
$workerRunningJob = $this->repoWorker->find($workerRunningJobId);

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS);


if ($record->getMimeType() == 'image/svg+xml') {

$this->logger->error("Can't write meta on svg file!");

// tell that we have finished to work on this file ("unlock")
$this->repoWorker->markFinished($workerRunningJobId, "Can't write meta on svg file!");

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::ERROR);

return;
}

Expand Down Expand Up @@ -313,6 +324,7 @@ public function process(array $payload)

// tell that we have finished to work on this file (=unlock)
$this->repoWorker->markFinished($workerRunningJobId, $stopInfo);
$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::ERROR);
}
return ;
}
Expand All @@ -322,6 +334,8 @@ public function process(array $payload)

// tell that we have finished to work on this file (=unlock)
$this->repoWorker->markFinished($workerRunningJobId);

$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, \Session_Logger::EVENT_WRITEMETADATAS, new \DateTime('now'), WorkerRunningJob::FINISHED);
}

private function removeNulChar($value)
Expand Down
Loading

0 comments on commit 8a48978

Please sign in to comment.