Implement pre-install and post-install unit execution
This commit is contained in:
parent
91fe129bf4
commit
e2a8dbfe27
4 changed files with 44 additions and 1 deletions
|
@ -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/),
|
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).
|
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
|
This update introduces bug fixes
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Add getter methods for installation lifecycle steps
|
- Add getter methods for installation lifecycle steps
|
||||||
|
- Added pre-install & post-install execution unit handling
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Updated DocStrings in PackageManager
|
- Updated DocStrings in PackageManager
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
use ncc\Classes\PhpExtension\PhpRunner;
|
use ncc\Classes\PhpExtension\PhpRunner;
|
||||||
use ncc\Enums\Runners;
|
use ncc\Enums\Runners;
|
||||||
use ncc\Exceptions\ConfigurationException;
|
use ncc\Exceptions\ConfigurationException;
|
||||||
|
use ncc\Exceptions\IntegrityException;
|
||||||
use ncc\Exceptions\IOException;
|
use ncc\Exceptions\IOException;
|
||||||
use ncc\Exceptions\NotSupportedException;
|
use ncc\Exceptions\NotSupportedException;
|
||||||
use ncc\Exceptions\OperationException;
|
use ncc\Exceptions\OperationException;
|
||||||
|
@ -137,6 +138,7 @@
|
||||||
* @return int
|
* @return int
|
||||||
* @throws ConfigurationException
|
* @throws ConfigurationException
|
||||||
* @throws OperationException
|
* @throws OperationException
|
||||||
|
* @throws IntegrityException
|
||||||
*/
|
*/
|
||||||
public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int
|
public static function executeFromPackage(PackageReader $package_reader, string $policy_name, array $args=[]): int
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
* Returns an execution unit from the package by pointer
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
use Exception;
|
use Exception;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use ncc\Classes\ArchiveExtractor;
|
use ncc\Classes\ArchiveExtractor;
|
||||||
|
use ncc\Classes\ExecutionUnitRunner;
|
||||||
use ncc\Classes\PackageReader;
|
use ncc\Classes\PackageReader;
|
||||||
use ncc\Classes\ShutdownHandler;
|
use ncc\Classes\ShutdownHandler;
|
||||||
use ncc\CLI\Main;
|
use ncc\CLI\Main;
|
||||||
|
@ -426,6 +427,20 @@
|
||||||
$this->uninstall($package_reader->getAssembly()->getPackage(), $package_reader->getAssembly()->getVersion());
|
$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();
|
$filesystem = new Filesystem();
|
||||||
$package_path = PathFinder::getPackagesPath() . DIRECTORY_SEPARATOR . sprintf(
|
$package_path = PathFinder::getPackagesPath() . DIRECTORY_SEPARATOR . sprintf(
|
||||||
'%s=%s', $package_reader->getAssembly()->getPackage(), $package_reader->getAssembly()->getVersion()
|
'%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;
|
return $installed_packages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue