diff --git a/classes/migration/install/ReviewerRecommendationsMigration.php b/classes/migration/install/ReviewerRecommendationsMigration.php index f927aa898a9..8befefc42af 100644 --- a/classes/migration/install/ReviewerRecommendationsMigration.php +++ b/classes/migration/install/ReviewerRecommendationsMigration.php @@ -53,11 +53,6 @@ public function up(): void ->default(true) ->comment('The status which determine if will be showen in recommendation list'); - $table - ->boolean('removable') - ->default(true) - ->comment('Describe if system define and non removable'); - $table->timestamps(); }); diff --git a/classes/migration/upgrade/v3_6_0/I1660_ReviewerRecommendations.php b/classes/migration/upgrade/v3_6_0/I1660_ReviewerRecommendations.php index 4fcbb78bfd2..fa34197ef6c 100644 --- a/classes/migration/upgrade/v3_6_0/I1660_ReviewerRecommendations.php +++ b/classes/migration/upgrade/v3_6_0/I1660_ReviewerRecommendations.php @@ -47,7 +47,7 @@ public function up(): void { $this->recommendationInstallMigration->up(); - $this->seedNonRemovableRecommendations(); + $this->seedNonRemovableRecommendations($this->systemDefineNonRemovableRecommendations()); } /** @@ -59,15 +59,13 @@ public function down(): void } // TODO : Optimize the process if possible - protected function seedNonRemovableRecommendations(): void + protected function seedNonRemovableRecommendations(array $nonRemovablerecommendations): void { - $nonRemovablerecommendations = $this->systemDefineNonRemovableRecommendations(); - if (empty($nonRemovablerecommendations)) { return; } - $currentLocale = Locale::getLocale(); + // $currentLocale = Locale::getLocale(); $contextSupportedLocales = DB::table($this->recommendationInstallMigration->contextTable()) ->select($this->recommendationInstallMigration->contextPrimaryKey()) ->addSelect([ @@ -93,7 +91,6 @@ protected function seedNonRemovableRecommendations(): void $recommendations[$recommendationValue] = [ 'contextId' => null, 'value' => $recommendationValue, - 'removable' => 0, 'status' => 1, 'title' => [], ]; @@ -111,14 +108,18 @@ protected function seedNonRemovableRecommendations(): void foreach ($allContextSupportLocales as $locale) { - Locale::setLocale($locale); + // Locale::setLocale($locale); foreach ($nonRemovablerecommendations as $recommendationValue => $translatableKey) { - $recommendations[$recommendationValue]['title'][$locale] = __($translatableKey); + $recommendations[$recommendationValue]['title'][$locale] = Locale::get( + $translatableKey, + [], + $locale + ); } } - Locale::setLocale($currentLocale); + // Locale::setLocale($currentLocale); $contextSupportedLocales->each( fn (array $supportedLocales, int $contextId) => collect($recommendations)->each( @@ -142,7 +143,7 @@ protected function seedNonRemovableRecommendations(): void } catch (Throwable $exception) { DB::rollBack(); - Locale::setLocale($currentLocale); + // Locale::setLocale($currentLocale); ReviewerRecommendation::reguard(); throw $exception; diff --git a/classes/navigationMenu/NavigationMenuDAO.php b/classes/navigationMenu/NavigationMenuDAO.php index d1daaf2a3f5..da64ef2bd29 100644 --- a/classes/navigationMenu/NavigationMenuDAO.php +++ b/classes/navigationMenu/NavigationMenuDAO.php @@ -17,6 +17,7 @@ namespace PKP\navigationMenu; use APP\core\Application; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Cache; use PKP\db\DAORegistry; use PKP\db\DAOResultFactory; diff --git a/classes/services/PKPContextService.php b/classes/services/PKPContextService.php index fc8ab3fb4bf..2008a0dc576 100644 --- a/classes/services/PKPContextService.php +++ b/classes/services/PKPContextService.php @@ -17,6 +17,8 @@ namespace PKP\services; use APP\core\Application; +use Illuminate\Support\Arr; + use APP\core\Request; use APP\facades\Repo; use APP\file\PublicFileManager; @@ -49,6 +51,7 @@ use PKP\services\interfaces\EntityWriteInterface; use PKP\submission\GenreDAO; use PKP\validation\ValidatorFactory; +use PKP\submission\reviewer\recommendation\ReviewerRecommendation; abstract class PKPContextService implements EntityPropertyInterface, EntityReadInterface, EntityWriteInterface { @@ -522,6 +525,25 @@ public function add($context, $request) $context = $this->get($context->getId()); + $locales = array_merge( + Arr::wrap($context->getData('primaryLocale')), + $context->getData('supportedLocales') + ); + foreach(ReviewerRecommendation::seedableRecommendations() as $recommendationValue => $translatableKey) { + ReviewerRecommendation::create([ + 'contextId' => $context->getId(), + 'value' => $recommendationValue, + 'status' => 1, + 'title' => collect($locales) + ->mapWithKeys( + fn (string $locale): array => [ + $locale => Locale::get($translatableKey, [], $locale) + ] + ) + ->toArray(), + ]); + } + // Move uploaded files into place and update the settings $supportedLocales = $context->getSupportedFormLocales(); $fileUploadProps = ['favicon', 'homepageImage', 'pageHeaderLogoImage']; @@ -629,7 +651,8 @@ public function delete($context) $genreDao->deleteByContextId($context->getId()); // TODO is it OK to delete without listening Model's delete-associated events (not loading each Model)? - Announcement::withContextIds([$context->getId])->delete(); + Announcement::withContextIds([$context->getId()])->delete(); + ReviewerRecommendation::query()->withContextId($context->getId())->delete(); Repo::highlight() ->getCollector() diff --git a/classes/submission/reviewer/recommendation/ReviewerRecommendation.php b/classes/submission/reviewer/recommendation/ReviewerRecommendation.php index 49e266dd67f..b443939f956 100644 --- a/classes/submission/reviewer/recommendation/ReviewerRecommendation.php +++ b/classes/submission/reviewer/recommendation/ReviewerRecommendation.php @@ -27,7 +27,7 @@ class ReviewerRecommendation extends Model /** * @copydoc \Illuminate\Database\Eloquent\Concerns\GuardsAttributes::$guarded */ - // TODO : add `recommendation_id` and `removable` as guarded column once pkp/pkp-lib#10292 and pkp/pkp-lib#10562 merged + // TODO : add `recommendation_id` as guarded column once pkp/pkp-lib#10292 and pkp/pkp-lib#10562 merged protected $guarded = []; /** @@ -39,7 +39,6 @@ protected function casts(): array 'value' => 'integer', 'context_id' => 'integer', 'status' => 'integer', // We cast the boolean to corresponding int e.g. true/false to 1/0 - 'removable' => 'boolean', ]; } @@ -48,9 +47,9 @@ protected function casts(): array */ protected static function booted(): void { - static::creating(function (Model $recommendation) { - $recommendation->value = $recommendation->value; - }); + static::creating( + fn (self $recommendation) => $recommendation->value = $recommendation->value + ); } /** @@ -61,6 +60,21 @@ public function getSettingsTable(): string return 'reviewer_recommendation_settings'; } + /** + * Get default recommendation seed data + */ + public static function seedableRecommendations(): array + { + return [ + 1 => 'reviewer.article.decision.accept', // SUBMISSION_REVIEWER_RECOMMENDATION_ACCEPT + 2 => 'reviewer.article.decision.pendingRevisions', // SUBMISSION_REVIEWER_RECOMMENDATION_PENDING_REVISIONS + 3 => 'reviewer.article.decision.resubmitHere', // SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_HERE + 4 => 'reviewer.article.decision.resubmitElsewhere', // SUBMISSION_REVIEWER_RECOMMENDATION_RESUBMIT_ELSEWHERE + 5 => 'reviewer.article.decision.decline', // SUBMISSION_REVIEWER_RECOMMENDATION_DECLINE + 6 => 'reviewer.article.decision.seeComments', // SUBMISSION_REVIEWER_RECOMMENDATION_SEE_COMMENTS + ]; + } + /** * @copydoc \PKP\core\traits\ModelWithSettings::getSchemaName */ @@ -101,7 +115,7 @@ protected function value(): Attribute $existingRecommendation = static::query() ->withContextId($this->contextId) ->where('value', $value) - ->first(); + ->exists(); if ($existingRecommendation) { throw new Exception( @@ -129,25 +143,11 @@ protected function value(): Attribute protected function removable(): Attribute { return Attribute::make( - get: function () { - if (!$this->getRawOriginal('removable')) { - return false; - } - - $reviewAssignmentCount = Repo::reviewAssignment() - ->getCollector() - ->filterByRecommenddations([$this->value]) - ->getCount(); - - return $reviewAssignmentCount === 0; - }, - // TODO : MUST FIX ME !!! This cause issue at data seeding in migration process - set: function (bool $value) { - if (!is_null($this->getRawOriginal('removable'))) { - return $this->getRawOriginal('removable'); - } - return $value; - } + get: fn () => Repo::reviewAssignment() + ->getCollector() + ->filterByRecommenddations([$this->value]) + ->getQueryBuilder() + ->exists() )->shouldCache(); }