mirror of
https://github.com/wintercms/winter.git
synced 2024-06-28 05:33:29 +02:00
Code tidying for console commands
Also switches theme:list, plugin:list, and mix:list to output nicely formatted tables.
This commit is contained in:
parent
5b297aeb28
commit
cd2d769402
@ -1,10 +1,10 @@
|
||||
<?php namespace Backend\Console;
|
||||
|
||||
use Str;
|
||||
use Backend\Models\User;
|
||||
use Winter\Storm\Console\Command;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Str;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to change the password of a Backend user via CLI.
|
||||
@ -25,17 +25,19 @@ class WinterPasswd extends Command
|
||||
*/
|
||||
protected $signature = 'winter:passwd
|
||||
{username? : The username or email of the Backend user. <info>(eg: admin or admin@example.com)</info>}
|
||||
{password? : The new password to set.}';
|
||||
{password? : The new password to set.}
|
||||
';
|
||||
|
||||
/**
|
||||
* @var string The console command description.
|
||||
*/
|
||||
protected $description = 'Change the password of a Backend user.';
|
||||
|
||||
|
||||
/**
|
||||
* @var array List of commands that this command replaces (aliases)
|
||||
*/
|
||||
protected $replaces = [
|
||||
'october:passwd',
|
||||
'winter:password',
|
||||
];
|
||||
|
||||
@ -44,17 +46,6 @@ class WinterPasswd extends Command
|
||||
*/
|
||||
protected $generatedPassword = false;
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Register aliases for backwards compatibility with October
|
||||
$this->setAliases(['october:passwd']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
* @return int
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php namespace Cms\Console;
|
||||
|
||||
use Winter\Storm\Scaffold\GeneratorCommand;
|
||||
use InvalidArgumentException;
|
||||
use Winter\Storm\Scaffold\GeneratorCommand;
|
||||
|
||||
class CreateTheme extends GeneratorCommand
|
||||
{
|
||||
|
@ -1,12 +1,10 @@
|
||||
<?php namespace Cms\Console;
|
||||
|
||||
use File;
|
||||
use Cms\Classes\Theme;
|
||||
use Cms\Classes\ThemeManager;
|
||||
use File;
|
||||
use System\Classes\UpdateManager;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Exception;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to install a new theme.
|
||||
@ -24,6 +22,14 @@ class ThemeInstall extends Command
|
||||
*/
|
||||
protected $name = 'theme:install';
|
||||
|
||||
/**
|
||||
* @var string The name and signature of this command.
|
||||
*/
|
||||
protected $signature = 'theme:install
|
||||
{name : The name of the theme. <info>(eg: AuthorName.ThemeName)</info>}
|
||||
{dirName? : Destination directory name for the theme installation.}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
@ -121,16 +127,4 @@ class ThemeInstall extends Command
|
||||
{
|
||||
return strtolower(str_replace('.', '-', $themeCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the theme. Eg: AuthorName.ThemeName'],
|
||||
['dirName', InputArgument::OPTIONAL, 'Destination directory name for the theme installation.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
<?php namespace Cms\Console;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Cms\Classes\Theme;
|
||||
use Cms\Classes\ThemeManager;
|
||||
use System\Classes\UpdateManager;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to list themes.
|
||||
@ -21,6 +20,13 @@ class ThemeList extends Command
|
||||
*/
|
||||
protected $name = 'theme:list';
|
||||
|
||||
/**
|
||||
* @var string The name and signature of this command.
|
||||
*/
|
||||
protected $signature = 'theme:list
|
||||
{--m|include-marketplace : Include downloadable themes from the Winter marketplace.}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*/
|
||||
@ -33,36 +39,28 @@ class ThemeList extends Command
|
||||
{
|
||||
$themeManager = ThemeManager::instance();
|
||||
$updateManager = UpdateManager::instance();
|
||||
$results = [];
|
||||
|
||||
foreach (Theme::all() as $theme) {
|
||||
$flag = $theme->isActiveTheme() ? '[*] ' : '[-] ';
|
||||
$themeId = $theme->getId();
|
||||
$themeName = $themeManager->findByDirName($themeId) ?: $themeId;
|
||||
$this->info($flag . $themeName);
|
||||
$results[] = [
|
||||
'code' => $theme->getId(),
|
||||
'is_active' => $theme->isActiveTheme() ? '<info>Yes</info>': '<fg=red>No</>',
|
||||
'is_installed' => '<info>Yes</info>',
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->option('include-marketplace')) {
|
||||
// @todo List everything in the marketplace - not just popular.
|
||||
|
||||
// @TODO List everything in the marketplace - not just popular.
|
||||
$popularThemes = $updateManager->requestPopularProducts('theme');
|
||||
|
||||
foreach ($popularThemes as $popularTheme) {
|
||||
if (!$themeManager->isInstalled($popularTheme['code'])) {
|
||||
$this->info('[ ] '.$popularTheme['code']);
|
||||
}
|
||||
$results[] = [
|
||||
'code' => $popularTheme['code'],
|
||||
'is_active' => '<fg=red>No</>',
|
||||
'is_installed' => $themeManager->isInstalled($popularTheme['code']) ? '<info>Yes</info>': '<fg=red>No</>',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->info(PHP_EOL."[*] Active [-] Installed [ ] Not installed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['include-marketplace', 'm', InputOption::VALUE_NONE, 'Include downloadable themes from the Winter marketplace.']
|
||||
];
|
||||
$this->table(['Theme', 'Active', 'Installed'], $results);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,8 @@
|
||||
|
||||
use Cms\Classes\Theme;
|
||||
use Cms\Classes\ThemeManager;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to remove a theme.
|
||||
@ -17,7 +15,6 @@ use Exception;
|
||||
*/
|
||||
class ThemeRemove extends Command
|
||||
{
|
||||
|
||||
use \Illuminate\Console\ConfirmableTrait;
|
||||
|
||||
/**
|
||||
@ -26,6 +23,14 @@ class ThemeRemove extends Command
|
||||
*/
|
||||
protected $name = 'theme:remove';
|
||||
|
||||
/**
|
||||
* @var string The name and signature of this command.
|
||||
*/
|
||||
protected $signature = 'theme:remove
|
||||
{name : The name of the theme to delete. <info>(eg: mytheme)</info>}
|
||||
{--f|force : Force the operation to run.}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
@ -57,33 +62,9 @@ class ThemeRemove extends Command
|
||||
|
||||
try {
|
||||
$themeManager->deleteTheme($themeName);
|
||||
|
||||
$this->info(sprintf('The theme %s has been deleted.', $themeName));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$this->error($ex->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the theme. (directory name)'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,9 @@
|
||||
<?php namespace Cms\Console;
|
||||
|
||||
use App;
|
||||
use Cms\Classes\Theme;
|
||||
use Event;
|
||||
use Exception;
|
||||
use Cms\Classes\Theme;
|
||||
|
||||
use Winter\Storm\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
|
||||
/**
|
||||
* Console command to sync a theme between the DB and Filesystem layers.
|
||||
@ -32,6 +28,16 @@ class ThemeSync extends Command
|
||||
*/
|
||||
protected $name = 'theme:sync';
|
||||
|
||||
/**
|
||||
* @var string The name and signature of this command.
|
||||
*/
|
||||
protected $signature = 'theme:sync
|
||||
{name? : The name of the theme (directory name). Defaults to currently active theme.}
|
||||
{--paths= : Comma-separated specific paths (relative to provided theme directory) to specificaly sync. Default is all paths. You may use regular expressions.}
|
||||
{--target= : The target of the sync, the other will be used as the source. Defaults to "filesystem", can be "database"}
|
||||
{--f|force : Force the operation to run.}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
@ -224,31 +230,5 @@ class ThemeSync extends Command
|
||||
|
||||
return $entity;
|
||||
});
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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. You may use regular expressions.'],
|
||||
['target', null, InputOption::VALUE_REQUIRED, 'The target of the sync, the other will be used as the source. Defaults to "filesystem", can be "database"'],
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
<?php namespace Cms\Console;
|
||||
|
||||
use Cms\Classes\Theme;
|
||||
use Illuminate\Console\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to switch themes.
|
||||
@ -23,6 +21,14 @@ class ThemeUse extends Command
|
||||
*/
|
||||
protected $name = 'theme:use';
|
||||
|
||||
/**
|
||||
* @var string The name and signature of this command.
|
||||
*/
|
||||
protected $signature = 'theme:use
|
||||
{name : The name of the theme. (directory name).}
|
||||
{--f|force : Force the operation to run.}
|
||||
';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
* @var string
|
||||
@ -57,26 +63,4 @@ class ThemeUse extends Command
|
||||
|
||||
Theme::setActiveTheme($newThemeName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command arguments.
|
||||
* @return array
|
||||
*/
|
||||
protected function getArguments()
|
||||
{
|
||||
return [
|
||||
['name', InputArgument::REQUIRED, 'The name of the theme. (directory name)'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the console command options.
|
||||
* @return array
|
||||
*/
|
||||
protected function getOptions()
|
||||
{
|
||||
return [
|
||||
['force', null, InputOption::VALUE_NONE, 'Force the operation to run.'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -934,6 +934,11 @@ class UpdateManager
|
||||
$this->applyHttpAttributes($http, $postData);
|
||||
});
|
||||
|
||||
// @TODO: Refactor when marketplace API finalized
|
||||
if ($result->body === 'Package not found') {
|
||||
$result->code = 500;
|
||||
}
|
||||
|
||||
if ($result->code == 404) {
|
||||
throw new ApplicationException(Lang::get('system::lang.server.response_not_found'));
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php namespace System\Console;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Str;
|
||||
use System\Console\BaseScaffoldCommand;
|
||||
use System\Classes\VersionManager;
|
||||
use System\Console\BaseScaffoldCommand;
|
||||
use Winter\Storm\Support\Str;
|
||||
use Yaml;
|
||||
|
||||
/**
|
||||
|
@ -40,21 +40,22 @@ class MixList extends Command
|
||||
|
||||
$errors = [];
|
||||
|
||||
$rows = [];
|
||||
foreach ($packages as $name => $package) {
|
||||
if ($package['ignored'] ?? false) {
|
||||
$this->warn($name);
|
||||
} else {
|
||||
$this->info($name);
|
||||
}
|
||||
|
||||
$this->line(' Path: ' . $package['path']);
|
||||
$this->line(' Configuration: ' . $package['mix']);
|
||||
$rows[] = [
|
||||
'name' => $name,
|
||||
'active' => $package['ignored'] ?? false ? '<fg=red>No</>' : '<info>Yes</info>',
|
||||
'path' => $package['path'],
|
||||
'configuration' => $package['mix'],
|
||||
];
|
||||
|
||||
if (!File::exists($package['mix'])) {
|
||||
$errors[] = "The mix file for $name doesn't exist, try running artisan mix:install";
|
||||
}
|
||||
}
|
||||
|
||||
$this->table(['Name', 'Active', 'Path', 'Configuration'], $rows);
|
||||
|
||||
$this->line('');
|
||||
|
||||
if (!empty($errors)) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
<?php namespace System\Console;
|
||||
|
||||
use Winter\Storm\Console\Command;
|
||||
use System\Models\PluginVersion;
|
||||
use Symfony\Component\Console\Helper\Table;
|
||||
use Symfony\Component\Console\Helper\TableSeparator;
|
||||
use System\Models\PluginVersion;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to list existing plugins.
|
||||
@ -42,34 +42,16 @@ class PluginList extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new Table instance.
|
||||
$table = new Table($this->output);
|
||||
|
||||
// Set the table headers.
|
||||
$table->setHeaders([
|
||||
'Plugin name', 'Version', 'Updates enabled', 'Plugin enabled'
|
||||
]);
|
||||
|
||||
// Create a new TableSeparator instance.
|
||||
$separator = new TableSeparator;
|
||||
|
||||
$pluginTable = [];
|
||||
|
||||
$row = 0;
|
||||
$rows = [];
|
||||
foreach ($allPlugins as $plugin) {
|
||||
$row++;
|
||||
|
||||
$pluginTable[] = [$plugin->code, $plugin->version, (!$plugin->is_frozen) ? 'Yes': 'No', (!$plugin->is_disabled) ? 'Yes': 'No'];
|
||||
|
||||
if ($row < $pluginsCount) {
|
||||
$pluginTable[] = $separator;
|
||||
}
|
||||
$rows[] = [
|
||||
$plugin->code,
|
||||
$plugin->version,
|
||||
(!$plugin->is_frozen) ? '<info>Yes</info>': '<fg=red>No</>',
|
||||
(!$plugin->is_disabled) ? '<info>Yes</info>': '<fg=red>No</>',
|
||||
];
|
||||
}
|
||||
|
||||
// Set the contents of the table.
|
||||
$table->setRows($pluginTable);
|
||||
|
||||
// Render the table to the output.
|
||||
$table->render();
|
||||
$this->table(['Plugin name', 'Version', 'Updates enabled', 'Plugin enabled'], $rows);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,17 @@
|
||||
<?php namespace System\Console;
|
||||
|
||||
use Db;
|
||||
use App;
|
||||
use Str;
|
||||
use PDO;
|
||||
use File;
|
||||
use Config;
|
||||
use Backend\Database\Seeds\SeedSetupAdmin;
|
||||
use Config;
|
||||
use Db;
|
||||
use Exception;
|
||||
use File;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use PDO;
|
||||
use Str;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use System\Classes\UpdateManager;
|
||||
use Winter\Storm\Config\ConfigWriter;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Encryption\Encrypter;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Exception;
|
||||
use Winter\Storm\Console\Command;
|
||||
|
||||
/**
|
||||
* Console command to install Winter.
|
||||
@ -38,6 +37,13 @@ class WinterInstall extends Command
|
||||
*/
|
||||
protected $description = 'Set up Winter for the first time.';
|
||||
|
||||
/**
|
||||
* @var array List of commands that this command replaces (aliases)
|
||||
*/
|
||||
protected $replaces = [
|
||||
'october:install',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Winter\Storm\Config\ConfigWriter
|
||||
*/
|
||||
@ -51,9 +57,6 @@ class WinterInstall extends Command
|
||||
parent::__construct();
|
||||
|
||||
$this->configWriter = new ConfigWriter;
|
||||
|
||||
// Register aliases for backwards compatibility with October
|
||||
$this->setAliases(['october:install']);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +67,7 @@ class WinterInstall extends Command
|
||||
$this->displayIntro();
|
||||
|
||||
if (
|
||||
App::hasDatabase() &&
|
||||
$this->laravel->hasDatabase() &&
|
||||
!$this->confirm('Application appears to be installed already. Continue anyway?', false)
|
||||
) {
|
||||
return;
|
||||
|
@ -1,6 +1,5 @@
|
||||
<?php namespace System\Console;
|
||||
|
||||
use App;
|
||||
use System\Classes\UpdateManager;
|
||||
|
||||
/**
|
||||
@ -15,7 +14,7 @@ use System\Classes\UpdateManager;
|
||||
* @author Ben Thomson
|
||||
* @author Winter CMS
|
||||
*/
|
||||
class WinterVersion extends \Illuminate\Console\Command
|
||||
class WinterVersion extends \Winter\Storm\Console\Command
|
||||
{
|
||||
/**
|
||||
* @var string The console command description.
|
||||
@ -26,7 +25,8 @@ class WinterVersion extends \Illuminate\Console\Command
|
||||
* @var string The name and signature of the console command.
|
||||
*/
|
||||
protected $signature = 'winter:version
|
||||
{--changes : Include the list of changes between this install and the expected files for the detected build.}';
|
||||
{--changes : Include the list of changes between this install and the expected files for the detected build.}
|
||||
';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -48,7 +48,7 @@ class WinterVersion extends \Illuminate\Console\Command
|
||||
{
|
||||
$this->comment('*** Detecting Winter CMS build...');
|
||||
|
||||
if (!App::hasDatabase()) {
|
||||
if (!$this->laravel->hasDatabase()) {
|
||||
$build = UpdateManager::instance()->getBuildNumberManually($this->option('changes'));
|
||||
|
||||
// Skip setting the build number if no database is detected to set it within
|
||||
|
Loading…
x
Reference in New Issue
Block a user