forked from pkp/pkp-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp#7366 user api key generation process update
- Loading branch information
1 parent
1719e79
commit b98f04f
Showing
4 changed files
with
152 additions
and
38 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
classes/migration/upgrade/v3_4_0/I7366_UpdateUserAPIKeySettings.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,47 @@ | ||
<?php | ||
|
||
namespace PKP\migration\upgrade\v3_4_0; | ||
|
||
use Illuminate\Support\Facades\DB; | ||
use PKP\install\DowngradeNotSupportedException; | ||
|
||
class I7366_UpdateUserAPIKeySettings extends \PKP\migration\Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
$userSettings = DB::table('user_settings') | ||
->select(['user_id', 'setting_name']) | ||
->where('setting_name', 'apiKeyEnabled') | ||
->distinct() | ||
->get(); | ||
|
||
$userSettingsWithApiKey = DB::table('user_settings') | ||
->select(['user_id', 'setting_name']) | ||
->where('user_id', $userSettings->pluck('user_id')->toArray()) | ||
->where('setting_name', 'apiKey') | ||
->distinct() | ||
->get(); | ||
|
||
DB::table('user_settings') | ||
->whereIn( | ||
'user_id', | ||
$userSettings | ||
->pluck('user_id') | ||
->diff($userSettingsWithApiKey->pluck('user_id')) | ||
->toArray() | ||
) | ||
->where('setting_name', 'apiKeyEnabled') | ||
->delete(); | ||
} | ||
|
||
/** | ||
* Reverse the migration. | ||
*/ | ||
public function down(): void | ||
{ | ||
throw new DowngradeNotSupportedException('Downgrade unsupported due to data update'); | ||
} | ||
} |
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
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
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