forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#10041 Consider existing default masthead roles and all user-role …
…assignments to be displayed on masthead
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
classes/migration/upgrade/v3_5_0/I10041_UserGroupsAndUserUserGroupsMastheadValues.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/migration/upgrade/v3_5_0/I10041_UserGroupsAndUserUserGroupsMastheadValues.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 I10041_UserGroupsAndUserUserGroupsMastheadValues | ||
* | ||
* @brief Consider existing default masthead roles and all user-role assignments to be dispalyed on masthead. | ||
*/ | ||
|
||
namespace PKP\migration\upgrade\v3_5_0; | ||
|
||
use Illuminate\Database\Query\Builder; | ||
use Illuminate\Support\Facades\DB; | ||
use PKP\migration\Migration; | ||
|
||
class I10041_UserGroupsAndUserUserGroupsMastheadValues extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
$userGroupIds = DB::table('user_group_settings') | ||
->where('setting_name', 'nameLocaleKey') | ||
->where( | ||
fn (Builder $q) => | ||
$q->where('setting_value', 'default.groups.name.editor') | ||
->orWhere('setting_value', 'default.groups.name.sectionEditor') | ||
->orWhere('setting_value', 'default.groups.name.externalReviewer') | ||
) | ||
->pluck('user_group_id'); | ||
DB::table('user_groups') | ||
->whereIn('user_group_id', $userGroupIds) | ||
->update(['masthead' => 1]); | ||
DB::table('user_user_groups') | ||
->update(['masthead' => 1]); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
*/ | ||
public function down(): void | ||
{ | ||
$userGroupIds = DB::table('user_group_settings') | ||
->where('setting_name', 'nameLocaleKey') | ||
->where( | ||
fn (Builder $q) => | ||
$q->where('setting_value', 'default.groups.name.editor') | ||
->orWhere('setting_value', 'default.groups.name.sectionEditor') | ||
->orWhere('setting_value', 'default.groups.name.externalReviewer') | ||
) | ||
->pluck('user_group_id'); | ||
DB::table('user_groups') | ||
->whereIn('user_group_id', $userGroupIds) | ||
->update(['masthead' => 0]); | ||
DB::table('user_user_groups') | ||
->update(['masthead' => null]); | ||
} | ||
} |