mirror of
https://github.com/getgrav/grav-plugin-admin.git
synced 2025-11-03 03:46:30 +01:00
Handle error when trying to remove a package that other packages depend on.
This commit is contained in:
@@ -522,6 +522,23 @@ class Admin
|
|||||||
return $dependencies;
|
return $dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get list of packages that depend on the passed package slug
|
||||||
|
*
|
||||||
|
* @param string $slug The package slug
|
||||||
|
*
|
||||||
|
* @return array|bool
|
||||||
|
*/
|
||||||
|
public function getPackagesThatDependOnPackage($slug)
|
||||||
|
{
|
||||||
|
$gpm = $this->gpm();
|
||||||
|
if (!$gpm) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $gpm->getPackagesThatDependOnPackage($slug);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the passed packages list can be updated
|
* Check the passed packages list can be updated
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -367,6 +367,22 @@ class AdminController
|
|||||||
|
|
||||||
require_once __DIR__ . '/gpm.php';
|
require_once __DIR__ . '/gpm.php';
|
||||||
|
|
||||||
|
//check if there are packages that have this as a dependency. Abort and show which ones
|
||||||
|
$dependent_packages = $this->admin->getPackagesThatDependOnPackage($package);
|
||||||
|
if (count($dependent_packages) > 0) {
|
||||||
|
if (count($dependent_packages) > 1) {
|
||||||
|
$message = "The installed packages <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove those first.";
|
||||||
|
} else {
|
||||||
|
$message = "The installed package <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove it first.";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->admin->json_response = ['status' => 'error', 'message' => $message];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->admin->json_response = ['status' => 'success', 'message' => 'xxx'];
|
||||||
|
return true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dependencies = $this->admin->dependenciesThatCanBeRemovedWhenRemoving($package);
|
$dependencies = $this->admin->dependenciesThatCanBeRemovedWhenRemoving($package);
|
||||||
$result = \Grav\Plugin\Admin\Gpm::uninstall($package, []);
|
$result = \Grav\Plugin\Admin\Gpm::uninstall($package, []);
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ class Packages {
|
|||||||
$(document).on('closing', '[data-remodal-id="remove-package"]', () => {
|
$(document).on('closing', '[data-remodal-id="remove-package"]', () => {
|
||||||
Packages.getBackToList(type);
|
Packages.getBackToList(type);
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('.remove-package-confirm').addClass('hidden');
|
||||||
|
$('.remove-package-error').removeClass('hidden');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,5 +31,11 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="remove-package-error hidden">
|
||||||
|
<h1>Error removing the {{ type }}</h1>
|
||||||
|
<div class="button-bar">
|
||||||
|
<button data-remodal-action="cancel" class="button secondary remodal-cancel"><i class="fa fa-fw fa-close"></i> {{ "PLUGIN_ADMIN.CANCEL"|tu }}</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user