Skip to content

Commit

Permalink
pkp/pkp-lib#10511 remove invalid series navigation menu items
Browse files Browse the repository at this point in the history
  • Loading branch information
kaitlinnewson committed Nov 25, 2024
1 parent 6d5eefa commit 256006c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
54 changes: 54 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,54 @@
<?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');

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();
}
}
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 256006c

Please sign in to comment.