Skip to content

Commit

Permalink
TASK: Check for existence of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed May 24, 2023
1 parent a1a7c84 commit c5385c8
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,47 @@
use TYPO3\Surf\Domain\Model\Node;
use TYPO3\Surf\Domain\Service\ShellCommandService;

/**
* Find all releases for current application
*
* @return string[]
*/
function findAllReleases(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): array
{
$releasesPath = $node->getReleasesPath();
$allReleasesList = $shell->execute("if [ -d $releasesPath/. ]; then find $releasesPath/. -maxdepth 1 -type d -exec basename {} \; ; fi", $node, $deployment);
if (!function_exists('TYPO3\Surf\findAllReleases')) {
/**
* Find all releases for current application
*
* @return string[]
*/
function findAllReleases(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): array
{
$releasesPath = $node->getReleasesPath();
$allReleasesList = $shell->execute("if [ -d $releasesPath/. ]; then find $releasesPath/. -maxdepth 1 -type d -exec basename {} \; ; fi", $node, $deployment);

$allReleases = preg_split('/\s+/', $allReleasesList, -1, PREG_SPLIT_NO_EMPTY);

if ($allReleases === false) {
return [];
}

return $allReleases;
}
}

$allReleases = preg_split('/\s+/', $allReleasesList, -1, PREG_SPLIT_NO_EMPTY);
if (!function_exists('TYPO3\Surf\findPreviousReleaseIdentifier')) {
/**
* Get previous release identifier
*/
function findPreviousReleaseIdentifier(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): string
{
$previousReleasePath = $node->getReleasesPath().'/previous';

if ($allReleases === false) {
return[];
return trim($shell->execute("if [ -h $previousReleasePath ]; then basename `readlink $previousReleasePath` ; fi", $node, $deployment) ?? '');
}

return $allReleases;
}

/**
* Get previous release identifier
*/
function findPreviousReleaseIdentifier(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): string
{
$previousReleasePath = $node->getReleasesPath() . '/previous';
return trim($shell->execute("if [ -h $previousReleasePath ]; then basename `readlink $previousReleasePath` ; fi", $node, $deployment) ?? '');
}
if (!function_exists('TYPO3\Surf\findCurrentReleaseIdentifier')) {
/**
* Get current release identifier
*/
function findCurrentReleaseIdentifier(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): string
{
$currentReleasePath = $node->getReleasesPath().'/current';

/**
* Get current release identifier
*/
function findCurrentReleaseIdentifier(Deployment $deployment, Node $node, Application $application, ShellCommandService $shell): string
{
$currentReleasePath = $node->getReleasesPath() . '/current';
return trim($shell->execute("if [ -h $currentReleasePath ]; then basename `readlink $currentReleasePath` ; fi", $node, $deployment));
return trim($shell->execute("if [ -h $currentReleasePath ]; then basename `readlink $currentReleasePath` ; fi", $node, $deployment));
}
}

0 comments on commit c5385c8

Please sign in to comment.