/** * Test create config. */ public function testCreateConfig() { $config = Factory::createConfig(); $this->assertInstanceOf(Config::class, $config); $this->assertEquals('slicer/slicer', $config->getAppName()); $this->assertEquals(clean_slicer_path(__DIR__ . '/../../../'), $config->getBaseDir()); }
/** * Get the path to the base of the install. * * @param string $path * * @return string */ function base_path($path = '') { $dir = isset($_SERVER['PWD']) ? $_SERVER['PWD'] : __DIR__ . '/../'; if (!file_exists(clean_slicer_path($dir . '/slicer.json')) && !file_exists(clean_slicer_path($dir . 'slicer/tmp'))) { echo PHP_EOL . PHP_EOL . 'Unable to find slicer.json file in current directory' . PHP_EOL . 'Place a slicer.json file in this directory if you want this to be the base directory for this application.' . PHP_EOL . PHP_EOL; exit(1); } $path = strtr(str_replace(['phar://', 'update.phar'], '', $dir) . ($path ? DIRECTORY_SEPARATOR . $path : $path), '\\', '/'); $path = strtoupper(substr($path, 0, 1)) . substr($path, 1); return clean_slicer_path($path); }
/** * Execute backup command. * * @param InputInterface $input * @param OutputInterface $output * * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $this->backupManager = $this->getApplication()->getSlicer()->getBackupManager(); $config = $this->backupManager->getConfig(); $date = new DateTime(); $dir = base_path($config->getStorage()['backup-dir']); $type = $config->getBackup()['file-type']; if ($input->hasOption('type') && '' !== trim($input->getOption('type'))) { $type = $input->getOption('type'); if (!in_array($type, ['daily', 'unique', 'single'])) { $output->writeln('<error>Unknown type ' . $type . '. Using \'single\' by default.</error>'); } } switch ($type) { case 'daily': $fileName = clean_slicer_path($dir . '/backup-' . $date->format('Ymd') . '.zip'); break; case 'unique': $fileName = clean_slicer_path($dir . '/backup-' . $date->format('Ymdhms') . '.zip'); break; case 'single': default: $fileName = clean_slicer_path($dir . '/backup.zip'); break; } $baseDir = base_path(); if ($input->hasOption('working-dir') && '' !== trim($input->getOption('working-dir'))) { $baseDir = $input->getOption('working-dir'); if (!file_exists($baseDir)) { if (file_exists(base_path($baseDir))) { $baseDir = base_path($baseDir); } else { $output->writeln('Working Directory "' . $baseDir . '" not found'); return 1; } } } $status = $this->backupManager->backup(['backup-file' => $fileName, 'backup-type' => $input->hasOption('full') ? 'full' : 'restore', 'base-dir' => $baseDir, 'output' => ['debug' => $input->getOption('debug'), 'quiet' => TRUE === $input->getOption('debug') ? FALSE : TRUE, 'verbose' => $input->getOption('verbose')]]); if ($status instanceof Exception) { $output->writeln('<error>' . $status->getMessage() . '</error>'); $status = 0; } $status = 1 === (int) $status ? 'Success' : 'Failed'; $output->writeln('Backup Status: <info>' . $status . '</info>'); }
/** * @dataProvider dataCleanSliderPaths * * @param string $expected * @param string $path */ public function testCleanSliderPath($expected, $path) { $this->assertEquals($expected, clean_slicer_path($path)); }
/** * Helper method to check for file in a directory. * * @param string $dir * @param string $file */ private function dirHasFile($dir, $file) { $this->assertTrue(file_exists(clean_slicer_path($dir . '/' . $file))); }