public deletePackage ( string $packageKey ) : void | ||
$packageKey | string | package to remove |
return | void |
public function deletePackage($packageKey)
{
if (!$this->isPackageAvailable($packageKey)) {
throw new Exception\UnknownPackageException('Package "' . $packageKey . '" is not available and cannot be removed.', 1166543253);
}
$package = $this->getPackage($packageKey);
if ($package->isProtected()) {
throw new Exception\ProtectedPackageKeyException('The package "' . $packageKey . '" is protected and cannot be removed.', 1220722120);
}
$packagePath = $package->getPackagePath();
if ($this->isPackageActive($packageKey)) {
$this->deactivatePackage($packageKey);
$packagePath = Files::concatenatePaths([$this->packagesBasePath, $this->buildInactivePackageRelativePath($packagePath)]);
}
$this->unregisterPackage($package);
try {
Files::removeDirectoryRecursively($packagePath);
} catch (UtilityException $exception) {
throw new Exception('Please check file permissions. The directory "' . $packagePath . '" for package "' . $packageKey . '" could not be removed.', 1301491089, $exception);
}
}
/** * @test */ public function deletePackageRemovesPackageFromAvailableAndActivePackagesAndDeletesThePackageDirectory() { $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage'); $packagePath = $package->getPackagePath(); $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_CONFIGURATION), 'The package configuration directory does not exist.'); $this->assertTrue($this->packageManager->isPackageActive('Acme.YetAnotherTestPackage'), 'The package is not active.'); $this->assertTrue($this->packageManager->isPackageAvailable('Acme.YetAnotherTestPackage'), 'The package is not available.'); $this->packageManager->deletePackage('Acme.YetAnotherTestPackage'); $this->assertFalse(is_dir($packagePath . PackageInterface::DIRECTORY_CONFIGURATION), 'The package configuration directory does still exist.'); $this->assertFalse($this->packageManager->isPackageActive('Acme.YetAnotherTestPackage'), 'The package is still active.'); $this->assertFalse($this->packageManager->isPackageAvailable('Acme.YetAnotherTestPackage'), 'The package is still available.'); }