Skip to content

Commit

Permalink
Adjustment to previous commit, this adds a dependencies flag to the s…
Browse files Browse the repository at this point in the history
…tart/stop/restart endpoints instead of just the restart
  • Loading branch information
austinwbest committed Oct 4, 2024
1 parent e7acfc0 commit c3d22c8
Showing 1 changed file with 53 additions and 15 deletions.
68 changes: 53 additions & 15 deletions root/app/www/public/functions/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,39 +402,77 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = [])
apiResponse(400, ['error' => 'Missing name parameter']);
}

$dependencyFile = getFile(DEPENDENCY_FILE);
$dependencies = $dependencyFile[$payload['name']]['containers'];
$dependencies = is_array($dependencies) ? $dependencies : [];

$stopContainer = $docker->stopContainer($payload['name']);
$return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES);
$startContainer = $docker->startContainer($payload['name']);
$return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES);

if ($dependencies) {
$return[] = 'restarting dependenices...';

foreach ($dependencies as $dependency) {
$stopContainer = $docker->stopContainer($dependency);
$return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES);
$startContainer = $docker->startContainer($dependency);
$return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES);
if ($payload['dependencies']) {
$dependencyFile = getFile(DEPENDENCY_FILE);
$dependencies = $dependencyFile[$payload['name']]['containers'];
$dependencies = is_array($dependencies) ? $dependencies : [];

if ($dependencies) {
$return[] = 'restarting dependenices...';

foreach ($dependencies as $dependency) {
$stopContainer = $docker->stopContainer($dependency);
$return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES);
$startContainer = $docker->startContainer($dependency);
$return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES);
}
}
}

return $return;
return $payload['dependencies'] ? $return : $startContainer;
case 'docker-startContainer':
if (!$payload['name']) {
apiResponse(400, ['error' => 'Missing name parameter']);
}

return $docker->startContainer($payload['name']);
$startContainer = $docker->startContainer($payload['name']);
$return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES);

if ($payload['dependencies']) {
$dependencyFile = getFile(DEPENDENCY_FILE);
$dependencies = $dependencyFile[$payload['name']]['containers'];
$dependencies = is_array($dependencies) ? $dependencies : [];

if ($dependencies) {
$return[] = 'starting dependenices...';

foreach ($dependencies as $dependency) {
$startContainer = $docker->startContainer($dependency);
$return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES);
}
}
}

return $payload['dependencies'] ? $return : $startContainer;
case 'docker-stopContainer':
if (!$payload['name']) {
apiResponse(400, ['error' => 'Missing name parameter']);
}

return $docker->stopContainer($payload['name']);
$stopContainer = $docker->stopContainer($payload['name']);
$return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES);

if ($payload['dependencies']) {
$dependencyFile = getFile(DEPENDENCY_FILE);
$dependencies = $dependencyFile[$payload['name']]['containers'];
$dependencies = is_array($dependencies) ? $dependencies : [];

if ($dependencies) {
$return[] = 'restarting dependenices...';

foreach ($dependencies as $dependency) {
$stopContainer = $docker->stopContainer($dependency);
$return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES);
}
}
}

return $payload['dependencies'] ? $return : $stopContainer;
case 'file-dependency':
case 'file-pull':
case 'file-sse':
Expand Down

0 comments on commit c3d22c8

Please sign in to comment.