Skip to content

Commit

Permalink
pkp/pkp-lib#8093 UserGroupDAO, UserGroupAssignmentDAO functions replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
defstat authored and asmecher committed Aug 26, 2022
1 parent 318f0ab commit 615ae5a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
8 changes: 5 additions & 3 deletions classes/install/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,14 @@ public function migrateUserAndAuthorNames()
public function changeUserRolesAndStageAssignmentsForStagePermitSubmissionEdit()
{
$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /** @var StageAssignmentDAO $stageAssignmentDao */
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var UserGroupDAO $userGroupDao */

$roles = UserGroupDAO::getNotChangeMetadataEditPermissionRoles();
$roles = Repo::userGroup()::NOT_CHANGE_METADATA_EDIT_PERMISSION_ROLES;
$roleString = '(' . implode(',', $roles) . ')';

$userGroupDao->update('UPDATE user_groups SET permit_metadata_edit = 1 WHERE role_id IN ' . $roleString);
DB::table('user_groups')
->whereIn('role_id', $roles)
->update(['permit_metadata_edit' => 1]);

switch (Config::getVar('database', 'driver')) {
case 'mysql':
case 'mysqli':
Expand Down
14 changes: 8 additions & 6 deletions classes/submission/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ public function getCoverImageAltText()
public function getAuthorOrEditorString($preferred = true)
{
if ($this->getWorkType() != self::WORK_TYPE_EDITED_VOLUME) {
$userGroupIds = array_map(function ($author) {
return $author->getData('userGroupId');
}, Repo::author()->getSubmissionAuthors($this, true)->toArray());
$userGroupIds = Repo::author()->getSubmissionAuthors($this, true)
->pluck('userGroupId')
->unique()
->toArray();

$userGroups = Repo::userGroup()->getCollector()
->filterByUserIds($userGroupIds)
->getMany();

$userGroups = array_map(function ($userGroupId) {
return DAORegistry::getDAO('UserGroupDAO')->getbyId($userGroupId);
}, array_unique($userGroupIds));
return $this->getCurrentPublication()->getAuthorString($userGroups);
}

Expand Down
6 changes: 5 additions & 1 deletion pages/catalog/CatalogBookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,17 @@ public function book($args, $request)
return empty($a) || strtotime((string) $b->getData('datePublished')) < strtotime((string) $a->getData('datePublished')) ? $b : $a;
}, 0);

$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$submission->getData('contextId')])
->getMany();

$templateMgr->assign([
'isChapterRequest' => $this->isChapterRequest,
'publishedSubmission' => $submission,
'publication' => $this->publication,
'firstPublication' => $firstPublication,
'currentPublication' => $submission->getCurrentPublication(),
'authorString' => $this->publication->getAuthorString(DAORegistry::getDAO('UserGroupDAO')->getByContextId($submission->getData('contextId'))->toArray()),
'authorString' => $this->publication->getAuthorString($userGroups),
]);

// Provide the publication formats to the template
Expand Down
5 changes: 3 additions & 2 deletions pages/manageCatalog/ManageCatalogHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ public function index($args, $request)
$total = $collector->getCount();
$submissions = $collector->limit($catalogList->count)->getMany();

$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var UserGroupDAO $userGroupDao */
$userGroups = $userGroupDao->getByContextId($context->getId())->toArray();
$userGroups = Repo::userGroup()->getCollector()
->filterByContextIds([$context->getId()])
->getMany();

/** @var GenreDAO $genreDao */
$genreDao = DAORegistry::getDAO('GenreDAO');
Expand Down
8 changes: 6 additions & 2 deletions plugins/importexport/csv/CSVImportExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public function executeCLI($scriptName, &$args)
}

$pressDao = Application::getContextDAO();
$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var UserGroupDAO $userGroupDao */
$seriesDao = DAORegistry::getDAO('SeriesDAO'); /** @var SeriesDAO $seriesDao */
$publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); /** @var PublicationFormatDAO $publicationFormatDao */
$submissionFileDao = Repo::submissionFile()->dao;
Expand All @@ -134,7 +133,12 @@ public function executeCLI($scriptName, &$args)
if (!is_array($supportedLocales) || count($supportedLocales) < 1) {
$supportedLocales = [$press->getPrimaryLocale()];
}
$authorGroup = $userGroupDao->getDefaultByRoleId($press->getId(), Role::ROLE_ID_AUTHOR);
$authorGroup = Repo::userGroup()->getCollector()
->filterByContextIds([$press->getId()])
->filterByRoleIds([Role::ROLE_ID_AUTHOR])
->filterByIsDefault(true)
->getMany()
->first();

// we need a Genre for the files. Assume a key of MANUSCRIPT as a default.
$genre = $genreDao->getByKey('MANUSCRIPT', $press->getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PKP\db\DAORegistry;
use PKP\facades\Locale;
use APP\core\Application;
use PKP\facades\Repo;

class MonographONIX30XmlFilter extends \PKP\plugins\importexport\native\filter\NativeExportFilter
{
Expand Down Expand Up @@ -322,8 +323,7 @@ public function createProductNode($doc, $submission, $publicationFormat)
$contributorNode = $doc->createElementNS($deployment->getNamespace(), 'Contributor');
$contributorNode->appendChild($this->_buildTextNode($doc, 'SequenceNumber', $sequence));

$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var UserGroupDAO $userGroupDao */
$userGroup = $userGroupDao->getById($author->getUserGroupId(), $submission->getContextId());
$userGroup = Repo::userGroup()->get($author->getUserGroupId());

$userGroupOnixMap = ['AU' => 'A01', 'VE' => 'B01', 'CA' => 'A01', 'Trans' => 'B06', 'PE' => 'B21']; // From List17, ContributorRole types.

Expand Down

0 comments on commit 615ae5a

Please sign in to comment.