Skip to content
Snippets Groups Projects

Issue #3330887: GUI install multiple modules at once.

Open Ben Mullins requested to merge issue/project_browser-3330887:multiple_modules into 1.0.x
Files
10
@@ -201,12 +201,18 @@ class InstallerController extends ControllerBase {
$core_installing = $this->projectBrowserTempStore->get('installing');
$return = ['status' => self::STATUS_IDLE];
if (isset($requiring['project_id']) && $requiring['project_id'] === $project_id) {
$return['status'] = self::STATUS_REQUIRING_PROJECT;
$return['phase'] = $requiring['phase'];
}
if ($core_installing === $project_id) {
$return['status'] = self::STATUS_INSTALLING_PROJECT;
$projects = explode('-', $project_id);
foreach ($projects as $pid) {
if (isset($requiring['project_id']) && in_array($pid, explode('-', $requiring['project_id']))) {
$return['status'] = self::STATUS_REQUIRING_PROJECT;
$return['phase'] = $requiring['phase'];
break;
}
if ($core_installing === $pid) {
$return['status'] = self::STATUS_INSTALLING_PROJECT;
break;
}
}
return new JsonResponse($return);
@@ -292,11 +298,12 @@ class InstallerController extends ControllerBase {
* @param string $stage_id
* The stage id.
*/
private function setRequiringState(string $project_id, string $phase, string $stage_id = ''): void {
private function setRequiringState(string $project_id, string $phase, string $stage_id = '', $pre_or_post = ''): void {
$this->projectBrowserTempStore->set('requiring', [
'project_id' => $project_id,
'phase' => $phase,
'stage_id' => $stage_id,
'pre_or_post' => $pre_or_post,
]);
}
@@ -373,9 +380,15 @@ class InstallerController extends ControllerBase {
if ($source === NULL) {
return new JsonResponse(['message' => "Cannot download $project_id from any available source"], 500);
}
if (!$source->isProjectSafe($project_id)) {
return new JsonResponse(['message' => "$project_id is not safe to add because its security coverage has been revoked"], 500);
$projects = explode('-', $project_id);
foreach($projects as $pid) {
if (!$source->isProjectSafe($pid)) {
return new JsonResponse(['message' => "$pid is not safe to add because its security coverage has been revoked"], 500);
}
}
$stage_available = $this->installer->isAvailable();
if (!$stage_available) {
$requiring_metadata = $this->projectBrowserTempStore->getMetadata('requiring');
@@ -416,8 +429,9 @@ class InstallerController extends ControllerBase {
}
try {
$this->setRequiringState($project_id, 'creating install stage', '', 'pre');
$stage_id = $this->installer->create();
$this->setRequiringState($project_id, 'creating install stage', $stage_id);
$this->setRequiringState($project_id, 'creating install stage', $stage_id, 'post');
}
catch (\Exception $e) {
$this->cancelRequire();
@@ -447,9 +461,15 @@ class InstallerController extends ControllerBase {
'message' => sprintf('Error: a request to install %s was ignored as an install for a different module is in progress.', $project_id),
], 500);
}
$this->setRequiringState($project_id, 'requiring module', $stage_id);
$this->setRequiringState($project_id, 'requiring module', $stage_id, 'pre');
try {
$this->installer->claim($stage_id)->require(["$composer_namespace/$project_id"]);
$this->installer->claim($stage_id);
$project_ids = explode('-', $project_id);
$composer_namespaces = explode('-', $composer_namespace);
foreach ($project_ids as $index => $pid) {
$this->installer->require(["$composer_namespaces[$index]/$pid"]);
}
$this->setRequiringState($project_id, 'requiring module', $stage_id, 'post');
}
catch (\Exception $e) {
$this->cancelRequire();
@@ -472,9 +492,10 @@ class InstallerController extends ControllerBase {
* Status message.
*/
public function apply(string $composer_namespace, string $project_id, string $stage_id): JsonResponse {
$this->setRequiringState($project_id, 'applying', $stage_id);
$this->setRequiringState($project_id, 'applying', $stage_id, 'pre');
try {
$this->installer->claim($stage_id)->apply();
$this->setRequiringState($project_id, 'applying', $stage_id, 'post');
}
catch (\Exception $e) {
$this->cancelRequire();
@@ -497,9 +518,10 @@ class InstallerController extends ControllerBase {
* Status message.
*/
public function postApply(string $composer_namespace, string $project_id, string $stage_id): JsonResponse {
$this->setRequiringState($project_id, 'post apply', $stage_id);
$this->setRequiringState($project_id, 'post apply', $stage_id, 'pre');
try {
$this->installer->claim($stage_id)->postApply();
$this->setRequiringState($project_id, 'post apply', $stage_id, 'post');
}
catch (\Exception $e) {
return $this->errorResponse($e, 'post apply');
@@ -521,18 +543,28 @@ class InstallerController extends ControllerBase {
* Status message.
*/
public function destroy(string $composer_namespace, string $project_id, string $stage_id): JsonResponse {
$this->setRequiringState($project_id, 'completing', $stage_id);
$this->setRequiringState($project_id, 'completing', $stage_id, 'pre');
try {
$this->installer->claim($stage_id)->destroy();
$this->logger->info("destroyed the $project_id for $stage_id");
$this->setRequiringState($project_id, 'completing', $stage_id, 'post');
}
catch (\Exception $e) {
return $this->errorResponse($e, 'destroy');
}
$this->projectBrowserTempStore->delete('requiring');
$this->logger->info("was able to delete $project_id tempstore" . print_r([
'phase' => 'destroy',
'status' => self::STAGE_STATUS_OK,
'stage_id' => $stage_id,
'message' => strpos($project_id, '-') === FALSE ? $this->t('Project @project was downloaded successfully', ['@project' => $project_id]) : 'All modules downloaded',
], TRUE));
return new JsonResponse([
'phase' => 'destroy',
'status' => self::STAGE_STATUS_OK,
'stage_id' => $stage_id,
'message' => strpos($project_id, '-') === FALSE ? $this->t('Project @project was downloaded successfully', ['@project' => $project_id]) : 'All modules downloaded',
]);
}
@@ -560,4 +592,22 @@ class InstallerController extends ControllerBase {
]);
}
/**
* Checks if a stage id can be claimed.
*
* @param $stage_id
*
* @return bool
* TRUE if the stage can be claimed with the provided id.
*/
public function canClaim($stage_id) {
try {
$this->installer->claim($stage_id);
}
catch (\Exception $e) {
return FALSE;
}
return TRUE;
}
}
Loading