diff --git a/modules/system/ServiceProvider.php b/modules/system/ServiceProvider.php index fd7ec13c1..9792defd0 100644 --- a/modules/system/ServiceProvider.php +++ b/modules/system/ServiceProvider.php @@ -241,6 +241,7 @@ class ServiceProvider extends ModuleServiceProvider $this->registerConsoleCommand('theme.remove', 'System\Console\ThemeRemove'); $this->registerConsoleCommand('theme.list', 'System\Console\ThemeList'); $this->registerConsoleCommand('theme.use', 'System\Console\ThemeUse'); + $this->registerConsoleCommand('theme.sync', 'System\Console\ThemeSync'); } /* diff --git a/modules/system/console/ThemeSync.php b/modules/system/console/ThemeSync.php new file mode 100644 index 000000000..9c009ad02 --- /dev/null +++ b/modules/system/console/ThemeSync.php @@ -0,0 +1,128 @@ +error("The application is not using a database."); + } + + // Check to see if the DB layer is enabled + $enableDbLayer = Config::get('cms.enableDatabaseLayer', false); + if (is_null($enableDbLayer)) { + $enableDbLayer = !Config::get('app.debug'); + } + if (!$enableDbLayer) { + return $this->error("cms.enableDatabaseLayer is not enabled, enable it first and try again."); + } + + // Check to see if the provided theme exists + $themeManager = ThemeManager::instance(); + $themeName = $this->argument('name') ?: Theme::getActiveThemeCode(); + $themeExists = Theme::exists($themeName); + if (!$themeExists) { + $themeName = strtolower(str_replace('.', '-', $themeName)); + $themeExists = Theme::exists($themeName); + } + if (!$themeExists) { + return $this->error(sprintf('The theme %s does not exist.', $themeName)); + } + + // Get the target and source datasources + $availableSources = ['filesystem', 'database']; + $target = $this->option('target') ?: 'database'; + $source = 'filesystem'; + if ($target === 'filesystem') { + $source = 'database'; + } + if (!in_array($target, $availableSources)) { + $this->error(sprintf("Provided --target of %s is invalid. Allowed: database, filesystem"), $target); + } + + // Get the paths + $paths = $this->option('paths') ?: null; + if ($paths) { + $paths = array_map('trim', explode(',', $paths)); + } + + // Confirm with the user + if (!$this->confirmToProceed(sprintf('This will REPLACE the provided paths from "themes/%s" on the %s with content from the %s', $themeName, $target, $source), function () { return true; })) { + return; + } + + try { + // TODO: Actually implement the functionality + + $this->info(sprintf('The theme %s has been synced from the %s to the %s.', $themeName, $source, $target)); + } + catch (Exception $ex) { + $this->error($ex->getMessage()); + } + } + + /** + * Get the console command arguments. + * @return array + */ + protected function getArguments() + { + return [ + ['name', InputArgument::OPTIONAL, 'The name of the theme (directory name). Defaults to currently active theme.'], + ]; + } + + /** + * Get the console command options. + * @return array + */ + protected function getOptions() + { + return [ + ['paths', null, InputOption::VALUE_REQUIRED, 'Comma-separated specific paths (relative to provided theme directory) to specificaly sync. Default is all paths'], + ['target', null, InputOption::VALUE_REQUIRED, 'The target of the sync, the other will be used as the source. Defaults to "database", can be "filesystem"'], + ['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'], + ]; + } +}