Skip to content

Commit

Permalink
Merge pull request #1417 from Vitaliy-1/i8933_restore_original
Browse files Browse the repository at this point in the history
pkp/pkp-lib#8933 refactor event log
  • Loading branch information
Vitaliy-1 authored Jun 2, 2023
2 parents 691d418 + d2ab7c7 commit 4f500d5
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @file classes/log/SubmissionEventLogEntry.php
* @file classes/log/event/SubmissionEventLogEntry.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
Expand All @@ -16,9 +16,9 @@
* @brief Describes an entry in the submission history log.
*/

namespace APP\log;
namespace APP\log\event;

use PKP\log\PKPSubmissionEventLogEntry;
use PKP\log\event\PKPSubmissionEventLogEntry;

/**
* Log entry event types. All types must be defined here.
Expand All @@ -38,7 +38,7 @@ class SubmissionEventLogEntry extends PKPSubmissionEventLogEntry
}

if (!PKP_STRICT_MODE) {
class_alias('\APP\log\SubmissionEventLogEntry', '\SubmissionEventLogEntry');
class_alias('\APP\log\event\SubmissionEventLogEntry', '\SubmissionEventLogEntry');
foreach ([
'SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH',
'SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH',
Expand Down
96 changes: 96 additions & 0 deletions classes/migration/upgrade/v3_4_0/I8933_EventLogLocalized.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

/**
* @file classes/migration/upgrade/v3_4_0/I8933_EventLogLocalized.php
*
* Copyright (c) 2023 Simon Fraser University
* Copyright (c) 2023 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I8933_EventLogLocalized.php
*
* @brief Extends the event log migration with the correct table names for OJS.
*/

namespace APP\migration\upgrade\v3_4_0;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;

class I8933_EventLogLocalized extends \PKP\migration\upgrade\v3_4_0\I8933_EventLogLocalized
{
protected function getContextTable(): string
{
return 'presses';
}

protected function getContextIdColumn(): string
{
return 'press_id';
}

/**
* Run the migration.
*/
public function up(): void
{
parent::up();

// Get contexts with their primary locales
$contexts = DB::table('presses')->get(['press_id', 'primary_locale']);
// Add site primary locale at the end of the collection; to be used when associated context (based on a submission) cannot be determined
$contexts->push((object) [
'press_id' => null,
'primary_locale' => DB::table('site')->value('primary_locale')
]);
/**
* Update locale for localized settings by context primary locale.
* All event types using settings that require update have submission assoc type,
* we can join event logs with submissions table to get the context ID
*/
foreach ($contexts as $context) {
$idsToUpdate = DB::table('event_log as e')
->leftJoin('submissions as s', 'e.assoc_id', '=', 's.submission_id')
->where('assoc_type', 0x0100009) // PKPApplication::ASSOC_TYPE_SUBMISSION
->whereIn('event_type', [
268435475, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_REMOVE
268435474, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE
268435464, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH
268435465, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH
268435476, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_AVAILABLE
268435477, // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNAVAILABLE
])
->whereIn('e.log_id', function (Builder $qb) {
$qb->select('es.log_id')
->from('event_log_settings as es')
->whereIn('setting_name', ['publicationFormatName', 'filename']);
})
->where('s.context_id', $context->press_id)
->pluck('log_id');

foreach ($idsToUpdate->chunk(parent::CHUNK_SIZE) as $ids) {
DB::table('event_log_settings')->whereIn('log_id', $ids)->update(['locale' => $context->primary_locale]);
}
}
}

/**
* Add setting to the map for renaming
*/
protected function mapSettings(): Collection
{
$map = parent::mapSettings();
$map->put(268435475, [ // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_REMOVE
'formatName' => 'publicationFormatName'
]);
$map->put(0x50000007, [ // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE
'file' => 'filename',
'name' => 'userFullName'
]);
$map->put(268435474, [ // SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE
'formatName' => 'publicationFormatName'
]);
return $map;
}
}
2 changes: 1 addition & 1 deletion classes/services/NavigationMenuService.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function getDisplayStatusCallback($hookName, $args)
$templateMgr = TemplateManager::getManager(Application::get()->getRequest());

$isUserLoggedIn = Validation::isLoggedIn();
$isUserLoggedInAs = Validation::isLoggedInAs();
$isUserLoggedInAs = (bool) Validation::loggedInAs();
$context = $request->getContext();
$contextId = $context ? $context->getId() : Application::CONTEXT_ID_NONE;

Expand Down
17 changes: 14 additions & 3 deletions classes/services/PublicationFormatService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

use APP\core\Application;
use APP\facades\Repo;
use APP\log\SubmissionEventLogEntry;
use APP\log\event\SubmissionEventLogEntry;
use APP\press\Press;
use APP\publicationFormat\IdentificationCodeDAO;
use APP\publicationFormat\MarketDAO;
use APP\publicationFormat\PublicationDateDAO;
use APP\publicationFormat\PublicationFormat;
use APP\publicationFormat\SalesRightsDAO;
use PKP\core\Core;
use PKP\core\PKPApplication;
use APP\submission\Submission;
use PKP\db\DAORegistry;
use PKP\log\SubmissionLog;

class PublicationFormatService
{
Expand Down Expand Up @@ -68,6 +69,16 @@ public function deleteFormat($publicationFormat, $submission, $context)
}

// Log the deletion of the format.
SubmissionLog::logEvent(Application::get()->getRequest(), $submission, SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_REMOVE, 'submission.event.publicationFormatRemoved', ['formatName' => $publicationFormat->getLocalizedName()]);
$eventLog = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $submission->getId(),
'eventType' => SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_REMOVE,
'userId' => Application::get()->getRequest()->getUser()?->getId(),
'message' => 'submission.event.publicationFormatRemoved',
'isTranslated' => false,
'dateLogged' => Core::getCurrentDate(),
'publicationFormatName' => $publicationFormat->getData('name') // formatName
]);
Repo::eventLog()->add($eventLog);
}
}
59 changes: 39 additions & 20 deletions controllers/grid/catalogEntry/PublicationFormatGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use APP\core\Request;
use APP\core\Services;
use APP\facades\Repo;
use APP\log\SubmissionEventLogEntry;
use APP\log\event\SubmissionEventLogEntry;
use APP\notification\Notification;
use APP\notification\NotificationManager;
use APP\publication\Publication;
Expand All @@ -38,14 +38,14 @@
use PKP\controllers\grid\files\proof\form\ManageProofFilesForm;
use PKP\controllers\grid\GridColumn;
use PKP\controllers\grid\pubIds\form\PKPAssignPublicIdentifiersForm;
use PKP\core\Core;
use PKP\core\JSONMessage;
use PKP\core\PKPApplication;
use PKP\db\DAO;
use PKP\db\DAORegistry;
use PKP\linkAction\LinkAction;
use PKP\linkAction\request\AjaxModal;
use PKP\log\SubmissionFileEventLogEntry;
use PKP\log\SubmissionFileLog;
use PKP\log\SubmissionLog;
use PKP\log\event\SubmissionFileEventLogEntry;
use PKP\plugins\PluginRegistry;
use PKP\security\authorization\internal\RepresentationRequiredPolicy;
use PKP\security\authorization\PublicationAccessPolicy;
Expand Down Expand Up @@ -397,14 +397,17 @@ public function setApproved($args, $request)
$representation->setIsApproved($newApprovedState);
$representationDao->updateObject($representation);

// log the state changing of the format.
SubmissionLog::logEvent(
$request,
$this->getSubmission(),
$newApprovedState ? SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH : SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH,
$newApprovedState ? 'submission.event.publicationFormatPublished' : 'submission.event.publicationFormatUnpublished',
['publicationFormatName' => $representation->getLocalizedName()]
);
$logEntry = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $this->getSubmission()->getId(),
'eventType' => $newApprovedState ? SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH : SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH,
'userId' => $request->getUser()?->getId(),
'message' => $newApprovedState ? 'submission.event.publicationFormatPublished' : 'submission.event.publicationFormatUnpublished',
'isTranslated' => false,
'dateLogged' => Core::getCurrentDate(),
'publicationFormatName' => $representation->getData('name')
]);
Repo::eventLog()->add($logEntry);

// Update the formats tombstones.
$publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
Expand Down Expand Up @@ -443,13 +446,17 @@ public function setAvailable($args, $request)
$publicationFormatDao->updateObject($publicationFormat);

// log the state changing of the format.
SubmissionLog::logEvent(
$request,
$this->getSubmission(),
$newAvailableState ? SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_AVAILABLE : SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNAVAILABLE,
$newAvailableState ? 'submission.event.publicationFormatMadeAvailable' : 'submission.event.publicationFormatMadeUnavailable',
['publicationFormatName' => $publicationFormat->getLocalizedName()]
);
$logEntry = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $this->getSubmission()->getId(),
'eventType' => $newAvailableState ? SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_AVAILABLE : SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_UNAVAILABLE,
'userId' => $request->getUser()?->getId(),
'message' => $newAvailableState ? 'submission.event.publicationFormatMadeAvailable' : 'submission.event.publicationFormatMadeUnavailable',
'isTranslated' => false,
'dateLogged' => Core::getCurrentDate(),
'publicationFormatName' => $publicationFormat->getData('name')
]);
Repo::eventLog()->add($logEntry);

// Update the formats tombstones.
$publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
Expand Down Expand Up @@ -600,7 +607,19 @@ public function setProofFileCompletion($args, $request)

// Log the event
$user = $request->getUser();
SubmissionFileLog::logEvent($request, $submissionFile, SubmissionFileEventLogEntry::SUBMISSION_LOG_FILE_SIGNOFF_SIGNOFF, 'submission.event.signoffSignoff', ['file' => $submissionFile->getLocalizedData('name'), 'name' => $user->getFullName(), 'username' => $user->getUsername()]);
$eventLog = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION_FILE,
'assocId' => $submissionFile->getId(),
'eventType' => SubmissionFileEventLogEntry::SUBMISSION_LOG_FILE_SIGNOFF_SIGNOFF,
'userId' => $user->getId(),
'message' => 'submission.event.signoffSignoff',
'isTranslated' => false,
'dateLogged' => Core::getCurrentDate(),
'filename' => $submissionFile->getData('name'),
'userFullName' => $user->getFullName(),
'username' => $user->getUsername()
]);
Repo::eventLog()->add($eventLog);

return DAO::getDataChangedEvent();
}
Expand Down
18 changes: 15 additions & 3 deletions controllers/grid/catalogEntry/form/PublicationFormatForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,19 @@

use APP\codelist\ONIXCodelistItemDAO;
use APP\core\Application;
use APP\log\SubmissionEventLogEntry;
use APP\facades\Repo;
use APP\log\event\SubmissionEventLogEntry;
use APP\publication\Publication;
use APP\publicationFormat\IdentificationCodeDAO;
use APP\publicationFormat\PublicationFormat;
use APP\publicationFormat\PublicationFormatDAO;
use APP\submission\Submission;
use APP\template\TemplateManager;
use Exception;
use PKP\core\Core;
use PKP\core\PKPApplication;
use PKP\db\DAORegistry;
use PKP\form\Form;
use PKP\log\SubmissionLog;

class PublicationFormatForm extends Form
{
Expand Down Expand Up @@ -268,7 +270,17 @@ public function execute(...$functionParams)

if (!$existingFormat) {
// log the creation of the format.
SubmissionLog::logEvent(Application::get()->getRequest(), $this->getMonograph(), SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE, 'submission.event.publicationFormatCreated', ['formatName' => $publicationFormat->getLocalizedName()]);
$logEntry = Repo::eventLog()->newDataObject([
'assocType' => PKPApplication::ASSOC_TYPE_SUBMISSION,
'assocId' => $this->getMonograph()->getId(),
'eventType' => SubmissionEventLogEntry::SUBMISSION_LOG_PUBLICATION_FORMAT_CREATE,
'userId' => Application::get()->getRequest()->getUser()?->getId(),
'message' => 'submission.event.publicationFormatCreated',
'isTranslate' => false,
'dateLogged' => Core::getCurrentDate(),
'publicationFormatName' => $publicationFormat->getData('name')
]);
Repo::eventLog()->add($logEntry);
}

return $representationId;
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
<migration class="APP\migration\upgrade\v3_4_0\I8992_FixEmptyUrlPaths"/>
<migration class="APP\migration\upgrade\v3_4_0\I9040_DropSettingType"/>
<migration class="APP\migration\upgrade\v3_4_0\I9039_DropDeprecatedFields"/>
<migration class="APP\migration\upgrade\v3_4_0\I8933_EventLogLocalized"/>
<data file="dbscripts/xml/upgrade/3.4.0_preupdate_email_templates.xml" />
<note file="docs/release-notes/README-3.4.0" />
</upgrade>
Expand Down
2 changes: 1 addition & 1 deletion lib/pkp
Submodule pkp updated 60 files
+19 −13 api/v1/submissions/PKPSubmissionHandler.php
+1 −1 classes/announcement/Repository.php
+3 −3 classes/category/Repository.php
+29 −23 classes/controllers/grid/users/reviewer/PKPReviewerGridHandler.php
+0 −2 classes/core/PKPApplication.php
+1 −1 classes/db/DBDataXMLParser.php
+13 −13 classes/decision/Repository.php
+16 −11 classes/decision/types/traits/NotifyReviewers.php
+6 −0 classes/facades/Repo.php
+1 −1 classes/galley/Repository.php
+0 −212 classes/log/EventLogDAO.php
+0 −53 classes/log/SubmissionEventLogDAO.php
+0 −52 classes/log/SubmissionFileEventLogDAO.php
+0 −67 classes/log/SubmissionFileLog.php
+0 −88 classes/log/SubmissionLog.php
+110 −0 classes/log/event/Collector.php
+169 −0 classes/log/event/DAO.php
+3 −5 classes/log/event/EventLogEntry.php
+5 −7 classes/log/event/PKPSubmissionEventLogEntry.php
+152 −0 classes/log/event/Repository.php
+3 −5 classes/log/event/SubmissionFileEventLogEntry.php
+89 −0 classes/log/event/maps/Schema.php
+4 −4 classes/migration/install/LogMigration.php
+253 −0 classes/migration/upgrade/v3_4_0/I8933_EventLogLocalized.php
+2 −2 classes/migration/upgrade/v3_4_0/PreflightCheckMigration.php
+15 −8 classes/observers/listeners/LogSubmissionSubmitted.php
+47 −20 classes/publication/Repository.php
+17 −6 classes/security/Validation.php
+1 −1 classes/services/PKPNavigationMenuService.php
+1 −0 classes/services/PKPSchemaService.php
+7 −3 classes/submission/DAO.php
+38 −22 classes/submission/action/EditorAction.php
+17 −14 classes/submission/reviewer/ReviewerAction.php
+16 −15 classes/submission/reviewer/form/PKPReviewerReviewStep3Form.php
+75 −70 classes/submissionFile/Repository.php
+13 −12 classes/task/ReviewReminder.php
+1 −1 classes/template/PKPTemplateManager.php
+1 −2 classes/user/Repository.php
+107 −1 controllers/api/file/PKPManageFileApiHandler.php
+2 −2 controllers/grid/eventLog/EventLogGridCellProvider.php
+2 −2 controllers/grid/eventLog/EventLogGridRow.php
+5 −4 controllers/grid/eventLog/SubmissionEventLogGridHandler.php
+6 −10 controllers/grid/eventLog/SubmissionFileEventLogGridHandler.php
+1 −1 controllers/grid/settings/user/UserGridRow.php
+1 −1 controllers/grid/users/reviewer/ReviewerGridRow.php
+19 −3 controllers/grid/users/reviewer/form/ReinstateReviewerForm.php
+19 −15 controllers/grid/users/reviewer/form/ResendRequestReviewerForm.php
+17 −14 controllers/grid/users/reviewer/form/ReviewReminderForm.php
+19 −3 controllers/grid/users/reviewer/form/UnassignReviewerForm.php
+30 −5 controllers/grid/users/stageParticipant/StageParticipantGridHandler.php
+1 −1 controllers/grid/users/stageParticipant/StageParticipantGridRow.php
+13 −4 controllers/grid/users/stageParticipant/form/PKPStageParticipantNotifyForm.php
+8 −7 controllers/informationCenter/FileInformationCenterHandler.php
+20 −10 controllers/informationCenter/InformationCenterHandler.php
+3 −2 controllers/informationCenter/SubmissionInformationCenterHandler.php
+19 −3 controllers/wizard/fileUpload/FileUploadWizardHandler.php
+28 −6 js/controllers/wizard/fileUpload/FileUploadWizardHandler.js
+251 −0 schemas/eventLog.json
+2 −2 schemas/userGroup.json
+2 −1 templates/controllers/wizard/fileUpload/fileUploadWizard.tpl
13 changes: 13 additions & 0 deletions schemas/eventLog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"title": "Event Log",
"properties": {
"publicationFormatName": {
"type": "string",
"description": "The name of publication format being logged.",
"multilingual": true,
"validation": [
"nullable"
]
}
}
}

0 comments on commit 4f500d5

Please sign in to comment.