diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cf70af..b15410c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,12 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.1.2] - Ongoing +## [2.1.2] - 2024-09-27 This update introduces bug fixes ### Added - Add getter methods for installation lifecycle steps + - Added pre-install & post-install execution unit handling ### Changed - Updated DocStrings in PackageManager diff --git a/src/ncc/Classes/ExecutionUnitRunner.php b/src/ncc/Classes/ExecutionUnitRunner.php index d7b17cf..aaecece 100644 --- a/src/ncc/Classes/ExecutionUnitRunner.php +++ b/src/ncc/Classes/ExecutionUnitRunner.php @@ -31,6 +31,7 @@ use ncc\Classes\PhpExtension\PhpRunner; use ncc\Enums\Runners; use ncc\Exceptions\ConfigurationException; + use ncc\Exceptions\IntegrityException; use ncc\Exceptions\IOException; use ncc\Exceptions\NotSupportedException; use ncc\Exceptions\OperationException; @@ -137,6 +138,7 @@ * @return int * @throws ConfigurationException * @throws OperationException + * @throws IntegrityException */ public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int { diff --git a/src/ncc/Classes/PackageReader.php b/src/ncc/Classes/PackageReader.php index 3c9858d..bd17ccf 100644 --- a/src/ncc/Classes/PackageReader.php +++ b/src/ncc/Classes/PackageReader.php @@ -550,6 +550,17 @@ } } + /** + * Checks if an execution unit with the specified name exists in the package. + * + * @param string $name The name of the execution unit to check. + * @return bool True if the execution unit exists, false otherwise. + */ + public function executionUnitExists(string $name): bool + { + return isset($this->headers[PackageStructure::DIRECTORY->value][sprintf('@%s:%s', PackageDirectory::EXECUTION_UNITS->value, $name)]); + } + /** * Returns an execution unit from the package by pointer * diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index cfdd9f1..af8612d 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -28,6 +28,7 @@ use Exception; use InvalidArgumentException; use ncc\Classes\ArchiveExtractor; + use ncc\Classes\ExecutionUnitRunner; use ncc\Classes\PackageReader; use ncc\Classes\ShutdownHandler; use ncc\CLI\Main; @@ -426,6 +427,20 @@ $this->uninstall($package_reader->getAssembly()->getPackage(), $package_reader->getAssembly()->getVersion()); } + if(count($package_reader->getInstaller()->getPreInstall()) > 0) + { + foreach ($package_reader->getInstaller()->getPreInstall() as $unit) + { + Console::outVerbose(sprintf('Running pre-install unit: %s', $unit)); + if(!$package_reader->executionUnitExists($unit)) + { + throw new OperationException(sprintf("Unable to run pre-install unit '%s' because it is not defined in the package", $unit)); + } + + ExecutionUnitRunner::executeFromPackage($package_reader, $unit); + } + } + $filesystem = new Filesystem(); $package_path = PathFinder::getPackagesPath() . DIRECTORY_SEPARATOR . sprintf( '%s=%s', $package_reader->getAssembly()->getPackage(), $package_reader->getAssembly()->getVersion() @@ -528,6 +543,20 @@ } } + if(count($package_reader->getInstaller()->getPostInstall()) > 0) + { + foreach ($package_reader->getInstaller()->getPostInstall() as $unit) + { + Console::outVerbose(sprintf('Running post-install unit: %s', $unit)); + if(!$package_reader->executionUnitExists($unit)) + { + throw new OperationException(sprintf("Unable to run post-install unit '%s' because it is not defined in the package", $unit)); + } + + ExecutionUnitRunner::executeFromPackage($package_reader, $unit); + } + } + return $installed_packages; }