Skip to content

Commit

Permalink
don't start spacedeck on cleanup job/command, just throw an error. ki…
Browse files Browse the repository at this point in the history
…ll spacedeck and update config if index.php presence does not match config

Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Feb 10, 2021
1 parent 5c1a9ee commit 3a2f01b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Service/SpacedeckAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,18 @@ public function getSpaceList(string $baseUrl, string $apiToken, bool $usesIndexD
* Delete storage data that is not used anymore:
* - everything related to spaces that have no corresponding file
* - data of artifacts that don't exist anymore
* This should be done by spacedeck...
* This should be done by spacedeck...but it's not ATM
*
* @param string $baseUrl
* @param string $apiToken
* @return array with status and errors
*/
public function cleanupSpacedeckStorage(string $baseUrl, string $apiToken): array {
$spaces = $this->getSpaceList($baseUrl, $apiToken, true);
// we don't try to launch spacedeck here because urlGenerator->getBaseUrl()
// gives a bad result (path is missing) in a job/command context
$spaces = $this->apiRequest($baseUrl, $apiToken, 'spaces');
if (isset($spaces['error'])) {
return $spaces;
return ['error' => 'Spacedeck is unreachable, it might not be running. ' . $spaces['error']];
}
$actions = [];
// get all whiteboard file IDs
Expand Down
20 changes: 20 additions & 0 deletions lib/Service/SpacedeckBundleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ private function killOneSpacedeck(int $pid): bool {
*/
public function launchSpacedeck(bool $usesIndexDotPhp): ?int {
$pid = $this->spacedeckIsRunning();
$indexDotPhpMismastch = ($usesIndexDotPhp !== $this->configUsesIndexDotPhp());
// if it's running but config base URL is incorrect, kill it
if ($pid && $indexDotPhpMismastch) {
$this->killSpacedeck();
$pid = 0;
}
if (!$pid) {
$this->setBaseUrl($usesIndexDotPhp);
$binaryDirPath = $this->appDataDirPath;
Expand Down Expand Up @@ -225,6 +231,20 @@ public function copySpacedeckData(): void {
}
}

/**
* Check if congif base URL value contains index.php
*
* @return bool
*/
private function configUsesIndexDotPhp(): bool {
$configPath = $this->appDataDirPath . '/config/default.json';
if (file_exists($configPath)) {
$config = json_decode(file_get_contents($configPath), true);
return preg_match('/index\.php\/apps\/integration_whiteboard/', $config['endpoint']) === 1;
}
return false;
}

/**
* Add or remove index.php to spacedeck config baseUrl
*/
Expand Down

0 comments on commit 3a2f01b

Please sign in to comment.