Skip to content

Commit

Permalink
refactor: remove duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaucau committed Dec 30, 2023
1 parent c309c05 commit 1f644e7
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/Command/LSCacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ protected function fire(): int
//Create a temporary API key to authorize a request
$apiKey = new ApiKey();
$key = $apiKey::generate()->key;
//The key is saved temporarily in the settings. The native Flarum API key is not used because it requires a user ID and in the case of the command the user is not logged in.
//The key is saved temporarily in the settings.
//The native Flarum API key is not used because it requires a user ID but in the case of the command, the user is not logged in.
$this->settings->set('acpl-lscache.purgeKey', $key);

$options = [
Expand All @@ -59,20 +60,15 @@ protected function fire(): int
//GET does not require the Flarum API key
$client->request('GET', $this->url->to('api')->route('lscache.purge'), $options);
} catch (GuzzleException $exception) {
$this->deleteKey();
$this->error('Something went wrong while sending the request.');

return 1;
} finally {
$this->settings->delete('acpl-lscache.purgeKey');
}

$this->deleteKey();
$this->info('Notified LiteSpeed Web Server to purge'.(empty($paths) ? ' all' : '').' LSCache entries');

return 0;
}

private function deleteKey(): void
{
$this->settings->delete('acpl-lscache.purgeKey');
}
}

0 comments on commit 1f644e7

Please sign in to comment.