mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
PHRAS-4033 Log_docs - log subdefinition build and write metadata - WorkerRunningJobs (#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 <maillat@alchemy.fr>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Exception\SessionNotFound;
|
||||
use Alchemy\Phrasea\Model\Entities\SessionModule;
|
||||
use Alchemy\Phrasea\Model\Entities\WorkerRunningJob;
|
||||
|
||||
class Session_Logger
|
||||
{
|
||||
@@ -38,6 +39,8 @@ class Session_Logger
|
||||
const EVENT_STATUS = 'status';
|
||||
const EVENT_SUBSTITUTE = 'substit';
|
||||
const EVENT_VALIDATE = 'validate';
|
||||
const EVENT_SUBDEFCREATION = 'subdefCreation';
|
||||
const EVENT_WRITEMETADATAS = 'writeMetadatas';
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -63,16 +66,17 @@ class Session_Logger
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function log(record_adapter $record, $action, $final, $comment, $coll_id_from=null)
|
||||
public function log(record_adapter $record, $action, $final, $comment, $coll_id_from = null, DateTime $date = null)
|
||||
{
|
||||
$sql = 'INSERT INTO log_docs
|
||||
(id, log_id, date, record_id, coll_id_from, coll_id, action, final, comment)
|
||||
VALUES (null, :log_id, NOW(), :record_id, :coll_id_from, :coll_id, :action, :final, :comm)';
|
||||
VALUES (null, :log_id, :date, :record_id, :coll_id_from, :coll_id, :action, :final, :comm)';
|
||||
|
||||
$stmt = $this->databox->get_connection()->prepare($sql);
|
||||
|
||||
$params = [
|
||||
':log_id' => $this->get_id(),
|
||||
':date' => ($date == null ) ? (new \DateTime('now'))->format(DATE_ATOM) : $date->format(DATE_ATOM),
|
||||
':record_id' => $record->getRecordId(),
|
||||
':coll_id_from' => $coll_id_from,
|
||||
':coll_id' => $record->getCollectionId(),
|
||||
@@ -269,4 +273,55 @@ class Session_Logger
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public function initOrUpdateLogDocsFromWorker(\record_adapter $record, \databox $databox, WorkerRunningJob $workerRunningJob, $subdefName, $action, DateTime $finished = null, $status = WorkerRunningJob::RUNNING)
|
||||
{
|
||||
$whereClause = ' date=:date AND record_id=:record_id AND action=:action AND final=:final';
|
||||
|
||||
$sqlCount = 'SELECT COUNT(id) as n FROM log_docs WHERE ' . $whereClause;
|
||||
|
||||
$params = [
|
||||
':date' => $workerRunningJob->getCreated()->format('Y-m-d H:i:s'),
|
||||
':record_id' => $record->getRecordId(),
|
||||
':action' => $workerRunningJob->getWork(),
|
||||
':final' => $subdefName
|
||||
];
|
||||
|
||||
$stmt = $databox->get_connection()->prepare($sqlCount);
|
||||
$stmt->execute($params);
|
||||
$count = $stmt->fetchColumn(0);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$comment = json_encode([
|
||||
'finished' => empty($finished) ? '' : $finished->format('Y-m-d H:i:s'),
|
||||
'duration' => empty($finished) ? '' : $finished->getTimestamp() - $workerRunningJob->getCreated()->getTimestamp() ,
|
||||
'status' => $status
|
||||
]);
|
||||
|
||||
if ($count > 0) {
|
||||
$sql = "UPDATE log_docs SET comment=:comment WHERE " . $whereClause;
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
|
||||
$p = [
|
||||
':comment' => $comment,
|
||||
':date' => $workerRunningJob->getCreated()->format('Y-m-d H:i:s'),
|
||||
':record_id' => $record->getRecordId(),
|
||||
':action' => $workerRunningJob->getWork(),
|
||||
':final' => $subdefName
|
||||
];
|
||||
|
||||
$stmt->execute($p);
|
||||
$stmt->closeCursor();
|
||||
} else {
|
||||
// insert to log_docs
|
||||
$this->log(
|
||||
$record,
|
||||
$action,
|
||||
$subdefName,
|
||||
$comment,
|
||||
null,
|
||||
$workerRunningJob->getCreated()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
71
lib/classes/patch/418RC10PHRAS4033.php
Normal file
71
lib/classes/patch/418RC10PHRAS4033.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
|
||||
class patch_418RC10PHRAS4033 implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '4.1.8-rc10';
|
||||
|
||||
/** @var array */
|
||||
private $concern = [base::DATA_BOX];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDoctrineMigrations()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $base, Application $app)
|
||||
{
|
||||
if ($base->get_base_type() === base::DATA_BOX) {
|
||||
$this->patch_databox($base, $app);
|
||||
} elseif ($base->get_base_type() === base::APPLICATION_BOX) {
|
||||
$this->patch_appbox($base, $app);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function patch_databox(databox $databox, Application $app)
|
||||
{
|
||||
$sql = "ALTER TABLE log_docs CHANGE action action ENUM('push','add','validate','edit','collection','status','print','substit','publish','download','mail','ftp','delete','subdefCreation','writeMetadatas','') CHARACTER SET ascii COLLATE ascii_bin NOT NULL";
|
||||
$stmt = $databox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
private function patch_appbox(base $appbox, Application $app)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user