Skip to content

Commit da68cfa

Browse files
committed
pkp/pkp-lib#5932 Rename section path to urlPath
1 parent 2eb475b commit da68cfa

File tree

38 files changed

+637
-448
lines changed

38 files changed

+637
-448
lines changed

classes/components/forms/publication/IssueEntryForm.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct($action, $locales, $publication, $publicationContext
7575
}
7676
$categoryOptions[] = [
7777
'value' => (int) $category->getId(),
78-
'label' => $category->getLocalizedTitle(),
78+
'label' => $label,
7979
];
8080
}
8181
if (!empty($categoryOptions)) {

classes/mail/variables/SubmissionEmailVariable.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function getSubmissionPublishedUrl(Context $context): string
2626
Application::get()->getRequest(),
2727
Application::ROUTE_PAGE,
2828
$context->getPath(),
29-
'preprint',
29+
'preprints',
3030
'view',
3131
$this->submission->getBestId()
3232
);

classes/migration/install/OPSMigration.php

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function up(): void
3232
$table->foreign('server_id')->references('server_id')->on('servers')->onDelete('cascade');
3333
$table->index(['server_id'], 'sections_server_id');
3434

35+
$table->string('url_path', 255);
36+
3537
$table->bigInteger('review_form_id')->nullable();
3638
$table->foreign('review_form_id')->references('review_form_id')->on('review_forms')->onDelete('set null');
3739
$table->index(['review_form_id'], 'sections_review_form_id');
@@ -44,6 +46,7 @@ public function up(): void
4446
$table->tinyInteger('hide_title')->default(0);
4547
$table->tinyInteger('hide_author')->default(0);
4648
$table->tinyInteger('is_inactive')->default(0);
49+
$table->smallInteger('not_browsable')->default(0);
4750
$table->bigInteger('abstract_word_count')->nullable();
4851
});
4952

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/**
4+
* @file classes/migration/upgrade/v3_4_0/I5932_GenerateSectionUrlPaths.php
5+
*
6+
* Copyright (c) 2014-2021 Simon Fraser University
7+
* Copyright (c) 2000-2021 John Willinsky
8+
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
9+
*
10+
* @class I5932_GenerateSectionUrlPaths
11+
* @brief Create section urlPath column and generate URL paths for sections.
12+
*/
13+
14+
namespace APP\migration\upgrade\v3_4_0;
15+
16+
use APP\facades\Repo;
17+
use Illuminate\Database\Schema\Blueprint;
18+
use Illuminate\Support\Facades\DB;
19+
use Illuminate\Support\Facades\Schema;
20+
use PKP\migration\Migration;
21+
use Stringy\Stringy;
22+
23+
class I5932_GenerateSectionUrlPaths extends Migration
24+
{
25+
/**
26+
* Run the migration.
27+
*/
28+
public function up(): void
29+
{
30+
31+
// pkp/pkp-lib#5932 Generate URL paths for sections
32+
Schema::table('sections', function (Blueprint $table) {
33+
$table->string('url_path', 255)->after('review_form_id');
34+
$table->smallInteger('not_browsable')->default(0)->after('is_inactive');
35+
});
36+
37+
$contexts = DB::table('servers AS s')
38+
->select('s.server_id')
39+
->get();
40+
41+
foreach ($contexts as $context) {
42+
$sections = Repo::section()->getCollector()->filterByContextIds([$context->server_id])->getMany();
43+
foreach ($sections as $section) {
44+
$sectionTitle = $section->getLocalizedTitle();
45+
$sectionUrlpath = (string) Stringy::create($sectionTitle)->toAscii()->toLowerCase()->dasherize()->regexReplace('[^a-z0-9\-\_.]', '');
46+
$section->setUrlPath($sectionUrlpath);
47+
Repo::section()->edit($section, []);
48+
}
49+
}
50+
}
51+
52+
/**
53+
* Reverse the downgrades
54+
*/
55+
public function down(): void
56+
{
57+
Schema::table('sections', function (Blueprint $table) {
58+
$table->dropColumn('url_path');
59+
$table->dropColumn('not_browsable');
60+
});
61+
}
62+
}
63+
64+
if (!PKP_STRICT_MODE) {
65+
class_alias('\APP\migration\upgrade\v3_4_0\I5932_GenerateSectionUrlPaths', '\I5932_GenerateSectionUrlPaths');
66+
}

classes/publication/maps/Schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected function mapByProperties(array $props, Publication $publication, bool
4040
$this->request,
4141
PKPApplication::ROUTE_PAGE,
4242
$this->context->getData('urlPath'),
43-
'preprint',
43+
'preprints',
4444
'view',
4545
[
4646
$this->submission->getBestId(),

classes/section/DAO.php

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DAO extends \PKP\section\DAO
3737
public $primaryTableColumns = [
3838
'id' => 'section_id',
3939
'contextId' => 'server_id',
40+
'urlPath' => 'url_path',
4041
'reviewFormId' => 'review_form_id',
4142
'sequence' => 'seq',
4243
'editorRestricted' => 'editor_restricted',
@@ -46,6 +47,7 @@ class DAO extends \PKP\section\DAO
4647
'hideTitle' => 'hide_title',
4748
'hideAuthor' => 'hide_author',
4849
'isInactive' => 'is_inactive',
50+
'notBrowsable' => 'not_browsable',
4951
'wordCount' => 'abstract_word_count'
5052
];
5153

classes/section/Section.php

+15-19
Original file line numberDiff line numberDiff line change
@@ -191,47 +191,43 @@ public function setIdentifyType(string|array $identifyType, string $locale = nul
191191
}
192192

193193
/**
194-
* Get section path.
195-
*
196-
* @return string
194+
* Get localized series description.
197195
*/
198-
public function getPath()
196+
public function getLocalizedDescription(): ?string
199197
{
200-
return $this->getData('path');
198+
return $this->getLocalizedData('description');
201199
}
202200

203201
/**
204-
* Set section path.
205-
*
206-
* @param string $path
202+
* Get series description.
207203
*/
208-
public function setPath($path)
204+
public function getDescription(?string $locale): string|array|null
209205
{
210-
return $this->setData('path', $path);
206+
return $this->getData('description', $locale);
211207
}
212208

213209
/**
214-
* Get localized series description.
210+
* Set series description.
215211
*/
216-
public function getLocalizedDescription(): ?string
212+
public function setDescription(string|array $description, string $locale = null): void
217213
{
218-
return $this->getLocalizedData('description');
214+
$this->setData('description', $description, $locale);
219215
}
220216

221217
/**
222-
* Get series description.
218+
* Set if section is browsable.
223219
*/
224-
public function getDescription(?string $locale): string|array|null
220+
public function setNotBrowsable(bool $notBrowsable): void
225221
{
226-
return $this->getData('description', $locale);
222+
$this->setData('notBrowsable', $notBrowsable);
227223
}
228224

229225
/**
230-
* Set series description.
226+
* Return boolean indicating if section is browsable.
231227
*/
232-
public function setDescription(string|array $description, string $locale = null): void
228+
public function getNotBrowsable(): bool
233229
{
234-
$this->setData('description', $description, $locale);
230+
return $this->getData('notBrowsable');
235231
}
236232
}
237233

classes/services/ContextService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function afterAddContext($hookName, $args)
6565
$section = Repo::section()->newDataObject();
6666
$section->setTitle(__('section.default.title'), $context->getPrimaryLocale());
6767
$section->setAbbrev(__('section.default.abbrev'), $context->getPrimaryLocale());
68-
$section->setPath(__('section.default.path'), $context->getPrimaryLocale());
68+
$section->setUrlPath(__('section.default.urlPath'), $context->getPrimaryLocale());
6969
$section->setMetaIndexed(true);
7070
$section->setMetaReviewed(true);
7171
$section->setPolicy(__('section.default.policy'), $context->getPrimaryLocale());

classes/submission/maps/Schema.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function mapByProperties(array $props, Submission $submission): array
2929
$this->request,
3030
Application::ROUTE_PAGE,
3131
$this->context->getPath(),
32-
'preprint',
32+
'preprints',
3333
'view',
3434
$submission->getBestId()
3535
);

controllers/grid/settings/sections/form/SectionForm.php

+26-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
class SectionForm extends PKPSectionForm
2424
{
25+
/** @var int $_serverId */
26+
public $_serverId;
27+
2528
/**
2629
* Constructor.
2730
*
@@ -36,11 +39,22 @@ public function __construct($request, $sectionId = null)
3639
$sectionId
3740
);
3841

42+
$this->_serverId = $serverId = $request->getContext()->getId();
43+
3944
// Validation checks for this form
45+
$form = $this;
4046
$this->addCheck(new \PKP\form\validation\FormValidatorLocale($this, 'title', 'required', 'manager.setup.form.section.nameRequired'));
4147
$this->addCheck(new \PKP\form\validation\FormValidatorLocale($this, 'abbrev', 'required', 'manager.sections.form.abbrevRequired'));
42-
$this->addCheck(new \PKP\form\validation\FormValidator($this, 'path', 'required', 'manager.setup.form.section.pathRequired'));
43-
$server = $request->getServer();
48+
$this->addCheck(new \PKP\form\validation\FormValidatorRegExp($this, 'urlPath', 'required', 'grid.section.urlPathAlphaNumeric', '/^[a-zA-Z0-9\/._-]+$/'));
49+
$this->addCheck(new \PKP\form\validation\FormValidatorCustom(
50+
$this,
51+
'urlPath',
52+
'required',
53+
'grid.section.urlPathExists',
54+
function ($urlPath) use ($form, $serverId) {
55+
return !Repo::section()->getByUrlPath($urlPath, $serverId) || ($form->getData('oldPath') != null && $form->getData('oldPath') == $urlPath);
56+
}
57+
));
4458
}
4559

4660
/**
@@ -62,6 +76,8 @@ public function initData()
6276
'abbrev' => $this->section->getAbbrev(null), // Localized
6377
'reviewFormId' => $this->section->getReviewFormId(),
6478
'isInactive' => $this->section->getIsInactive(),
79+
'urlPath' => $this->section->getUrlPath(),
80+
'notBrowsable' => $this->section->getNotBrowsable(),
6581
'metaIndexed' => !$this->section->getMetaIndexed(), // #2066: Inverted
6682
'metaReviewed' => !$this->section->getMetaReviewed(), // #2066: Inverted
6783
'abstractsNotRequired' => $this->section->getAbstractsNotRequired(),
@@ -71,7 +87,6 @@ public function initData()
7187
'hideAuthor' => $this->section->getHideAuthor(),
7288
'policy' => $this->section->getPolicy(null), // Localized
7389
'wordCount' => $this->section->getAbstractWordCount(),
74-
'path' => $this->section->getPath(),
7590
'description' => $this->section->getDescription(null)
7691
]);
7792
}
@@ -125,7 +140,12 @@ public function fetch($request, $template = null, $display = false)
125140
public function readInputData()
126141
{
127142
parent::readInputData();
128-
$this->readUserVars(['abbrev', 'path', 'description', 'policy', 'identifyType', 'isInactive', 'metaIndexed', 'abstractsNotRequired', 'editorRestriction', 'wordCount']);
143+
$this->readUserVars(['abbrev', 'urlPath', 'description', 'policy', 'identifyType', 'isInactive', 'notBrowsable', 'metaIndexed', 'abstractsNotRequired', 'editorRestriction', 'wordCount']);
144+
// For path duplicate checking; excuse the current path.
145+
if ($sectionId = $this->getSectionId()) {
146+
$section = Repo::section()->get($sectionId, $this->_serverId);
147+
$this->setData('oldPath', $section->getUrlPath());
148+
}
129149
}
130150

131151
/**
@@ -157,9 +177,10 @@ public function execute(...$functionArgs)
157177
// Populate/update the section object from the form
158178
$section->setTitle($this->getData('title'), null); // Localized
159179
$section->setAbbrev($this->getData('abbrev'), null); // Localized
160-
$section->setPath($this->getData('path'));
180+
$section->setUrlPath($this->getData('urlPath'));
161181
$section->setDescription($this->getData('description'), null); // Localized
162182
$section->setIsInactive($this->getData('isInactive') ? 1 : 0);
183+
$section->setNotBrowsable($this->getData('notBrowsable') ? 1 : 0);
163184
$section->setMetaIndexed($this->getData('metaIndexed') ? 0 : 1); // #2066: Inverted
164185
$section->setAbstractsNotRequired($this->getData('abstractsNotRequired') ? 1 : 0);
165186
$section->setIdentifyType($this->getData('identifyType'), null); // Localized

dbscripts/xml/upgrade.xml

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<migration class="APP\migration\upgrade\v3_4_0\I6782_CleanOldMetrics" />
6868
<migration class="APP\migration\upgrade\v3_4_0\I6782_RemovePlugins" />
6969
<migration class="PKP\migration\upgrade\v3_4_0\I7286_BatchesMigration"/>
70+
<migration class="APP\migration\upgrade\v3_4_0\I5932_GenerateSectionUrlPaths" />
7071
<migration class="APP\migration\upgrade\v3_4_0\I8151_ExtendSettingValues"/>
7172
<migration class="PKP\migration\upgrade\v3_4_0\I8151_ExtendSettingValues"/>
7273
<migration class="PKP\migration\upgrade\v3_4_0\I7366_UpdateUserAPIKeySettings"/>

locale/de_DE/default.po

+3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ msgstr ""
130130
msgid "default.submission.step.review"
131131
msgstr ""
132132

133+
msgid "section.default.urlPath"
134+
msgstr "Preprints"
135+
133136
#~ msgid "default.contextSettings.checklist.bibliographicRequirements"
134137
#~ msgstr ""
135138
#~ "Der Text hält sich an die stilistischen und bibliografischen "

locale/de_DE/locale.po

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ msgid "submission.layout.galleyPublicIdentificationExists"
5353
msgstr "Es gibt bereits eine öffentliche Kennzeichnung der Gesamtpfahne."
5454

5555
msgid "section.description"
56-
msgstr "Abschnittsarchiv Beschreibung"
57-
58-
msgid "section.pathDescription"
5956
msgstr ""
6057
"Abschnitt URL-Pfad. Verwenden Sie Bindestriche (-) anstelle von Leerzeichen."
6158

@@ -373,6 +370,9 @@ msgstr ""
373370
msgid "installer.allowFileUploads"
374371
msgstr ""
375372

373+
msgid "section.urlPathDescription"
374+
msgstr ""
375+
376376
msgid "installer.maxFileUploadSize"
377377
msgstr ""
378378

locale/en_US/default.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ msgstr "Preprints"
2121
msgid "section.default.abbrev"
2222
msgstr "PRE"
2323

24-
msgid "section.default.path"
24+
msgid "section.default.urlPath"
2525
msgstr "preprints"
2626

2727
msgid "section.default.policy"

locale/en_US/locale.po

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ msgstr "Public galley identification already exists."
5757
msgid "section.description"
5858
msgstr "Section archive Description"
5959

60-
msgid "section.pathDescription"
60+
msgid "section.urlPathDescription"
6161
msgstr "Section URL Path. Use hyphens (-) instead of spaces."
6262

6363
msgid "section.emptySection"

locale/en_US/manager.po

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ msgstr "Identify items posted in this section as a(n)"
105105
msgid "manager.sections.identifyTypeExamples"
106106
msgstr "(For example etc.)"
107107

108+
msgid "manager.sections.notBrowsable"
109+
msgstr "Disable the page that allows readers to browse all preprints in this section"
110+
108111
msgid "manager.sections.policy"
109112
msgstr "Section Policy"
110113

locale/es_ES/default.po

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ msgstr ""
135135
msgid "default.submission.step.review"
136136
msgstr ""
137137

138+
msgid "section.default.urlPath"
139+
msgstr "preprints"
140+
138141
#~ msgid "default.groups.abbrev.editor"
139142
#~ msgstr "JE"
140143

locale/es_ES/locale.po

+3
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,9 @@ msgstr ""
387387
msgid "installer.additionalLocalesInstructions"
388388
msgstr ""
389389

390+
msgid "section.urlPathDescription"
391+
msgstr ""
392+
390393
msgid "installer.filesDirInstructions"
391394
msgstr ""
392395

locale/fr_CA/default.po

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ msgstr "Texte de la prépublication"
3030
msgid "default.contextSettings.authorGuidelines"
3131
msgstr ""
3232

33+
msgid "section.default.urlPath"
34+
msgstr "prépublications"
35+
3336
msgid "default.contextSettings.checklist"
3437
msgstr ""
3538

locale/fr_CA/locale.po

+3
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ msgid "about.onlineSubmissions.submissionActions"
262262
msgstr "{$newSubmission} ou {$viewSubmissions}."
263263

264264
#, fuzzy
265+
msgid "section.urlPathDescription"
266+
msgstr ""
267+
265268
msgid "about.onlineSubmissions.submitToSection"
266269
msgstr ""
267270
"Faire une nouvelle soumission à la série <a href=\"{$url}\">{$name}</a>."

0 commit comments

Comments
 (0)