Skip to content

Commit

Permalink
Merge pull request #1772 from kaitlinnewson/10511-main
Browse files Browse the repository at this point in the history
 pkp/pkp-lib#10511 fix and cleanup invalid series navigation menu items
  • Loading branch information
jonasraoni authored Nov 29, 2024
2 parents 7ff1327 + dc49076 commit 350b77f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
58 changes: 58 additions & 0 deletions classes/migration/upgrade/v3_5_0/I10511_RemoveSeriesMenuItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* @file classes/migration/upgrade/v3_5_0/I10511_RemoveSeriesMenuItems.php
*
* Copyright (c) 2024 Simon Fraser University
* Copyright (c) 2024 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class I10511_RemoveSeriesMenuItems
*
* @brief Remove invalid series menu items.
*/

namespace APP\migration\upgrade\v3_5_0;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use PKP\install\DowngradeNotSupportedException;
use PKP\migration\Migration;

class I10511_RemoveSeriesMenuItems extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$invalidNavigationMenuItemIds = DB::table('navigation_menu_items')
->where('type', 'NMI_TYPE_SERIES')
->whereNotIn('path', function (Builder $query) {
$query->select('series_id')->from('series');
})->pluck('navigation_menu_item_id');

if (!$invalidNavigationMenuItemIds->count()) {
return;
}

DB::table('navigation_menu_item_assignments')
->whereIn('parent_id', $invalidNavigationMenuItemIds)
->update(['parent_id' => null]);

DB::table('navigation_menu_items')
->where('type', 'NMI_TYPE_SERIES')
->whereIn('navigation_menu_item_id', $invalidNavigationMenuItemIds)
->delete();
}

/**
* Reverse the downgrades
*
* @throws DowngradeNotSupportedException
*/
public function down(): void
{
throw new DowngradeNotSupportedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public function fetch($request, $template = null, $display = false)
->getCollector()
->filterByContextIds([$contextId])
->getMany();
$seriesTitles = $series->map(fn (Section $seriesObj) => [
$seriesTitles = $series->mapWithKeys(fn (Section $seriesObj) => [
$seriesObj->getId() => $seriesObj->getLocalizedTitle()
]);
])->all();

$categories = Repo::category()->getCollector()
->filterByParentIds([null])
Expand Down
1 change: 1 addition & 0 deletions dbscripts/xml/upgrade.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<migration class="APP\migration\upgrade\v3_5_0\I5885_RenameReviewReminderSettingsName"/>
<migration class="PKP\migration\upgrade\v3_5_0\COA75_AddUserRoleEndEmail"/>
<migration class="APP\migration\upgrade\v3_5_0\I10561_OnixFilter"/>
<migration class="APP\migration\upgrade\v3_5_0\I10511_RemoveSeriesMenuItems"/>
</upgrade>

<!-- Update plugin configuration - should be done as the final upgrade task -->
Expand Down

0 comments on commit 350b77f

Please sign in to comment.