various code improvements (#1415)

This commit is contained in:
Kevin Papst
2020-01-28 21:57:34 +01:00
committed by GitHub
parent 79c4c237fa
commit a1b554b3ac
16 changed files with 103 additions and 76 deletions

View File

@@ -48,7 +48,7 @@ class CreateReleaseCommand extends Command
->setName('kimai:create-release')
->setDescription('Create a pre-installed release package')
->setHelp('This command will create a release package with pre-installed composer, SQLite database and user.')
->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'Directory where the release package will be stored', 'var/data/')
->addOption('directory', null, InputOption::VALUE_OPTIONAL, 'Directory where the release package will be stored', '/tmp/')
->addOption('release', null, InputOption::VALUE_OPTIONAL, 'The version that should be zipped', Constants::VERSION)
;

View File

@@ -99,11 +99,13 @@ final class UpdateCommand extends Command
$command = $this->getApplication()->find('doctrine:migrations:migrate');
$cmdInput = new ArrayInput(['--allow-no-migration' => true]);
$cmdInput->setInteractive(false);
$command->run($cmdInput, $output);
if (0 !== $command->run($cmdInput, $output)) {
throw new \RuntimeException('CRITICAL: problem when migrating database');
}
$io->writeln('');
} catch (\Exception $ex) {
$io->error('Failed to set migration status: ' . $ex->getMessage());
$io->error($ex->getMessage());
return self::ERROR_MIGRATIONS;
}
@@ -111,12 +113,19 @@ final class UpdateCommand extends Command
// flush the cache, in case values from the database are cached
$cacheResult = $this->rebuildCaches($environment, $io, $input, $output);
$io->success(
sprintf('Congratulations! Successfully updated %s to version %s (%s)', Constants::SOFTWARE, Constants::VERSION, Constants::STATUS)
);
if ($cacheResult !== 0) {
$io->warning('Problem resetting cache, please execute cache clean manually');
$io->warning(
[
sprintf('Updated %s to version %s (%s) but the cache could not be rebuilt.', Constants::SOFTWARE, Constants::VERSION, Constants::STATUS),
'Please run the cache commands manually:',
'bin/console cache:clear --env=' . $environment . PHP_EOL .
'bin/console cache:warmup --env=' . $environment
]
);
} else {
$io->success(
sprintf('Congratulations! Successfully updated %s to version %s (%s)', Constants::SOFTWARE, Constants::VERSION, Constants::STATUS)
);
}
return 0;
@@ -128,18 +137,22 @@ final class UpdateCommand extends Command
$command = $this->getApplication()->find('cache:clear');
try {
$command->run(new ArrayInput(['--env' => $environment]), $output);
if (0 !== $command->run(new ArrayInput(['--env' => $environment]), $output)) {
throw new \RuntimeException('Could not clear cache, missing permissions?');
}
} catch (\Exception $ex) {
$io->error('Failed to clear cache: ' . $ex->getMessage());
$io->error($ex->getMessage());
return self::ERROR_CACHE_CLEAN;
}
$command = $this->getApplication()->find('cache:warmup');
try {
$command->run(new ArrayInput(['--env' => $environment]), $output);
if (0 !== $command->run(new ArrayInput(['--env' => $environment]), $output)) {
throw new \RuntimeException('Could not warmup cache, missing permissions?');
}
} catch (\Exception $ex) {
$io->error('Failed to warmup cache: ' . $ex->getMessage());
$io->error($ex->getMessage());
return self::ERROR_CACHE_WARMUP;
}

View File

@@ -17,11 +17,11 @@ class Constants
/**
* The current release version
*/
public const VERSION = '1.7';
public const VERSION = '1.8';
/**
* The current release status, either "stable" or "dev"
*/
public const STATUS = 'stable';
public const STATUS = 'dev';
/**
* The software name
*/

View File

@@ -149,26 +149,41 @@ class DoctorController extends AbstractController
try {
$logfile = $this->getLogFilename();
} catch (\Exception $ex) {
return [
$ex->getMessage()
];
return ['ATTENTION: ' . $ex->getMessage()];
}
if (!file_exists($logfile)) {
return [
'Empty or missing logfile'
];
return ['ATTENTION: Missing logfile'];
}
if (!is_readable($logfile)) {
return ['ATTENTION: Cannot read log file'];
}
$file = new \SplFileObject($logfile, 'r');
if ($file->getSize() === 0) {
return ['Empty log'];
}
$file->seek($file->getSize());
$last_line = $file->key();
while ($last_line - $lines < 0) {
$lines--;
}
$lines = new \LimitIterator($file, $last_line - $lines, $last_line);
$iterator = new \LimitIterator($file, $last_line - $lines, $last_line);
return iterator_to_array($lines);
$result = [];
if ($iterator->valid()) {
$result = iterator_to_array($iterator);
}
if (!is_writable($logfile)) {
$result[] = 'ATTENTION: Cannot write log file';
}
return $result;
}
private function getFilePermissions()