Skip to content

Commit

Permalink
Migrations must run with admin permissions
Browse files Browse the repository at this point in the history
Ensures that an admin user is logged in when running migrations.
This helps avoid permission problems or restrictive workflows when
running migrations.

It reads `Migration/User` from `project.ini`, if this is not set or empty
it defaults to the admin user with ID 14.
`Migration/User` may either be a numerical ID or a login name.
  • Loading branch information
am0s authored Jun 2, 2021
1 parent df0619f commit fd7affb
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Aplia/Migration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@ public static function bootstrap()
$script->initialize();
$script->shutdown();

// Login admin user to ensure all content operations have sufficient permissions
$projectIni = eZINI::instance('project.ini');
/** @var eZUser|null */
$user = null;
if ($projectIni->hasVariable('Migration', 'User')) {
/** @var mixed */
$migrationUser = $projectIni->variable('Migration', 'User');
if (is_numeric($migrationUser)) {
// Fetch by object ID
$user = eZUser::instance($migrationUser);
} elseif (is_string($migrationUser) && $migrationUser) {
// Fetch by login name
/** @var eZUser */
$user = eZUser::fetchByName($migrationUser);
}
}
if (!$user) {
// No user set, use default admin user
$user = eZUser::instance(14);
}
$user->loginCurrent();

// Make sure all translations are fetched
eZContentLanguage::setPrioritizedLanguages(eZContentLanguage::fetchLocaleList());
}
Expand Down

0 comments on commit fd7affb

Please sign in to comment.