Skip to content

Commit

Permalink
Merge pull request #6804 from bozana/6071-3_3_0
Browse files Browse the repository at this point in the history
#6071 Merge pull request #6159 from defstat/i6071
  • Loading branch information
bozana authored Mar 1, 2021
2 parents aa7ee24 + 924a752 commit 59878d7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
8 changes: 8 additions & 0 deletions classes/citation/CitationDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ function importCitations($publicationId, $rawCitationList) {
assert(is_numeric($publicationId));
$publicationId = (int) $publicationId;

$existingCitations = $this->getByPublicationId($publicationId)->toAssociativeArray();

// Remove existing citations.
$this->deleteByPublicationId($publicationId);

Expand All @@ -82,16 +84,22 @@ function importCitations($publicationId, $rawCitationList) {
$citationStrings = $citationTokenizer->execute($rawCitationList);

// Instantiate and persist citations
$importedCitations = array();
if (is_array($citationStrings)) foreach($citationStrings as $seq => $citationString) {
if (!empty(trim($citationString))) {
$citation = new Citation($citationString);
// Set the publication
$citation->setData('publicationId', $publicationId);
// Set the counter
$citation->setSequence($seq+1);

$this->insertObject($citation);

$importedCitations[] = $citation;
}
}

HookRegistry::call('CitationDAO::afterImportCitations', [$publicationId, $existingCitations, $importedCitations]);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions classes/publication/PKPPublicationDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,24 @@ public function deleteAllPubIds($contextId, $pubIdType) {
}
$this->flushCache();
}

/**
* Find publication ids by querying settings.
* @param $settingName string
* @param $settingValue mixed
* @param $contextId int
* @return array Publication.
*/
public function getIdsBySetting($settingName, $settingValue, $contextId) {
$q = Capsule::table('publications as p')
->join('publication_settings as ps', 'p.publication_id', '=', 'ps.publication_id')
->join('submissions as s', 'p.submission_id', '=', 's.submission_id')
->where('ps.setting_name', '=', $settingName)
->where('ps.setting_value', '=', $settingValue)
->where('s.context_id', '=', (int) $contextId);

return $q->select('p.publication_id')
->pluck('p.publication_id')
->toArray();
}
}
6 changes: 4 additions & 2 deletions classes/services/PKPPublicationService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,11 +527,13 @@ public function edit($publication, $params, $request) {
$newPublication = $this->get($newPublication->getId());

// Parse the citations
if (array_key_exists('citationsRaw', $params)) {
$citationDao = DAORegistry::getDAO('CitationDAO'); /* @var $citationDao CitationDAO */
if (array_key_exists('citationsRaw', $params) && $publication->getData('citationsRaw') != $newPublication->getData('citationsRaw')) {
$citationDao = DAORegistry::getDAO('CitationDAO'); /** @var $citationDao \CitationDAO */
$citationDao->importCitations($newPublication->getId(), $newPublication->getData('citationsRaw'));
}

$submission = Services::get('submission')->get($newPublication->getData('submissionId'));

// Log an event when publication data is updated
import('lib.pkp.classes.log.SubmissionLog');
import('classes.log.SubmissionEventLogEntry');
Expand Down
20 changes: 20 additions & 0 deletions classes/submission/PKPSubmissionDAO.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @brief Operations for retrieving and modifying Submission objects.
*/
use Illuminate\Database\Capsule\Manager as Capsule;

import('lib.pkp.classes.submission.PKPSubmission');
import('lib.pkp.classes.db.SchemaDAO');
Expand Down Expand Up @@ -312,4 +313,23 @@ function getSortDirection($sortOption) {
list($sortBy, $sortDir) = explode("-", $sortOption);
return $sortDir;
}

/**
* Find submission ids by querying settings.
* @param $settingName string
* @param $settingValue mixed
* @param $contextId int
* @return array Submission.
*/
public function getIdsBySetting($settingName, $settingValue, $contextId) {
$q = Capsule::table('submissions as s')
->join('submission_settings as ss', 's.submission_id', '=', 'ss.submission_id')
->where('ss.setting_name', '=', $settingName)
->where('ss.setting_value', '=', $settingValue)
->where('s.context_id', '=', (int) $contextId);

return $q->select('s.submission_id')
->pluck('s.submission_id')
->toArray();
}
}

0 comments on commit 59878d7

Please sign in to comment.