/** * Prints 'OK' or 'FAILURE' footer. * * @param Result $result */ protected function printFooter(Result $result) { if (count($result->getBackups()) === 0) { $this->writeWithColor('fg-black, bg-yellow', 'No backups executed!'); } elseif ($result->allOk()) { $this->writeWithColor('fg-black, bg-green', sprintf('OK (%d %s, %d %s, %d %s, %d %s, %d %s)' . PHP_EOL, count($result->getBackups()), Util\Str::appendPluralS('backup', count($result->getBackups())), $this->numChecks, Util\Str::appendPluralS('check', $this->numChecks), $this->numCrypts, Util\Str::appendPluralS('crypt', $this->numCrypts), $this->numSyncs, Util\Str::appendPluralS('sync', $this->numSyncs), $this->numCleanups, Util\Str::appendPluralS('cleanup', $this->numCleanups))); } elseif ($result->backupOkButSkipsOrFails()) { $this->writeWithColor('fg-black, bg-yellow', sprintf("OK, but skipped|failed Crypts, Syncs or Cleanups!\n" . 'Backups: %d, Crypts: %d|%d, Syncs: %d|%d, Cleanups: %d|%d.' . PHP_EOL, count($result->getBackups()), $result->cryptsSkippedCount(), $result->cryptsFailedCount(), $result->syncsSkippedCount(), $result->syncsFailedCount(), $result->cleanupsSkippedCount(), $result->cleanupsFailedCount())); } else { $this->writeWithColor('fg-white, bg-red', sprintf("FAILURE!\n" . 'Backups: %d, failed Checks: %d, failed Crypts: %d, failed Syncs: %d, failed Cleanups: %d.' . PHP_EOL, count($result->getBackups()), $result->checksFailedCount(), $result->cryptsFailedCount(), $result->syncsFailedCount(), $result->cleanupsFailedCount())); } }
/** * Return backup html information. * * @param \phpbu\App\Result $result * @return string */ protected function getInfoHtml(Result $result) { $html = ''; $backups = $result->getBackups(); if (count($backups)) { $html .= '<table ' . TPL::getSnippet('sTableBackup') . '>'; /** @var \phpbu\App\Result\Backup $backup */ foreach ($backups as $backup) { if ($backup->allOk()) { $color = TPL::getSnippet('cStatusOK'); $status = 'OK'; } elseif ($backup->okButSkipsOrFails()) { $color = TPL::getSnippet('cStatusWARN'); $status = 'WARNING'; } else { $color = TPL::getSnippet('cStatusFAIL'); $status = 'FAILURE'; } $html .= '<tr>' . '<td ' . sprintf(TPL::getSnippet('sTableBackupStatusColumn'), $color) . ' colspan="4">' . sprintf('backup <em>%s</em>', $backup->getName()) . ' <span ' . TPL::getSnippet('sTableBackupStatusText') . '>' . $status . '</span>' . '</td>' . '</tr>' . '<tr>' . '<td ' . TPL::getSnippet('sRowHead') . '> </td>' . '<td ' . TPL::getSnippet('sRowHead') . ' align="right">executed</td>' . '<td ' . TPL::getSnippet('sRowHead') . ' align="right">skipped</td>' . '<td ' . TPL::getSnippet('sRowHead') . ' align="right">failed</td>' . '</tr>'; $html .= '<tr>' . '<td ' . TPL::getSnippet('sRowCheck') . '>checks</td>' . '<td ' . TPL::getSnippet('sRowCheck') . ' align="right">' . $backup->checkCount() . ' </td>' . '<td ' . TPL::getSnippet('sRowCheck') . ' align="right"> </td>' . '<td ' . TPL::getSnippet('sRowCheck') . ' align="right">' . $backup->checkCountFailed() . '</td>' . '</tr>' . '<tr>' . '<td ' . TPL::getSnippet('sRowCrypt') . '>crypts</td>' . '<td ' . TPL::getSnippet('sRowCrypt') . ' align="right">' . $backup->cryptCount() . '</td>' . '<td ' . TPL::getSnippet('sRowCrypt') . ' align="right">' . $backup->cryptCountSkipped() . '</td>' . '<td ' . TPL::getSnippet('sRowCrypt') . ' align="right">' . $backup->cryptCountFailed() . '</td>' . '</tr>' . '<tr>' . '<td ' . TPL::getSnippet('sRowSync') . '>syncs</td>' . '<td ' . TPL::getSnippet('sRowSync') . ' align="right">' . $backup->syncCount() . '</td>' . '<td ' . TPL::getSnippet('sRowSync') . ' align="right">' . $backup->syncCountSkipped() . '</td>' . '<td ' . TPL::getSnippet('sRowSync') . ' align="right">' . $backup->syncCountFailed() . '</td>' . '</tr>' . '<tr>' . '<td ' . TPL::getSnippet('sRowCleanup') . '>cleanups</td>' . '<td ' . TPL::getSnippet('sRowCleanup') . ' align="right">' . $backup->cleanupCount() . '</td>' . '<td ' . TPL::getSnippet('sRowCleanup') . ' align="right">' . $backup->cleanupCountSkipped() . '</td>' . '<td ' . TPL::getSnippet('sRowCleanup') . ' align="right">' . $backup->cleanupCountFailed() . '</td>' . '</tr>'; } $html .= '</table>'; } return $html; }
/** * Return backup information. * * @param \phpbu\App\Result $result * @return array */ protected function extractBackups(Result $result) { $output = []; $backups = $result->getBackups(); if (count($backups) > 0) { /** @var \phpbu\App\Result\Backup $backup */ foreach ($backups as $backup) { $output[] = ['name' => $backup->getName(), 'status' => $backup->wasSuccessful() ? 0 : 1, 'checks' => ['executed' => $backup->checkCount(), 'failed' => $backup->checkCountFailed()], 'crypt' => ['executed' => $backup->cryptCount(), 'skipped' => $backup->cryptCountSkipped(), 'failed' => $backup->cryptCountFailed()], 'syncs' => ['executed' => $backup->syncCount(), 'skipped' => $backup->syncCountSkipped(), 'failed' => $backup->syncCountFailed()], 'cleanups' => ['executed' => $backup->cleanupCount(), 'skipped' => $backup->cleanupCountSkipped(), 'failed' => $backup->cleanupCountFailed()]]; } } return $output; }
/** * Tests Check failed. */ public function testBackupFailedOnFailedCheck() { $conf = new Configuration('/tmp/foo.xml'); $backup = new Configuration\Backup('test-backup', false); $check = new Configuration\Backup\Check('sizemin', '10M'); $result = new Result(); $result->phpbuStart($conf); $result->backupStart($backup); $result->backupEnd($backup); $result->checkStart($check); $result->addError(new Exception('failed')); $result->checkFailed($check); $result->backupFailed($backup); $result->backupEnd($backup); $result->phpbuEnd(); $this->assertFalse($result->wasSuccessful(), 'should be successful'); $this->assertFalse($result->allOk(), 'should be ok'); $this->assertEquals(1, $result->backupsFailedCount()); $this->assertEquals(1, $result->checksFailedCount()); $this->assertEquals(1, $result->errorCount()); $this->assertEquals(1, count($result->getErrors())); $this->assertEquals(1, count($result->getBackups())); }