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.
- Loading branch information
1 parent
6d77552
commit e2beb8a
Showing
2 changed files
with
75 additions
and
35 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
classes/migration/upgrade/v3_5_0/I10403_EmailTemplateRoleAccess.php
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.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,75 @@ | ||
<?php | ||
|
||
namespace PKP\migration\upgrade\v3_5_0; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use PKP\context\Context; | ||
use PKP\emailTemplate\EmailTemplateAccessGroup; | ||
use PKP\migration\Migration; | ||
|
||
class I10403_EmailTemplateUserGroupAccess extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
$contextDao = \APP\core\Application::getContextDAO(); | ||
Schema::create('email_template_user_group_access', function (Blueprint $table) use ($contextDao) { | ||
$table->bigInteger('email_template_user_group_access_id')->autoIncrement(); | ||
$table->string('email_key', 255); | ||
$table->bigInteger('context_id'); | ||
$table->bigInteger('user_group_id')->nullable(); | ||
|
||
$table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade'); | ||
$table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade'); | ||
}); | ||
|
||
$contextIds = array_map(fn (Context $context) => $context->getId(), $contextDao->getAll()->toArray()); | ||
|
||
if (!empty($contextIds)) { | ||
DB::table('email_template_user_group_access')->select('*')->get(); | ||
|
||
$defaultTemplateKeys = DB::table('email_templates_default_data')->select()->pluck('email_key')->all(); | ||
$alternateTemplates = DB::table('email_templates')->select(['context_id', 'email_key'])->get()->toArray(); | ||
|
||
$data = []; | ||
|
||
// Record any existing default templates as unrestricted for existing Contexts | ||
foreach ($defaultTemplateKeys as $defaultTemplateKey) { | ||
foreach ($contextIds as $contextId) { | ||
$data[] = [ | ||
'email_key' => $defaultTemplateKey, | ||
'context_id' => $contextId, | ||
'user_group_id' => null | ||
]; | ||
} | ||
} | ||
|
||
// For any existing alternate template, register it as unrestricted within its assigned context | ||
foreach ($alternateTemplates as $template) { | ||
foreach ($contextIds as $contextId) { | ||
if ($contextId === $template->context_id) { | ||
$data[] = [ | ||
'email_key' => $template->email_key, | ||
'context_id' => $contextId, | ||
'user_group_id' => null | ||
]; | ||
} | ||
} | ||
} | ||
|
||
EmailTemplateAccessGroup::insert($data); | ||
} | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::drop('email_template_user_group_access'); | ||
} | ||
} |