Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Strong type properties and functions in the updater
Signed-off-by: Côme Chilliet <[email protected]>
Signed-off-by: CaCO3 <[email protected]>
  • Loading branch information
come-nc authored and CaCO3 committed Oct 26, 2023
commit 0aa2bde2d7c19ed0af31f96b43d89124331a7278
1 change: 0 additions & 1 deletion lib/RecursiveDirectoryIteratorWithoutData.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

class RecursiveDirectoryIteratorWithoutData extends \RecursiveFilterIterator {
public function accept(): bool {
/** @var \DirectoryIterator $this */
$excludes = [
'.rnd',
'.well-known',
Expand Down
40 changes: 16 additions & 24 deletions lib/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@
use Symfony\Component\Console\Question\ConfirmationQuestion;

class UpdateCommand extends Command {
/** @var Updater */
protected $updater;

/** @var bool */
protected $shouldStop = false;

/** @var bool */
protected $skipBackup = false;

protected ?Updater $updater = null;
protected bool $shouldStop = false;
protected bool $skipBackup = false;
protected bool $skipUpgrade = false;

/** @var array strings of text for stages of updater */
protected $checkTexts = [
protected array $checkTexts = [
0 => '',
1 => 'Check for expected files',
2 => 'Check for write permissions',
Expand All @@ -59,7 +53,7 @@ class UpdateCommand extends Command {
12 => 'Done',
];

protected function configure() {
protected function configure(): void {
$this
->setName('update')
->setDescription('Updates the code of an Nextcloud instance')
Expand Down Expand Up @@ -351,10 +345,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
}

/**
* @param $step integer
* @return array with options 'proceed' which is a boolean and defines if the step succeeded and an optional 'response' string
* @return array{proceed:bool,response:string|array} with options 'proceed' which is a boolean and defines if the step succeeded and an optional 'response' string or array
*/
protected function executeStep($step) {
protected function executeStep(int $step): array {
if ($this->updater === null) {
return ['proceed' => false, 'response' => 'Initialization problem'];
}
$this->updater->log('[info] executeStep request for step "' . $step . '"');
try {
if ($step > 12 || $step < 1) {
Expand Down Expand Up @@ -404,19 +400,19 @@ protected function executeStep($step) {
break;
}
$this->updater->endStep($step);
return ['proceed' => true];
return ['proceed' => true, 'response' => ''];
} catch (UpdateException $e) {
$message = $e->getData();
$data = $e->getData();

try {
$this->updater->log('[error] executeStep request failed with UpdateException');
$this->updater->logException($e);
} catch (LogException $logE) {
$message .= ' (and writing to log failed also with: ' . $logE->getMessage() . ')';
$data[] = ' (and writing to log failed also with: ' . $logE->getMessage() . ')';
}

$this->updater->rollbackChanges($step);
return ['proceed' => false, 'response' => $message];
return ['proceed' => false, 'response' => $data];
} catch (\Exception $e) {
$message = $e->getMessage();

Expand All @@ -432,11 +428,7 @@ protected function executeStep($step) {
}
}

/**
* @param OutputInterface $output
* @param integer $stepNumber
*/
protected function showCurrentStatus(OutputInterface $output, $stepNumber) {
protected function showCurrentStatus(OutputInterface $output, int $stepNumber): void {
$output->writeln('Steps that will be executed:');
for ($i = 1; $i < sizeof($this->checkTexts); $i++) {
if ($i === 11) {
Expand All @@ -456,7 +448,7 @@ protected function showCurrentStatus(OutputInterface $output, $stepNumber) {
/**
* gets called by the PCNTL listener once the stop/terminate signal
*/
public function stopCommand() {
public function stopCommand(): void {
$this->shouldStop = true;
}
}
9 changes: 4 additions & 5 deletions lib/UpdateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
namespace NC\Updater;

class UpdateException extends \Exception {
protected $data;

public function __construct($data) {
$this->data = $data;
public function __construct(
protected array $data,
) {
}

public function getData() {
public function getData(): array {
return $this->data;
}
}
Loading