Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial work to remove config when plugin/ theme is uninstalled #2715

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ Icon?
Thumbs.db
*.swp

# phpstorm
# IDE related
.idea/*
.vscode/*

# testing stuff
tests/_output/*
Expand Down
32 changes: 27 additions & 5 deletions system/src/Grav/Common/GPM/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,18 @@ public static function sophisticatedInstall($source_path, $install_path, $ignore
}

/**
* 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.
*/
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;
}

Expand All @@ -358,7 +358,29 @@ public static function uninstall($path, $options = [])
}
}

$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')) {
Expand Down