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#10133 Port Genre and GenreDAO to Use Eloquent Model #4363

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
11 changes: 4 additions & 7 deletions api/v1/_dois/BackendDoiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\LazyCollection;
use PKP\db\DAORegistry;
use PKP\submission\genre\Genre;

class BackendDoiController extends \PKP\API\v1\_dois\PKPBackendDoiController
{
Expand Down Expand Up @@ -82,9 +82,8 @@ public function editGalley(Request $illuminateRequest): JsonResponse

Repo::galley()->edit($galley, ['doiId' => $doi->getId()]);

/** @var \PKP\submission\GenreDAO $genreDao */
$genreDao = DAORegistry::getDAO('GenreDAO');
$genres = $genreDao->getByContextId($context->getId())->toArray();
$genres = Genre::where('context_id', $context->getId())->get()->toArray();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're discussing approaches that don't require us to scatter database column names through the codebase; I'll pass you a link to a Mattermost thread about this!


// Re-fetch submission and publication to reflect changes in galley
$submission = Repo::submission()->get((int) $submissionId);
$publication = Repo::publication()->get((int) $publicationId);
Expand Down Expand Up @@ -152,8 +151,6 @@ protected function getUserGroups(int $contextId): LazyCollection

protected function getGenres(int $contextId): array
{
/** @var \PKP\submission\GenreDAO $genreDao */
$genreDao = DAORegistry::getDAO('GenreDAO');
return $genreDao->getByContextId($contextId)->toArray();
return Genre::where('context_id', $contextId)->get()->toArray();
}
}
6 changes: 2 additions & 4 deletions api/v1/issues/IssueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
use Illuminate\Support\LazyCollection;
use PKP\core\PKPBaseController;
use PKP\core\PKPRequest;
use PKP\db\DAORegistry;
use PKP\plugins\Hook;
use PKP\security\authorization\ContextAccessPolicy;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\authorization\UserRolesRequiredPolicy;
use PKP\security\Role;
use PKP\submission\GenreDAO;
use PKP\submission\genre\Genre;

class IssueController extends PKPBaseController
{
Expand Down Expand Up @@ -275,7 +274,6 @@ protected function getUserGroups(int $contextId): LazyCollection

protected function getGenres(int $contextId): array
{
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
return $genreDao->getByContextId($contextId)->toArray();
return Genre::where('context_id', $contextId)->get()->toArray();
}
}
8 changes: 3 additions & 5 deletions classes/services/ContextService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use PKP\db\DAORegistry;
use PKP\file\TemporaryFileManager;
use PKP\plugins\Hook;
use PKP\submission\GenreDAO;
use PKP\submission\genre\Genre;

class ContextService extends \PKP\services\PKPContextService
{
Expand Down Expand Up @@ -151,9 +151,7 @@ public function beforeDeleteContext($hookName, $args)
// Create tombstones for all published submissions
$articleTombstoneManager = new ArticleTombstoneManager();
$articleTombstoneManager->insertTombstonesByContext($context);
/** @var GenreDAO */
$genreDao = DAORegistry::getDAO('GenreDAO');
$genreDao->deleteByContextId($context->getId());
Genre::where('context_id', $context->getId())->delete();
}

/**
Expand Down Expand Up @@ -201,7 +199,7 @@ public function afterDeleteContext($hookName, $args)
*/
public function validateContext($hookName, $args)
{
$errors = & $args[0];
$errors = &$args[0];
$props = $args[2];
$allowedLocales = $args[3];

Expand Down
25 changes: 9 additions & 16 deletions pages/article/ArticleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
use PKP\plugins\PluginRegistry;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\Validation;
use PKP\submission\Genre;
use PKP\submission\GenreDAO;
use PKP\submission\genre\Genre;
use PKP\submission\PKPSubmission;
use PKP\submissionFile\SubmissionFile;
use stdClass;
Expand Down Expand Up @@ -167,8 +166,8 @@ public function initialize($request, $args = [])
$this->galley = $galley;
break;

// In some cases, a URL to a galley may use the ID when it should use
// the urlPath. Redirect to the galley's correct URL.
// In some cases, a URL to a galley may use the ID when it should use
// the urlPath. Redirect to the galley's correct URL.
} elseif (ctype_digit($galleyId) && $galley->getId() == $galleyId) {
$request->redirect(null, $request->getRequestedPage(), $request->getRequestedOp(), [$submission->getBestId(), $galley->getBestGalleyId()]);
}
Expand Down Expand Up @@ -261,15 +260,11 @@ public function view($args, $request)
$primaryGalleys = [];
$supplementaryGalleys = [];
if ($galleys) {
$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$primaryGenres = $genreDao->getPrimaryByContextId($context->getId())->toArray();
$primaryGenreIds = array_map(function ($genre) {
return $genre->getId();
}, $primaryGenres);
$supplementaryGenres = $genreDao->getBySupplementaryAndContextId(true, $context->getId())->toArray();
$supplementaryGenreIds = array_map(function ($genre) {
return $genre->getId();
}, $supplementaryGenres);
$primaryGenres = Repo::genre()->getPrimaryByContextId($context->getId());
$primaryGenreIds = $primaryGenres->pluck('id')->toArray();

$supplementaryGenres = Repo::genre()->getBySupplementaryAndContextId(true, $context->getId());
$supplementaryGenreIds = $supplementaryGenres->pluck('id')->toArray();

foreach ($galleys as $galley) {
$remoteUrl = $galley->getData('urlRemote');
Expand Down Expand Up @@ -502,9 +497,7 @@ public function download($args, $request)
// if the file is a galley file (i.e. not a dependent file e.g. CSS or images), fire an usage event.
if ($this->galley->getData('submissionFileId') == $this->submissionFileId) {
$assocType = Application::ASSOC_TYPE_SUBMISSION_FILE;
/** @var GenreDAO */
$genreDao = DAORegistry::getDAO('GenreDAO');
$genre = $genreDao->getById($submissionFile->getData('genreId'));
$genre = Repo::genre()->find($submissionFile->getData('genreId'));
// TO-DO: is this correct ?
if ($genre->getCategory() != Genre::GENRE_CATEGORY_DOCUMENT || $genre->getSupplementary() || $genre->getDependent()) {
$assocType = Application::ASSOC_TYPE_SUBMISSION_FILE_COUNTER_OTHER;
Expand Down
8 changes: 2 additions & 6 deletions pages/issue/IssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use PKP\plugins\PluginRegistry;
use PKP\security\authorization\ContextRequiredPolicy;
use PKP\security\Validation;
use PKP\submission\GenreDAO;
use PKP\submission\PKPSubmission;

class IssueHandler extends Handler
Expand Down Expand Up @@ -351,11 +350,8 @@ public static function _setupIssueTemplate(Request $request, Issue $issue, Journ

$issueGalleyDao = DAORegistry::getDAO('IssueGalleyDAO'); /** @var IssueGalleyDAO $issueGalleyDao */

$genreDao = DAORegistry::getDAO('GenreDAO'); /** @var GenreDAO $genreDao */
$primaryGenres = $genreDao->getPrimaryByContextId($journal->getId())->toArray();
$primaryGenreIds = array_map(function ($genre) {
return $genre->getId();
}, $primaryGenres);
$primaryGenreIds = Repo::genre()->getPrimaryByContextId($journal->getId())->pluck('id')->toArray();


// Show scheduled submissions if this is a preview
$allowedStatuses = [PKPSubmission::STATUS_PUBLISHED];
Expand Down
8 changes: 3 additions & 5 deletions plugins/generic/datacite/filter/DataciteXmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
use PKP\facades\Locale;
use PKP\galley\Galley;
use PKP\i18n\LocaleConversion;
use PKP\submission\Genre;
use PKP\submission\GenreDAO;
use PKP\submission\genre\Genre;
use PKP\submissionFile\SubmissionFile;

// Title types
Expand Down Expand Up @@ -131,9 +130,8 @@ public function &process(&$pubObject)
if ($cache->isCached('genres', $galleyFile->getData('genreId'))) {
$genre = $cache->get('genres', $galleyFile->getData('genreId'));
} else {
/** @var GenreDAO */
$genreDao = DAORegistry::getDAO('GenreDAO');
$genre = $genreDao->getById($galleyFile->getData('genreId'));
$genreId = $galleyFile->getData('genreId');
$genre = Genre::find($genreId);
if ($genre) {
$cache->add($genre, null);
}
Expand Down
Loading