From 8a2bfd60bd1e818b3475f219755dd5af1a13b860 Mon Sep 17 00:00:00 2001 From: dxL1nus Date: Mon, 6 Jul 2026 11:36:28 +0200 Subject: [PATCH 1/5] Status is saved and updated in Github Register Issue, status will be pending initially #141, #132 --- CodecheckPlugin.php | 15 ++++++++----- api/v1/CodecheckApiHandler.php | 21 +++++++----------- .../CodecheckGithubRegisterIssue.php | 9 ++++++-- classes/Constants.php | 1 + classes/Workflow/CodecheckStatusHandler.php | 17 ++++++++------ .../js/Components/CodecheckStatusForm.vue | 22 ++++++++++++++----- 6 files changed, 52 insertions(+), 33 deletions(-) diff --git a/CodecheckPlugin.php b/CodecheckPlugin.php index 2c462a72..557fc50d 100644 --- a/CodecheckPlugin.php +++ b/CodecheckPlugin.php @@ -115,15 +115,18 @@ public function validatePublicationHook(string $hookName, array $args): bool public function addCodecheckStatusLocalizations($hookName, $args) { $templateMgr = $args[0]; + + $localeKeys = array_combine( + Constants::CODECHECK_STATUSES, + array_map(fn($status) => __($status), Constants::CODECHECK_STATUSES) + ); + + $localeKeys[Constants::CODECHECK_STATUS_PENDING] = __(Constants::CODECHECK_STATUS_PENDING); + $templateMgr->addJavaScript( 'codecheck-locale-status', 'pkp.localeKeys = pkp.localeKeys || {};' . - 'Object.assign(pkp.localeKeys, ' . json_encode( - array_combine( - Constants::CODECHECK_STATUSES, - array_map(fn($status) => __($status), Constants::CODECHECK_STATUSES) - ) - ) . ');', + 'Object.assign(pkp.localeKeys, ' . json_encode($localeKeys) . ');', ['inline' => true, 'contexts' => ['backend']] ); return false; diff --git a/api/v1/CodecheckApiHandler.php b/api/v1/CodecheckApiHandler.php index 96292c0f..b8317c6f 100644 --- a/api/v1/CodecheckApiHandler.php +++ b/api/v1/CodecheckApiHandler.php @@ -972,15 +972,6 @@ public function getCurrentStatus(): void $statusRecord = CodecheckStatusHandler::getCurrentStatusData($submissionId); - if($statusRecord == null) { - JsonResponse::staticResponse([ - 'success' => false, - 'error' => "There doesn't exist any Status in the OJS Databse for this submission Id yet.", - 'statusRecord' => null, - 'allStatuses' => Constants::CODECHECK_STATUSES, - ], 500); - } - JsonResponse::staticResponse([ 'success' => true, 'statusRecord' => $statusRecord, @@ -990,14 +981,18 @@ public function getCurrentStatus(): void public function getStatusHistory(): void { + CodecheckLogger::debug("Get Status History"); $submissionId = (int) $this->codecheckMetadataHandler->getSubmissionId(); $statusHistory = CodecheckStatusHandler::getStatusDataHistory($submissionId); - if($statusHistory == null) { + CodecheckLogger::debug(print_r($statusHistory, true)); + + if(empty($statusHistory)) { JsonResponse::staticResponse([ 'success' => false, - 'statusHistory' => $statusHistory, + 'error' => "Currently there is no recorded CODECHECK status history for this submission ID in the OJS database.", + 'statusHistory' => null, ], 400); } @@ -1038,13 +1033,13 @@ public function updateStatus(): void } $statusUpdate = CodecheckStatusHandler::automaticStatusUpdate($submissionMetadata); - if($statusUpdate == null) { + if(empty($statusUpdate)) { JsonResponse::staticResponse([ 'success' => false, 'statusRecord' => $statusUpdate, 'allStatuses' => Constants::CODECHECK_STATUSES, 'error' => "Status doesn't need to be automatically updated." - ], 200); + ], 400); } else { JsonResponse::staticResponse([ 'success' => true, diff --git a/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php b/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php index 3e8578d9..d10f2ae5 100644 --- a/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php +++ b/classes/CodecheckRegister/CodecheckGithubRegisterIssue.php @@ -4,6 +4,7 @@ use APP\plugins\generic\codecheck\classes\CodecheckRegister\CertificateIdentifier; use APP\plugins\generic\codecheck\classes\CodecheckRegister\CodecheckIssueLabels; +use APP\plugins\generic\codecheck\classes\Workflow\CodecheckStatusHandler; class CodecheckGithubRegisterIssue { private string $repositoryOwner; @@ -13,6 +14,7 @@ class CodecheckGithubRegisterIssue { private string $submissionID; private array $labels; private string $jsonEncodedCodecheckMetadata; + private string $codecheckStatus; public function __construct( string $repositoryOwner, @@ -29,6 +31,7 @@ public function __construct( $this->repositoryOwner = $repositoryOwner; $this->repository = $repository; $this->submissionID = $submissionID; + $this->codecheckStatus = CodecheckStatusHandler::getCurrentStatusData($this->submissionID)->status; $authorString = empty($authorString) ? 'New CODECHECK' : $authorString; $this->title = $this->createTitleMarkdown($authorString, $certificateIdentifier); $this->jsonEncodedCodecheckMetadata = $this->createJsonEncodedCodecheckMetadataMarkdown($authorString, $certificateIdentifier, $journalName, $submissionID, $codecheckers, $repositories); @@ -77,6 +80,7 @@ private function createJsonEncodedCodecheckMetadataMarkdown( . "```json\n" . "{" . "\n\t\"identifier\": \"" . $certificateIdentifier->toStr() . "\"," + . "\n\t\"status\": \"" . $this->codecheckStatus . "\"," . "\n\t\"repositories\": " . json_encode($repositories) . "," . "\n\t\"codecheckers\": " . json_encode($codecheckers) . "," . "\n\t\"links\": []," @@ -99,8 +103,9 @@ private function createBodyMarkdown( return "\n## " . $paperTitle . "\n\n" . "\n**Article:**\n\n" . "\n**Journal:** " . $journalName . " *(Submission ID: " . $this->submissionID . ")*\n\n" - . "\n**Repositories:**\n" - . $repoStr; + . "\n**Repositories:**\n" . $repoStr . "\n\n" + . "\n**CODECHECK Status:** " + . __($this->codecheckStatus) . "\n\n"; } private function fillLabels( diff --git a/classes/Constants.php b/classes/Constants.php index aaf6fdbf..db601b23 100644 --- a/classes/Constants.php +++ b/classes/Constants.php @@ -26,6 +26,7 @@ class Constants /** * The possible Codecheck Statuses */ + public const CODECHECK_STATUS_PENDING = 'plugins.generic.codecheck.status.pending'; public const CODECHECK_STATUS_NEEDS_CODECHECKER = 'plugins.generic.codecheck.status.needsCodechecker'; public const CODECHECK_STATUS_ASSIGNED_CODECHECKER = 'plugins.generic.codecheck.status.assignedCodechecker'; public const CODECHECK_STATUS_STALLED_AUTHOR = 'plugins.generic.codecheck.status.stalled.author'; diff --git a/classes/Workflow/CodecheckStatusHandler.php b/classes/Workflow/CodecheckStatusHandler.php index 74d68bf2..c905c84c 100644 --- a/classes/Workflow/CodecheckStatusHandler.php +++ b/classes/Workflow/CodecheckStatusHandler.php @@ -4,22 +4,27 @@ use Illuminate\Support\Facades\DB; use APP\plugins\generic\codecheck\classes\Constants; +use APP\plugins\generic\codecheck\classes\Log\CodecheckLogger; class CodecheckStatusHandler { - public static function getCurrentStatusData(int $submissionId): object|null { - return DB::table('codecheck_status') + public static function getCurrentStatusData(int $submissionId): object { + $codecheckStatus = DB::table('codecheck_status') ->where('submission_id', $submissionId) ->orderBy('timestamp', 'desc') ->orderBy('status_id', 'desc') ->first(); + + return $codecheckStatus ?? (object) ['status' => 'plugins.generic.codecheck.status.pending']; } public static function getStatusDataHistory(int $submissionId): object|null { - return DB::table('codecheck_status') + $statusHistory = DB::table('codecheck_status') ->where('submission_id', $submissionId) ->orderBy('timestamp', 'desc') ->orderBy('status_id', 'desc') ->get(); + + return $statusHistory->isEmpty() ? null : $statusHistory; } public static function updateStatus(int $submissionId, string $status, int $userId): object|false { @@ -43,11 +48,9 @@ public static function automaticStatusUpdate(array $submissionMetadata): object| $submissionId = $submissionMetadata['submissionId']; $statusHistory = CodecheckStatusHandler::getStatusDataHistory($submissionId); - error_log("Status History: " . json_encode($statusHistory)); - error_log("Status History count: " . $statusHistory->count()); - error_log("Is null: " . ($statusHistory === null ? 'true' : 'false')); + CodecheckLogger::debug("Status History: " . json_encode($statusHistory)); - if($statusHistory == null || $statusHistory->count() < 2) { + if(empty($statusHistory) || $statusHistory->count() < 2) { $status = Constants::CODECHECK_STATUS_NEEDS_CODECHECKER; if(!empty($submissionMetadata['codecheck']['codecheckers'])) { $status = Constants::CODECHECK_STATUS_ASSIGNED_CODECHECKER; diff --git a/resources/js/Components/CodecheckStatusForm.vue b/resources/js/Components/CodecheckStatusForm.vue index c1cb5940..7153c096 100644 --- a/resources/js/Components/CodecheckStatusForm.vue +++ b/resources/js/Components/CodecheckStatusForm.vue @@ -1,9 +1,10 @@