Initial work to remove config when plugin/ theme is uninstalled

This commit is contained in:
Jeremy Gonyea 2019-11-01 20:54:02 -04:00
parent feeee9ef86
commit b3e188e3de
2 changed files with 29 additions and 6 deletions

3
.gitignore vendored
View File

@ -35,8 +35,9 @@ Icon?
Thumbs.db
*.swp
# phpstorm
# IDE related
.idea/*
.vscode/*
# testing stuff
tests/_output/*

View File

@ -327,9 +327,9 @@ class Installer
}
/**
* Uninstalls one or more given package
* Uninstalls one or more given packages
*
* @param string $path The slug of the package(s)
* @param string $path The path of the package(s)
* @param array $options Options to use for uninstalling
*
* @return bool True if everything went fine, False otherwise.
@ -337,8 +337,8 @@ class Installer
public static function uninstall($path, $options = [])
{
$options = array_merge(self::$options, $options);
if (!self::isValidDestination($path, $options['exclude_checks'])
) {
$config_folder_paths = false;
if (!self::isValidDestination($path, $options['exclude_checks'])) {
return false;
}
@ -358,7 +358,29 @@ class Installer
}
}
$result = Folder::delete($path);
// Find corresponding config yaml file for the package.
$slug = end(explode(DS, $path));
$grav = Grav::instance();
$gpm = new GPM();
$locator = Grav::instance()['locator'];
$package = $gpm->findPackage($slug);
if ($package){
$package_type = $package->package_type;
$config_folder_paths = $locator->findResource('config://' . $package_type . '/' . $slug . '.yaml');
}
if (false !== $config_folder_paths) {
$config_result = unlink($config_folder_paths);
} else {
$config_result = true;
}
// Delete package folder.
$folder_result = Folder::delete($path);
$result = ($folder_result && $config_result);
self::$message = '';
if ($result && $installer && method_exists($installer, 'postUninstall')) {