diff options
author | Marvin Borner | 2018-05-23 22:23:28 +0200 |
---|---|---|
committer | Marvin Borner | 2018-05-23 22:23:28 +0200 |
commit | b66a61addb6c8e66cb26fcf74b532d68891267e4 (patch) | |
tree | 05e9449ff25bdc98f68105f41923ccb9f6ef5095 /main/app/system/Bakery/Command | |
parent | 1d4ef435177a5f9b6d1a289800d933e49be0c550 (diff) |
Refactored code, many fixes and improvements in chat backend+frontend
Diffstat (limited to 'main/app/system/Bakery/Command')
-rw-r--r-- | main/app/system/Bakery/Command/Bake.php | 11 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/BuildAssets.php | 35 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/ClearCache.php | 18 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/Debug.php | 33 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/Migrate.php | 13 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/MigrateRefresh.php | 15 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/MigrateReset.php | 13 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/MigrateRollback.php | 15 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/Setup.php | 31 | ||||
-rw-r--r-- | main/app/system/Bakery/Command/Test.php | 11 |
10 files changed, 84 insertions, 111 deletions
diff --git a/main/app/system/Bakery/Command/Bake.php b/main/app/system/Bakery/Command/Bake.php index 5dc0e27..d12dccd 100644 --- a/main/app/system/Bakery/Command/Bake.php +++ b/main/app/system/Bakery/Command/Bake.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -42,18 +43,16 @@ class Bake extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("bake") - ->setDescription("UserFrosting installation command") - ->setHelp("This command combine the <info>debug</info>, <info>migrate</info> and <info>build-assets</info> commands."); + ->setDescription("UserFrosting installation command") + ->setHelp("This command combine the <info>debug</info>, <info>migrate</info> and <info>build-assets</info> commands."); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->writeln("<info>{$this->title}</info>"); $command = $this->getApplication()->find('setup'); diff --git a/main/app/system/Bakery/Command/BuildAssets.php b/main/app/system/Bakery/Command/BuildAssets.php index 055fa43..4a1ab99 100644 --- a/main/app/system/Bakery/Command/BuildAssets.php +++ b/main/app/system/Bakery/Command/BuildAssets.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -29,20 +30,18 @@ class BuildAssets extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("build-assets") - ->setDescription("Build the assets using node and npm") - ->setHelp("The build directory contains the scripts and configuration files required to download Javascript, CSS, and other assets used by UserFrosting. This command will install Gulp, Bower, and several other required npm packages locally. With <info>npm</info> set up with all of its required packages, it can be use it to automatically download and install the assets in the correct directories. For more info, see <comment>https://learn.userfrosting.com/basics/installation</comment>") - ->addOption("compile", "c", InputOption::VALUE_NONE, "Compile the assets and asset bundles for production environment") - ->addOption("force", "f", InputOption::VALUE_NONE, "Force assets compilation by deleting cached data and installed assets before proceeding"); + ->setDescription("Build the assets using node and npm") + ->setHelp("The build directory contains the scripts and configuration files required to download Javascript, CSS, and other assets used by UserFrosting. This command will install Gulp, Bower, and several other required npm packages locally. With <info>npm</info> set up with all of its required packages, it can be use it to automatically download and install the assets in the correct directories. For more info, see <comment>https://learn.userfrosting.com/basics/installation</comment>") + ->addOption("compile", "c", InputOption::VALUE_NONE, "Compile the assets and asset bundles for production environment") + ->addOption("force", "f", InputOption::VALUE_NONE, "Force assets compilation by deleting cached data and installed assets before proceeding"); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { // Display header, $this->io->title("UserFrosting's Assets Builder"); @@ -76,8 +75,7 @@ class BuildAssets extends BaseCommand * @access protected * @return void */ - protected function npmInstall() - { + protected function npmInstall() { $this->io->section("<info>Installing npm dependencies</info>"); $this->io->writeln("> <comment>npm install</comment>"); @@ -94,8 +92,7 @@ class BuildAssets extends BaseCommand * @access protected * @return void */ - protected function assetsInstall() - { + protected function assetsInstall() { $this->io->section("Installing assets bundles"); $this->io->writeln("> <comment>npm run uf-assets-install</comment>"); passthru("npm run uf-assets-install --prefix " . $this->buildPath); @@ -107,8 +104,7 @@ class BuildAssets extends BaseCommand * @access protected * @return void */ - protected function buildAssets() - { + protected function buildAssets() { $this->io->section("Building assets for production"); $this->io->writeln("> <comment>npm run uf-bundle-build</comment>"); @@ -127,15 +123,14 @@ class BuildAssets extends BaseCommand * @access protected * @return void */ - protected function checkAssets() - { + protected function checkAssets() { $this->io->section("Testing assets installation"); // Get path and vendor files $vendorPath = \UserFrosting\SPRINKLES_DIR . "/core/assets/vendor/*"; $coreVendorFiles = glob($vendorPath); - if (!$coreVendorFiles){ + if (!$coreVendorFiles) { $this->io->error("Assets installation seems to have failed. Directory `$vendorPath` is empty, but it shouldn't be. Check the above log for any errors."); exit(1); } @@ -156,8 +151,7 @@ class BuildAssets extends BaseCommand * @access protected * @return void */ - protected function clean() - { + protected function clean() { $this->io->section("Cleaning cached data"); $this->io->writeln("> <comment>npm run uf-clean</comment>"); passthru("npm run uf-clean --prefix " . $this->buildPath); @@ -169,8 +163,7 @@ class BuildAssets extends BaseCommand * @access protected * @return bool */ - protected function isProduction() - { + protected function isProduction() { // N.B.: Need to touch the config service first to load dotenv values $config = $this->ci->config; $mode = getenv("UF_MODE") ?: ''; diff --git a/main/app/system/Bakery/Command/ClearCache.php b/main/app/system/Bakery/Command/ClearCache.php index d38f382..4d30209 100644 --- a/main/app/system/Bakery/Command/ClearCache.php +++ b/main/app/system/Bakery/Command/ClearCache.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -24,17 +25,15 @@ class ClearCache extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("clear-cache") - ->setDescription("Clears the application cache. Includes cache service, Twig and Router cached data"); + ->setDescription("Clears the application cache. Includes cache service, Twig and Router cached data"); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("Clearing cache"); // Clear normal cache @@ -65,8 +64,7 @@ class ClearCache extends BaseCommand * @access protected * @return void */ - protected function clearIlluminateCache() - { + protected function clearIlluminateCache() { $this->ci->cache->flush(); } @@ -76,8 +74,7 @@ class ClearCache extends BaseCommand * @access protected * @return bool true/false if operation is successfull */ - protected function clearTwigCache() - { + protected function clearTwigCache() { $cacheHelper = new CacheHelper($this->ci); return $cacheHelper->clearCache(); } @@ -88,8 +85,7 @@ class ClearCache extends BaseCommand * @access protected * @return bool true/false if operation is successfull */ - protected function clearRouterCache() - { + protected function clearRouterCache() { return $this->ci->router->clearCache(); } }
\ No newline at end of file diff --git a/main/app/system/Bakery/Command/Debug.php b/main/app/system/Bakery/Command/Debug.php index 4e8a3e4..60565a4 100644 --- a/main/app/system/Bakery/Command/Debug.php +++ b/main/app/system/Bakery/Command/Debug.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -26,18 +27,16 @@ class Debug extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("debug") - ->setDescription("Test the UserFrosting installation and setup the database") - ->setHelp("This command is used to check if the various dependencies of UserFrosting are met and display useful debugging information. \nIf any error occurs, check out the online documentation for more info about that error. \nThis command also provide the necessary tools to setup the database credentials"); + ->setDescription("Test the UserFrosting installation and setup the database") + ->setHelp("This command is used to check if the various dependencies of UserFrosting are met and display useful debugging information. \nIf any error occurs, check out the online documentation for more info about that error. \nThis command also provide the necessary tools to setup the database credentials"); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { // Display header, $this->io->title("UserFrosting"); $this->io->writeln("UserFrosing version : " . \UserFrosting\VERSION); @@ -67,11 +66,10 @@ class Debug extends BaseCommand * @access public * @return void */ - protected function checkPhpVersion() - { + protected function checkPhpVersion() { $this->io->writeln("PHP Version : " . phpversion()); if (version_compare(phpversion(), \UserFrosting\PHP_MIN_VERSION, '<')) { - $this->io->error("UserFrosting requires php version ".\UserFrosting\PHP_MIN_VERSION." or above. You'll need to update you PHP version before you can continue."); + $this->io->error("UserFrosting requires php version " . \UserFrosting\PHP_MIN_VERSION . " or above. You'll need to update you PHP version before you can continue."); exit(1); } } @@ -82,8 +80,7 @@ class Debug extends BaseCommand * @access public * @return void */ - protected function checkNodeVersion() - { + protected function checkNodeVersion() { $npmVersion = trim(exec('node -v')); $this->io->writeln("Node Version : $npmVersion"); @@ -99,8 +96,7 @@ class Debug extends BaseCommand * @access public * @return void */ - protected function checkNpmVersion() - { + protected function checkNpmVersion() { $npmVersion = trim(exec('npm -v')); $this->io->writeln("NPM Version : $npmVersion"); @@ -117,12 +113,11 @@ class Debug extends BaseCommand * @access protected * @return void */ - protected function listSprinkles() - { + protected function listSprinkles() { // Check for Sprinkles schema file $path = \UserFrosting\SPRINKLES_SCHEMA_FILE; $sprinklesFile = @file_get_contents($path); - if ($sprinklesFile === false) { + if ($sprinklesFile === FALSE) { $this->io->error("The file `$path` not found."); } @@ -145,8 +140,7 @@ class Debug extends BaseCommand * @access protected * @return void */ - protected function checkDatabase() - { + protected function checkDatabase() { $this->io->section("Testing database connection..."); try { @@ -166,8 +160,7 @@ class Debug extends BaseCommand * @access protected * @return void */ - protected function showConfig() - { + protected function showConfig() { // Get config $config = $this->ci->config; diff --git a/main/app/system/Bakery/Command/Migrate.php b/main/app/system/Bakery/Command/Migrate.php index c0a5b4f..e398628 100644 --- a/main/app/system/Bakery/Command/Migrate.php +++ b/main/app/system/Bakery/Command/Migrate.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,19 +26,17 @@ class Migrate extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("migrate") - ->setDescription("Perform database migration") - ->setHelp("This command runs all the pending database migrations.") - ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); + ->setDescription("Perform database migration") + ->setHelp("This command runs all the pending database migrations.") + ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("UserFrosting's Migrator"); $pretend = $input->getOption('pretend'); diff --git a/main/app/system/Bakery/Command/MigrateRefresh.php b/main/app/system/Bakery/Command/MigrateRefresh.php index 3d18c41..eb05b61 100644 --- a/main/app/system/Bakery/Command/MigrateRefresh.php +++ b/main/app/system/Bakery/Command/MigrateRefresh.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,20 +26,18 @@ class MigrateRefresh extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("migrate:refresh") - ->setDescription("Rollback the last migration operation and run it up again") - ->addOption('steps', 's', InputOption::VALUE_REQUIRED, 'Number of steps to rollback', 1) - ->addOption('sprinkle', null, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") - ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); + ->setDescription("Rollback the last migration operation and run it up again") + ->addOption('steps', 's', InputOption::VALUE_REQUIRED, 'Number of steps to rollback', 1) + ->addOption('sprinkle', NULL, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") + ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("Migration refresh"); $step = $input->getOption('steps'); diff --git a/main/app/system/Bakery/Command/MigrateReset.php b/main/app/system/Bakery/Command/MigrateReset.php index 9e38cbb..ad66a6c 100644 --- a/main/app/system/Bakery/Command/MigrateReset.php +++ b/main/app/system/Bakery/Command/MigrateReset.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,19 +26,17 @@ class MigrateReset extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("migrate:reset") - ->setDescription("Reset the whole database to an empty state") - ->addOption('sprinkle', null, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") - ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); + ->setDescription("Reset the whole database to an empty state") + ->addOption('sprinkle', NULL, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") + ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("Migration reset"); $sprinkle = $input->getOption('sprinkle'); diff --git a/main/app/system/Bakery/Command/MigrateRollback.php b/main/app/system/Bakery/Command/MigrateRollback.php index 916f5ee..ca2302a 100644 --- a/main/app/system/Bakery/Command/MigrateRollback.php +++ b/main/app/system/Bakery/Command/MigrateRollback.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -25,20 +26,18 @@ class MigrateRollback extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("migrate:rollback") - ->setDescription("Rollback last database migration") - ->addOption('steps', 's', InputOption::VALUE_REQUIRED, 'Number of steps to rollback', 1) - ->addOption('sprinkle', null, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") - ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); + ->setDescription("Rollback last database migration") + ->addOption('steps', 's', InputOption::VALUE_REQUIRED, 'Number of steps to rollback', 1) + ->addOption('sprinkle', NULL, InputOption::VALUE_REQUIRED, 'The sprinkle to rollback', "") + ->addOption('pretend', 'p', InputOption::VALUE_NONE, 'Run migrations in "dry run" mode'); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("Migration rollback"); $step = $input->getOption('steps'); diff --git a/main/app/system/Bakery/Command/Setup.php b/main/app/system/Bakery/Command/Setup.php index b489ce2..afea37b 100644 --- a/main/app/system/Bakery/Command/Setup.php +++ b/main/app/system/Bakery/Command/Setup.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Illuminate\Database\Capsule\Manager as Capsule; @@ -25,24 +26,22 @@ class Setup extends BaseCommand /** * envfile path */ - protected $envPath = \UserFrosting\APP_DIR. '/.env'; + protected $envPath = \UserFrosting\APP_DIR . '/.env'; /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("setup") - ->setDescription("UserFrosting configuration wizard") - ->setHelp("Helper command to setup the database and email configuration. This can also be done manually by editing the <comment>app/.env</comment> file or using global server environment variables.") - ->addOption("force", "f", InputOption::VALUE_NONE, "If `.env` file exist, force setup to run again"); + ->setDescription("UserFrosting configuration wizard") + ->setHelp("Helper command to setup the database and email configuration. This can also be done manually by editing the <comment>app/.env</comment> file or using global server environment variables.") + ->addOption("force", "f", InputOption::VALUE_NONE, "If `.env` file exist, force setup to run again"); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { // Get config $config = $this->ci->config; @@ -75,8 +74,7 @@ class Setup extends BaseCommand * @access public * @return void */ - public function setupEnv() - { + public function setupEnv() { // Get config $config = $this->ci->config; @@ -112,7 +110,7 @@ class Setup extends BaseCommand // Use custom validator to accept empty password return $password; }); - + $dbParams = [ 'driver' => $driverName, 'host' => $host, @@ -133,10 +131,10 @@ class Setup extends BaseCommand $conn = $capsule->getConnection(); $conn->getPdo(); $this->io->success("Database connection successful"); - $success = true; + $success = TRUE; } catch (\PDOException $e) { - $message = "Could not connect to the database '{$dbParams['username']}@{$dbParams['host']}/{$dbParams['database']}':".PHP_EOL; - $message .= "Exception: " . $e->getMessage() . PHP_EOL.PHP_EOL; + $message = "Could not connect to the database '{$dbParams['username']}@{$dbParams['host']}/{$dbParams['database']}':" . PHP_EOL; + $message .= "Exception: " . $e->getMessage() . PHP_EOL . PHP_EOL; $message .= "Please check your database configuration and/or google the exception shown above and run the command again."; $this->io->error($message); exit(1); @@ -191,8 +189,7 @@ class Setup extends BaseCommand * @access protected * @return void */ - protected function databaseDrivers() - { + protected function databaseDrivers() { return collect([ [ "driver" => "mysql", @@ -216,7 +213,7 @@ class Setup extends BaseCommand "driver" => "sqlite", "name" => "SQLite", "defaultDBName" => \UserFrosting\DB_DIR . \UserFrosting\DS . 'userfrosting.db', - "defaultPort" => null + "defaultPort" => NULL ] ]); } diff --git a/main/app/system/Bakery/Command/Test.php b/main/app/system/Bakery/Command/Test.php index 553fddd..dde187f 100644 --- a/main/app/system/Bakery/Command/Test.php +++ b/main/app/system/Bakery/Command/Test.php @@ -5,6 +5,7 @@ * @link https://github.com/userfrosting/UserFrosting * @license https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License) */ + namespace UserFrosting\System\Bakery\Command; use Symfony\Component\Console\Input\InputInterface; @@ -29,18 +30,16 @@ class Test extends BaseCommand /** * {@inheritDoc} */ - protected function configure() - { + protected function configure() { $this->setName("test") - ->setDescription("Run tests") - ->setHelp("Run php unit tests"); + ->setDescription("Run tests") + ->setHelp("Run php unit tests"); } /** * {@inheritDoc} */ - protected function execute(InputInterface $input, OutputInterface $output) - { + protected function execute(InputInterface $input, OutputInterface $output) { $this->io->title("UserFrosting's Tester"); // Get command |