Skip to content

Commit

Permalink
Merge pull request #1423 from jonasraoni/feature/main/8333-add-remain…
Browse files Browse the repository at this point in the history
…ing-fks

Feature/main/8333 Add remaining FKs
  • Loading branch information
jonasraoni authored Jul 24, 2024
2 parents 0248171 + 5eed2bd commit c5995e9
Show file tree
Hide file tree
Showing 28 changed files with 138 additions and 152 deletions.
4 changes: 2 additions & 2 deletions classes/file/PublicFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class PublicFileManager extends PKPPublicFileManager
/**
* @copydoc PKPPublicFileManager::getContextFilesPath()
*/
public function getContextFilesPath($contextId)
public function getContextFilesPath(int $contextId)
{
return Config::getVar('files', 'public_files_dir') . '/presses/' . (int) $contextId;
return Config::getVar('files', 'public_files_dir') . '/presses/' . $contextId;
}
}

Expand Down
33 changes: 33 additions & 0 deletions classes/migration/upgrade/v3_5_0/I8333_AddMissingForeignKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I8333_AddMissingForeignKeys.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 I8333_AddMissingForeignKeys
*
* @brief Upgrade/downgrade operations for introducing foreign key definitions to existing database relationships.
*/

namespace APP\migration\upgrade\v3_5_0;

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

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

protected function getContextSettingsTable(): string
{
return 'press_settings';
}
}
2 changes: 1 addition & 1 deletion classes/monograph/ChapterDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function getByContextId(int $pressId): DAOResultFactory
INNER JOIN publications p ON (spc.publication_id = p.publication_id)
INNER JOIN submissions s ON (p.submission_id = s.submission_id)
WHERE s.context_id = ?',
[(int) $pressId]
[$pressId]
),
$this,
'_fromRow'
Expand Down
12 changes: 3 additions & 9 deletions classes/oai/omp/OAIDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,11 @@ public function __construct()
/**
* Cached function to get a press
*
* @param int $pressId
*
* @return Press
*/
public function getPress($pressId)
public function getPress(int $pressId)
{
if (!isset($this->_pressCache[$pressId])) {
$this->_pressCache[$pressId] = $this->_pressDao->getById($pressId);
}
return $this->_pressCache[$pressId];
return $this->_pressCache[$pressId] ??= $this->_pressDao->getById($pressId);
}

/**
Expand All @@ -94,15 +89,14 @@ public function getSeries($seriesId)
/**
* Return hierarchy of OAI sets (presses plus press series).
*
* @param int|null $pressId
* @param int $offset
* @param int $total
*
* @return array OAISet
*
* @hook OAIDAO::getSets [[&$this, $pressId, $offset, $limit, $total, &$sets]]
*/
public function getSets($pressId, $offset, $limit, &$total)
public function getSets(?int $pressId, $offset, $limit, &$total)
{
if (isset($pressId)) {
$presses = [$this->getPress($pressId)];
Expand Down
6 changes: 2 additions & 4 deletions classes/oai/omp/PressOAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class PressOAI extends OAI
/** @var Press $press associated press object */
public $press;

/** @var int $pressId null if no press */
public $pressId;
public ?int $pressId;

/** @var OAIDAO $dao DAO for retrieving OAI records/tokens from database */
public $dao;
Expand Down Expand Up @@ -99,11 +98,10 @@ public function identifierToPublicationFormatId($identifier)
* Get press ID and series ID corresponding to a set specifier.
*
* @param string $setSpec
* @param int $pressId
*
* @return array
*/
public function setSpecToSeriesId($setSpec, $pressId = null)
public function setSpecToSeriesId($setSpec, ?int $pressId = null)
{
$tmpArray = preg_split('/:/', $setSpec);
if (count($tmpArray) == 1) {
Expand Down
2 changes: 1 addition & 1 deletion classes/observers/events/UsageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class UsageEvent extends \PKP\observers\events\UsageEvent
public ?Chapter $chapter;
public ?Section $series;

public function __construct(int $assocType, Context $context, Submission $submission = null, Representation $publicationFormat = null, SubmissionFile $submissionFile = null, Chapter $chapter = null, Section $series = null)
public function __construct(int $assocType, Context $context, ?Submission $submission = null, ?Representation $publicationFormat = null, ?SubmissionFile $submissionFile = null, ?Chapter $chapter = null, ?Section $series = null)
{
$this->chapter = $chapter;
$this->series = $series;
Expand Down
6 changes: 2 additions & 4 deletions classes/payment/omp/OMPCompletedPaymentDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ class OMPCompletedPaymentDAO extends DAO
* Retrieve a CompletedPayment by its ID.
*
* @param int $completedPaymentId
* @param int $contextId optional
*
* @return CompletedPayment|null
*/
public function getById($completedPaymentId, $contextId = null)
public function getById($completedPaymentId, ?int $contextId = null)
{
$params = [(int) $completedPaymentId];
if ($contextId) {
Expand Down Expand Up @@ -141,12 +140,11 @@ public function hasPaidPurchaseFile($userId, $submissionFileId)
/**
* Retrieve an array of payments for a particular context ID.
*
* @param int $contextId
* @param DBResultRange|null $rangeInfo
*
* @return DAOResultFactory<CompletedPayment> containing matching payments
*/
public function getByContextId($contextId, $rangeInfo = null)
public function getByContextId(int $contextId, $rangeInfo = null)
{
return new DAOResultFactory(
$this->retrieveRange(
Expand Down
2 changes: 1 addition & 1 deletion classes/plugins/PubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function getDAOs()
/**
* @copydoc PKPPubIdPlugin::checkDuplicate()
*/
public function checkDuplicate($pubId, $pubObjectType, $excludeId, $contextId)
public function checkDuplicate($pubId, $pubObjectType, $excludeId, int $contextId)
{
/** @var ChapterDAO */
$chapterDao = DAORegistry::getDAO('ChapterDAO');
Expand Down
6 changes: 2 additions & 4 deletions classes/press/PressDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ public function newDataObject()
/**
* Delete the public IDs of all publishing objects in a press.
*
* @param int $pressId
* @param string $pubIdType One of the NLM pub-id-type values or
* 'other::something' if not part of the official NLM list
* (see <http://dtd.nlm.nih.gov/publishing/tag-library/n-4zh0.html>).
*/
public function deleteAllPubIds($pressId, $pubIdType)
public function deleteAllPubIds(int $pressId, $pubIdType)
{
$pubObjectDaos = ['ChapterDAO', 'PublicationFormatDAO'];
foreach ($pubObjectDaos as $daoName) {
Expand All @@ -87,7 +86,6 @@ public function deleteAllPubIds($pressId, $pubIdType)
* Check whether the given public ID exists for any publishing
* object in a press.
*
* @param int $pressId
* @param string $pubIdType One of the NLM pub-id-type values or
* 'other::something' if not part of the official NLM list
* (see <http://dtd.nlm.nih.gov/publishing/tag-library/n-4zh0.html>).
Expand All @@ -100,7 +98,7 @@ public function deleteAllPubIds($pressId, $pubIdType)
* @return bool
*/
public function anyPubIdExists(
$pressId,
int $pressId,
$pubIdType,
$pubId,
$assocType = MetadataTypeDescription::ASSOC_TYPE_ANY,
Expand Down
7 changes: 2 additions & 5 deletions classes/publication/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ public function getEditorString()
/**
* Get the URL to a localized cover image
*
* @param int $contextId
* @param string $preferredLocale Return the cover image in a specified locale.
*
* @return string
*/
public function getLocalizedCoverImageUrl($contextId, $preferredLocale = null)
public function getLocalizedCoverImageUrl(int $contextId, $preferredLocale = null)
{
$coverImage = $this->getLocalizedData('coverImage', $preferredLocale);

Expand All @@ -73,11 +72,9 @@ public function getLocalizedCoverImageUrl($contextId, $preferredLocale = null)
/**
* Get the URL to the thumbnail of a localized cover image
*
* @param int $contextId
*
* @return string
*/
public function getLocalizedCoverImageThumbnailUrl($contextId)
public function getLocalizedCoverImageThumbnailUrl(int $contextId)
{
$url = $this->getLocalizedCoverImageUrl($contextId);
$pathParts = pathinfo($url);
Expand Down
Loading

0 comments on commit c5995e9

Please sign in to comment.