Skip to content

Commit 4fdb462

Browse files
Merge pull request #4 from wysiwyg-software-design/bugfix/handle-empty-backup-files
display an error, if a backup archive file wasn't created
2 parents a793358 + bc85999 commit 4fdb462

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

Classes/Command/BackupCommandController.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ public function createCommand(): void
2424
$this->quit();
2525
}
2626

27-
$this->output('Creating backup...');
28-
$this->backupService->createBackup();
29-
$this->outputLine('<success>success</success>');
27+
$this->outputLine('Creating backup...');
28+
29+
if (!$this->backupService->createBackup()) {
30+
$this->outputLine('<error>couldn\'t create backup</error>');
31+
$this->quit();
32+
}
33+
34+
$this->outputLine('<success>backup created</success>');
3035
}
3136

3237
/**

Classes/Service/BackupService.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
namespace Breadlesscode\Backups\Service;
33

44
use Breadlesscode\Backups\Compressor\BackupCompressorInterface;
5-
use Breadlesscode\Backups\BackupStep\StepInterface;
65
use Breadlesscode\Backups\Factory\FilesystemFactory;
7-
use Breadlesscode\Backups\Generators\BackupNameBackupNameGenerator;
86
use Breadlesscode\Backups\Generators\BackupNameGeneratorInterface;
7+
use Breadlesscode\Backups\Step\StepInterface;
98
use League\Flysystem\FileNotFoundException;
109
use League\Flysystem\Filesystem;
1110
use Neos\Flow\Annotations as Flow;
@@ -48,7 +47,7 @@ class BackupService
4847
protected $persistenceManager;
4948

5049
/**
51-
* @var LoggerInterface#
50+
* @var LoggerInterface
5251
*/
5352
protected $logger;
5453

@@ -126,12 +125,9 @@ public function restoreBackup(string $name)
126125
/**
127126
* @throws Exception
128127
* @throws \League\Flysystem\FileExistsException
129-
* @throws \Neos\Flow\Configuration\Exception\InvalidConfigurationTypeException
130-
* @throws \Neos\Flow\ObjectManagement\Exception\CannotBuildObjectException
131-
* @throws \Neos\Flow\ObjectManagement\Exception\UnknownObjectException
132128
* @throws \Neos\Utility\Exception\FilesException
133129
*/
134-
public function createBackup()
130+
public function createBackup(): bool
135131
{
136132
$backupName = $this->generateBackupName();
137133
$backupPath = $this->getTemporaryBackupPath($backupName);
@@ -145,16 +141,27 @@ public function createBackup()
145141
/** @var StepInterface $step */
146142
$step->backup();
147143
}
144+
148145
// create archive
149146
$compressor = $this->getCompressor();
150147
$archivePath = $compressor->compress($backupPath, $this->config['tempPath']);
148+
149+
if (!is_file($archivePath)) {
150+
$this->logger->error('couldn\`t create backup archive file: ' . $archivePath);
151+
152+
return false;
153+
}
154+
151155
// upload to file system and delete local one
152156
$this->filesystem->writeStream(basename($archivePath), fopen($archivePath, 'r'));
153157
unlink($archivePath);
154158
Files::removeDirectoryRecursively($backupPath);
159+
155160
// update index
156161
$this->indexService->addBackup($backupName, new \DateTime(), $meta);
157162
$this->logger->info('added backup '.$backupName);
163+
164+
return true;
158165
}
159166

160167
/**

0 commit comments

Comments
 (0)