Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasraoni committed Jul 24, 2024
1 parent 9ccbe41 commit 16703bc
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 134 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
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
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
117 changes: 54 additions & 63 deletions classes/publicationFormat/PublicationFormatDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ class PublicationFormatDAO extends DAO implements RepresentationDAOInterface
{
/**
* @copydoc RepresentationDAO::getById()
*
* @param null|mixed $publicationId
* @param null|mixed $contextId
*/
public function getById(int $representationId, ?int $publicationId = null, ?int $contextId = null): PublicationFormat
{
Expand All @@ -45,11 +42,11 @@ public function getById(int $representationId, ?int $publicationId = null, ?int

$result = $this->retrieve(
'SELECT pf.*
FROM publication_formats pf
' . ($contextId ? '
JOIN publications p ON (p.publication_id = pf.publicationId)
JOIN submissions s ON (s.submission_id=p.submission_id)' : '') . '
WHERE pf.publication_format_id=?' .
FROM publication_formats pf
' . ($contextId ? '
JOIN publications p ON (p.publication_id = pf.publicationId)
JOIN submissions s ON (s.submission_id=p.submission_id)' : '') . '
WHERE pf.publication_format_id=?' .
($publicationId ? ' AND pf.publication_id = ?' : '') .
($contextId ? ' AND s.context_id = ?' : ''),
$params
Expand All @@ -63,27 +60,26 @@ public function getById(int $representationId, ?int $publicationId = null, ?int
*
* @param string $settingName
* @param int $publicationId optional
* @param int $pressId optional
*
* @return array The publication formats identified by setting.
*/
public function getBySetting($settingName, $settingValue, $publicationId = null, $pressId = null)
public function getBySetting($settingName, $settingValue, $publicationId = null, ?int $pressId = null)
{
$params = [$settingName];

$sql = 'SELECT pf.*
FROM publication_formats pf ';
FROM publication_formats pf ';
if ($pressId) {
$sql .= 'INNER JOIN publications p ON p.publication_id = pf.publication_id
INNER JOIN submissions s ON s.submission_id = p.submission_id ';
INNER JOIN submissions s ON s.submission_id = p.submission_id ';
}
if (is_null($settingValue)) {
$sql .= 'LEFT JOIN publication_format_settings pfs ON pf.publication_format_id = pfs.publication_format_id AND pfs.setting_name = ?
WHERE (pfs.setting_value IS NULL OR pfs.setting_value = \'\')';
WHERE (pfs.setting_value IS NULL OR pfs.setting_value = \'\')';
} else {
$params[] = (string) $settingValue;
$sql .= 'INNER JOIN publication_format_settings pfs ON pf.publication_format_id = pfs.publication_format_id
WHERE pfs.setting_name = ? AND pfs.setting_value = ?';
WHERE pfs.setting_name = ? AND pfs.setting_value = ?';
}

if ($publicationId) {
Expand Down Expand Up @@ -115,11 +111,10 @@ public function getBySetting($settingName, $settingValue, $publicationId = null,
* (see <http://dtd.nlm.nih.gov/publishing/tag-library/n-4zh0.html>).
* @param string $pubId
* @param int $publicationId optional
* @param int $pressId optional
*
* @return PublicationFormat|null
*/
public function getByPubId($pubIdType, $pubId, $publicationId = null, $pressId = null)
public function getByPubId($pubIdType, $pubId, $publicationId = null, ?int $pressId = null)
{
if (empty($pubId)) {
return null;
Expand Down Expand Up @@ -160,9 +155,9 @@ public function getByBestId($representationId, $publicationId)
{
$result = $this->retrieve(
'SELECT pf.*
FROM publication_formats pf
WHERE pf.url_path = ?
AND pf.publication_id = ?',
FROM publication_formats pf
WHERE pf.url_path = ?
AND pf.publication_id = ?',
[
$representationId,
$publicationId,
Expand All @@ -179,11 +174,9 @@ public function getByBestId($representationId, $publicationId)
/**
* @copydoc RepresentationDAO::getByPublicationId()
*
* @param null|mixed $contextId
*
* @return DAOResultFactory<PublicationFormat>
*/
public function getByPublicationId($publicationId, $contextId = null): array
public function getByPublicationId($publicationId, ?int $contextId = null): array
{
$params = [(int) $publicationId];
if ($contextId) {
Expand All @@ -193,10 +186,10 @@ public function getByPublicationId($publicationId, $contextId = null): array
$result = new DAOResultFactory(
$this->retrieve(
'SELECT pf.*
FROM publication_formats pf ' .
FROM publication_formats pf ' .
($contextId ?
'INNER JOIN publications p ON (pf.publication_id=p.publication_id)
INNER JOIN submissions s ON (s.submission_id = p.submission_id) '
INNER JOIN submissions s ON (s.submission_id = p.submission_id) '
: '') .
'WHERE pf.publication_id=? '
. ($contextId ? ' AND s.context_id = ? ' : '')
Expand All @@ -213,21 +206,19 @@ public function getByPublicationId($publicationId, $contextId = null): array
/**
* Retrieves a list of publication formats for a press
*
* @param int $pressId
*
* @return DAOResultFactory<PublicationFormat>
*/
public function getByContextId($pressId)
public function getByContextId(int $pressId)
{
return new DAOResultFactory(
$this->retrieve(
'SELECT pf.*
FROM publication_formats pf
JOIN publications p ON (p.publication_id = pf.publication_id)
JOIN submissions s ON (s.submission_id = p.submission_id)
WHERE s.context_id = ?
ORDER BY pf.seq',
[(int) $pressId]
FROM publication_formats pf
JOIN publications p ON (p.publication_id = pf.publication_id)
JOIN submissions s ON (s.submission_id = p.submission_id)
WHERE s.context_id = ?
ORDER BY pf.seq',
[$pressId]
),
$this,
'_fromRow'
Expand Down Expand Up @@ -364,9 +355,9 @@ public function insertObject($publicationFormat)
{
$this->update(
'INSERT INTO publication_formats
(is_approved, entry_key, physical_format, publication_id, seq, file_size, front_matter, back_matter, height, height_unit_code, width, width_unit_code, thickness, thickness_unit_code, weight, weight_unit_code, product_composition_code, product_form_detail_code, country_manufacture_code, imprint, product_availability_code, technical_protection_code, returnable_indicator_code, remote_url, url_path, is_available, doi_id)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
(is_approved, entry_key, physical_format, publication_id, seq, file_size, front_matter, back_matter, height, height_unit_code, width, width_unit_code, thickness, thickness_unit_code, weight, weight_unit_code, product_composition_code, product_form_detail_code, country_manufacture_code, imprint, product_availability_code, technical_protection_code, returnable_indicator_code, remote_url, url_path, is_available, doi_id)
VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
[
(int) $publicationFormat->getIsApproved(),
$publicationFormat->getEntryKey(),
Expand Down Expand Up @@ -413,33 +404,33 @@ public function updateObject(Representation $publicationFormat): void
{
$this->update(
'UPDATE publication_formats
SET is_approved = ?,
entry_key = ?,
physical_format = ?,
seq = ?,
file_size = ?,
front_matter = ?,
back_matter = ?,
height = ?,
height_unit_code = ?,
width = ?,
width_unit_code = ?,
thickness = ?,
thickness_unit_code = ?,
weight = ?,
weight_unit_code = ?,
product_composition_code = ?,
product_form_detail_code = ?,
country_manufacture_code = ?,
imprint = ?,
product_availability_code = ?,
technical_protection_code = ?,
returnable_indicator_code = ?,
remote_url = ?,
url_path = ?,
is_available = ?,
doi_id = ?
WHERE publication_format_id = ?',
SET is_approved = ?,
entry_key = ?,
physical_format = ?,
seq = ?,
file_size = ?,
front_matter = ?,
back_matter = ?,
height = ?,
height_unit_code = ?,
width = ?,
width_unit_code = ?,
thickness = ?,
thickness_unit_code = ?,
weight = ?,
weight_unit_code = ?,
product_composition_code = ?,
product_form_detail_code = ?,
country_manufacture_code = ?,
imprint = ?,
product_availability_code = ?,
technical_protection_code = ?,
returnable_indicator_code = ?,
remote_url = ?,
url_path = ?,
is_available = ?,
doi_id = ?
WHERE publication_format_id = ?',
[
(int) $publicationFormat->getIsApproved(),
$publicationFormat->getEntryKey(),
Expand Down
Loading

0 comments on commit 16703bc

Please sign in to comment.