forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#10362 include editorName when logging an editorial decision
- Loading branch information
1 parent
8d8ada9
commit 6aca2bb
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
classes/migration/upgrade/v3_5_0/I10362_EventLogEditorNames.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/I10362_EventLogEditorNames.php | ||
* | ||
* Copyright (c) 2024 Simon Fraser University | ||
* Copyright (c) 2024 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class I10362_EventLogEditorNames | ||
* | ||
* @brief Adds missing editorName settings to the event log. | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\v3_5_0; | ||
|
||
use APP\facades\Repo; | ||
use Illuminate\Database\Query\JoinClause; | ||
use Illuminate\Support\Facades\DB; | ||
use PKP\install\DowngradeNotSupportedException; | ||
use PKP\migration\Migration; | ||
|
||
class I10362_EventLogEditorNames extends Migration | ||
{ | ||
|
||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
$idsToUpdate = DB::table('event_log as e') | ||
->select('e.log_id', 'e.user_id', 'e.event_type') | ||
->leftJoin('event_log_settings as es', function (JoinClause $join) { | ||
$join->on('es.log_id', '=', 'e.log_id') | ||
->where('es.setting_name', '=', 'editorName'); | ||
}) | ||
->whereNull('es.log_id') | ||
->whereIn('e.event_type', [ | ||
0x30000003, // PKPSubmissionEventLogEntry::SUBMISSION_LOG_EDITOR_DECISION | ||
0x30000004 // PKPSubmissionEventLogEntry::SUBMISSION_LOG_EDITOR_RECOMMENDATION | ||
]) | ||
->orderBy('e.log_id') | ||
->pluck('user_id', 'log_id'); | ||
|
||
$inserts = []; | ||
foreach ($idsToUpdate as $eventLogId => $userId) { | ||
$editorName = Repo::user()->get($userId)->getFullName(); | ||
|
||
if ($editorName) { | ||
$inserts[] = [ | ||
'log_id' => $eventLogId, | ||
'setting_name' => 'editorName', | ||
'setting_value' => $editorName | ||
]; | ||
} | ||
} | ||
|
||
DB::table('event_log_settings') | ||
->insert($inserts); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
* | ||
* @throws DowngradeNotSupportedException | ||
*/ | ||
public function down(): void | ||
{ | ||
throw new DowngradeNotSupportedException(); | ||
} | ||
} |