Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkp/pkp-lib#9465 Standardize submissionLocale attribute in certain entities #10746

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 3 additions & 21 deletions classes/author/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

namespace PKP\author;

use PKP\facades\Locale;
use PKP\identity\Identity;
use PKP\userGroup\UserGroup;
Expand All @@ -25,10 +26,11 @@ class Author extends Identity
{
/**
* Get the default/fall back locale the values should exist for
* (see LocalizedData trait)
*/
public function getDefaultLocale(): ?string
{
return $this->getSubmissionLocale();
return $this->getData('submissionLocale');
}

/**
Expand Down Expand Up @@ -79,26 +81,6 @@ public function setSubmissionId($submissionId)
$this->setData('submissionId', $submissionId);
}

/**
* Get submission locale.
*
* @return string
*/
public function getSubmissionLocale()
{
return $this->getData('locale');
}

/**
* Set submission locale.
*
* @param string $locale
*/
public function setSubmissionLocale($locale)
{
return $this->setData('locale', $locale);
}

/**
* Set the user group id
*
Expand Down
2 changes: 1 addition & 1 deletion classes/author/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function fromRow(object $row): Author
$author = parent::fromRow($row);

// Set the primary locale from the submission
$author->setData('locale', $row->submission_locale);
$author->setData('submissionLocale', $row->submission_locale);

return $author;
}
Expand Down
3 changes: 2 additions & 1 deletion classes/submissionFile/Collector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file classes/submissionFile/Collector.php
*
Expand Down Expand Up @@ -217,7 +218,7 @@ public function getQueryBuilder(): Builder
$qb = DB::table($this->dao->table . ' as sf')
->join('submissions as s', 's.submission_id', '=', 'sf.submission_id')
->join('files as f', 'f.file_id', '=', 'sf.file_id')
->select(['sf.*', 'f.*', 's.locale as locale']);
->select(['sf.*', 'f.*', 's.locale as submission_locale']);

if ($this->submissionIds !== null) {
$qb->whereIn('sf.submission_id', $this->submissionIds);
Expand Down
2 changes: 1 addition & 1 deletion classes/submissionFile/DAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function getMany(Collector $query): LazyCollection
public function fromRow(object $primaryRow): SubmissionFile
{
$submissionFile = parent::fromRow($primaryRow);
$submissionFile->setData('locale', $primaryRow->locale);
$submissionFile->setData('submissionLocale', $primaryRow->submission_locale);
$submissionFile->setData('path', $primaryRow->path);
$submissionFile->setData('mimetype', $primaryRow->mimetype);

Expand Down
36 changes: 3 additions & 33 deletions classes/submissionFile/SubmissionFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use APP\facades\Repo;
use PKP\facades\Locale;
use PKP\i18n\LocaleMetadata;
use PKP\services\PKPSchemaService;

/**
Expand Down Expand Up @@ -55,40 +54,11 @@ class SubmissionFile extends \PKP\core\DataObject

/**
* Get the default/fall back locale the values should exist for
* (see LocalizedData trait)
*/
public function getDefaultLocale(): ?string
{
return $this->getData('locale');
}

/**
* Get the locale of the submission.
* This is not properly a property of the submission file
* (e.g. it won't be persisted to the DB with the update function)
* It helps solve submission locale requirement for file's multilingual metadata
*
* @deprecated 3.3.0.0
*
* @return string
*/
public function getSubmissionLocale()
{
return $this->getData('locale');
}

/**
* Set the locale of the submission.
* This is not properly a property of the submission file
* (e.g. it won't be persisted to the DB with the update function)
* It helps solve submission locale requirement for file's multilingual metadata
*
* @deprecated 3.3.0.0
*
* @param string $submissionLocale
*/
public function setSubmissionLocale($submissionLocale)
{
$this->setData('locale', $submissionLocale);
return $this->getData('submissionLocale');
}

/**
Expand Down Expand Up @@ -401,7 +371,7 @@ public function getLanguages(): array
{
$props = app()->get('schema')->getMultilingualProps(PKPSchemaService::SCHEMA_SUBMISSION_FILE);
$locales = array_map(fn (string $prop): array => array_keys($this->getData($prop) ?? []), $props);
return collect([$this->getData('locale')])
return collect([$this->getData('submissionLocale')])
->concat($locales)
->flatten()
->filter()
Expand Down