/**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     if ($this->args && $this->args[0] === 'view') {
         $this->out('<error>The view command has been renamed.</error>');
         $this->out('To create template files, please use the template command:', 2);
         $args = $this->args;
         array_shift($args);
         $args = implode($args, ' ');
         $this->out(sprintf('    <info>`bin/cake bake template %s`</info>', $args), 2);
         return false;
     }
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('Your database configuration was not found.');
         $this->out('Add your database connection information to config/app.php.');
         return false;
     }
     $this->out('The following commands can be used to generate skeleton code for your application.', 2);
     $this->out('<info>Available bake commands:</info>', 2);
     $this->out('- all');
     $names = [];
     foreach ($this->tasks as $task) {
         list(, $name) = pluginSplit($task);
         $names[] = Inflector::underscore($name);
     }
     sort($names);
     foreach ($names as $name) {
         $this->out('- ' . $name);
     }
     $this->out('');
     $this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
     return false;
 }
 /**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('Your database configuration was not found.');
         $this->out('Add your database connection information to config/app.php.');
         return false;
     }
 }
 protected function setUp()
 {
     parent::setUp();
     $configured = ConnectionManager::configured();
     if (empty($configured)) {
         ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => self::SQLITE_PATH]);
     }
     $this->Posts = TableRegistry::get('Posts');
 }
 /**
  * main() method.
  *
  * @return bool|int Success or error code.
  */
 public function install()
 {
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('Your database configuration was not found.');
         $this->out('Add your database connection information to config/app.php.');
         return false;
     }
     $this->migrate();
     $this->migrate('Users');
     $this->migrate('Permissions');
     $this->cleanup();
 }
Beispiel #5
0
 /**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('Your database configuration was not found.');
         $this->out('Add your database connection information to config/app.php.');
         return false;
     }
     $this->out('The following commands can be used to generate skeleton code for your application.', 2);
     $this->out('<info>Available bake commands:</info>', 2);
     $this->out('- all');
     foreach ($this->tasks as $task) {
         list($p, $name) = pluginSplit($task);
         $this->out('- ' . Inflector::underscore($name));
     }
     $this->out('');
     $this->out('By using <info>`cake bake [name]`</info> you can invoke a specific bake task.');
 }
Beispiel #6
0
 /**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out(__d('cake_console', 'Your database configuration was not found.'));
         $this->out(__d('cake_console', 'Add your database connection information to App/Config/app.php.'));
         return false;
     }
     $this->out(__d('cake_console', 'The following commands you can generate skeleton code your your application.'));
     $this->out('');
     $this->out(__d('cake_console', '<info>Available bake commands:</info>'));
     $this->out('');
     foreach ($this->tasks as $task) {
         list($p, $name) = pluginSplit($task);
         $this->out(Inflector::underscore($name));
     }
     $this->out('');
     $this->out(__d('cake_console', 'By using <info>Console/cake bake [name]</info> you can invoke a specific bake task.'));
 }
Beispiel #7
0
 /**
  * Initialize hook - configures logger.
  *
  * This will unfortunately build all the connections, but they
  * won't connect until used.
  *
  * @return void
  */
 public function initialize()
 {
     $configs = ConnectionManager::configured();
     foreach ($configs as $name) {
         $connection = ConnectionManager::get($name);
         if ($connection->configName() === 'debug_kit') {
             continue;
         }
         $logger = null;
         if ($connection->logQueries()) {
             $logger = $connection->logger();
         }
         if ($logger instanceof DebugLog) {
             continue;
         }
         $logger = new DebugLog($logger, $name);
         $connection->logQueries(true);
         $connection->logger($logger);
         $this->_loggers[] = $logger;
     }
 }
Beispiel #8
0
 /**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('Your database configuration was not found.');
         $this->out('Add your database connection information to config/app.php.');
         return false;
     }
     $this->out('The following commands can be used to import or export tsv file.', 2);
     $this->out('<info>Available tsvio commands:</info>', 2);
     $names = [];
     foreach ($this->tasks as $task) {
         list(, $name) = pluginSplit($task);
         $names[] = Inflector::underscore($name);
     }
     sort($names);
     foreach ($names as $name) {
         $this->out('- ' . $name);
     }
     $this->out('');
     return false;
 }
Beispiel #9
0
 /**
  * Add aliases for all non test prefixed connections.
  *
  * This allows models to use the test connections without
  * a pile of configuration work.
  *
  * @return void
  */
 protected function _aliasConnections()
 {
     $connections = ConnectionManager::configured();
     ConnectionManager::alias('test', 'default');
     $map = [];
     foreach ($connections as $connection) {
         if ($connection === 'test' || $connection === 'default') {
             continue;
         }
         if (isset($map[$connection])) {
             continue;
         }
         if (strpos($connection, 'test_') === 0) {
             $map[$connection] = substr($connection, 5);
         } else {
             $map['test_' . $connection] = $connection;
         }
     }
     foreach ($map as $alias => $connection) {
         ConnectionManager::alias($alias, $connection);
     }
 }
 /**
  * Helper method to get query log.
  *
  * @return array Query log.
  */
 protected function _getQueryLog()
 {
     $queryLog = [];
     $sources = ConnectionManager::configured();
     foreach ($sources as $source) {
         $logger = ConnectionManager::get($source)->logger();
         if (method_exists($logger, 'getLogs')) {
             $queryLog[$source] = $logger->getLogs();
         }
     }
     return $queryLog;
 }
 /**
  * Test alias() raises an error when aliasing an undefined connection.
  *
  * @expectedException \Cake\Datasource\Exception\MissingDatasourceConfigException
  * @return void
  */
 public function testAliasError()
 {
     $this->assertNotContains('test_kaboom', ConnectionManager::configured());
     ConnectionManager::alias('test_kaboom', 'other_name');
 }
 /**
  * Get a list of sources defined in database.php
  *
  * @return array
  * @codeCoverageIgnore
  */
 protected function _getSources()
 {
     return ConnectionManager::configured();
 }
Beispiel #13
0
 /**
  * Override main() to handle action
  *
  * @return mixed
  */
 public function main()
 {
     // This adds a style for console formatting. It's used in the menu to better recognize
     // the actions' letters.
     $this->_io->styles('bold', ['bold' => true, 'underline' => true]);
     // Menu
     $this->out('', 1, 0);
     $this->out('+--[ SuperBake ]------------------------------------------------+');
     $this->out('|                                           |   ___             |');
     $this->out('|                                           |   | | <success>Experiments</success> |');
     $this->out('|  This script generates plugins, models,   |  /   \\    <success>Labs</success>    |');
     $this->out('|  views and controllers for them.          | (____\')           |');
     $this->out('|                                           |                   |');
     $this->out('+---------------------------------------------------------------+', 1, 0);
     $this->out('|                                                               |', 1, 0);
     $this->out('|  <info>Welcome to the SuperBake Shell.</info>                              |', 1, 0);
     $this->out('|  <info>This Shell can be quieter if launched with the -q option.</info>    |');
     $this->out('|                                                               |', 1, 0);
     $this->out('|  <warning>Read the doc before things turns bad</warning>                         |', 1, 0);
     $this->out('|                                                               |', 1, 0);
     $this->out('+---------------------------------------------------------------+', 1, 0);
     $this->out('|', 1, 0);
     $this->out('|  <info>You currently use the ' . $this->Sbc->getTemplateName() . ' template</info>', 1, 0);
     $this->out('|', 1, 0);
     // Disabled for now as invalid for 3.0
     //		if (count($this->Sbc->getPrefixesList()) != (count(Configure::read('Routing.prefixes')) + 1)) {
     //			debug(Configure::read('Routing.prefixes'));die();
     //			$this->out('| <warning>-->The amount of routing prefixes defined in your core.php.</warning>', 1, 0);
     //			$this->out('| <warning>--> differs from the ones defined in your configuration files...</warning>', 1, 0);
     //			$this->out('|', 1, 0);
     //		}
     if ($this->Sbc->getErrors() > 0) {
         $this->out('| <warning>--> This file contains errors. Check it.</warning>', 1, 0);
         $this->out('|', 1, 0);
     }
     $connections = ConnectionManager::configured();
     if (empty($connections)) {
         $this->out('+---------------------------------------------------------------+', 1, 0);
         $this->out('| <warning>--> Your database configuration was not found.</warning>');
         $this->out('| <warning>--> Add your database connection information to config/app.php.</warning>');
         $this->out('|', 1, 0);
         return false;
     }
     $this->out('+--[ <error>' . __d('superBake', 'Plugin creation') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>P</bold>]lugins (Creates all plugins structures)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>S</bold>]pecific entire plugin (M/C/V)'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Batch generation') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>M</bold>]odels (Generates all models)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>C</bold>]ontrollers (Generates all controllers)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>V</bold>]iews (Generates all views)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>A</bold>]ll (Models, Controllers and Views)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    Risk[<bold>Y</bold>] (Models, Controllers, Views, Menus, Files and copy required.)'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Model generation') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    One plugin mo[<bold>D</bold>]els (All models for a specific plugin)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>B</bold>]ake one model'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Controller generation') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>O</bold>]ne plugin controllers (All controllers for a specific plugin)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    Bake one contro[<bold>L</bold>]ler'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'View generation') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '<info>View generation is based on the configuration file, and not</info>'));
     $this->out('|  ' . __d('superBake', '<info>from the existing controller. That means that if you have modified your</info>'));
     $this->out('|  ' . __d('superBake', '<info>controllers, the new actions will not be available.</info>'));
     $this->out('|  ' . __d('superBake', '    O[<bold>N</bold>]e plugin views (All views for a specific plugin)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    Bake a view for one [<bold>G</bold>]iven action (plugin/controller specific)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    Views fo[<bold>R</bold>] one given controller'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Menus') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    M[<bold>E</bold>]nus (Generates menus)'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Files') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>F</bold>]iles (Generates files)'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Required files') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    Required f[<bold>I</bold>]les (Copies files and dirs)'), 1, 0);
     $this->out('|', 1, 0);
     $this->out('+--[ <error>' . __d('superBake', 'Misc') . '</error> ]', 1, 0);
     $this->out('|  ' . __d('superBake', '    Config [<bold>J</bold>]anitor (Cleans and fills your config. Outputs the result)'), 1, 0);
     $this->out('|  ' . __d('superBake', '    [<bold>Q</bold>]uit'), 1, 0);
     $this->out('|', 1, 0);
     // Used letters (just for info):
     // A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
     // = = = = = = =   = =   = = = = = = = =     =     =
     $classToGenerate = strtoupper($this->in('+--> ' . __d('superBake', 'What would you like to generate ?'), ['A', 'B', 'C', 'D', 'E', 'G', 'I', 'J', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'V', 'Y']));
     switch ($classToGenerate) {
         // Plugins: -------------------------------------------------------
         case 'P':
             // Plugin structures
             $this->Plugins();
             break;
         case 'M':
             // Models
             $this->Models();
             break;
         case 'V':
             // Views
             $this->Views();
             break;
         case 'C':
             // Controllers
             $this->Controllers();
             break;
         case 'A':
             // MVC
             $this->MVC();
             break;
         case 'Y':
             // Risky
             $this->All();
             break;
         case 'S':
             // MVC of a given plugin
             $this->pluginMVC();
             break;
             // Models: --------------------------------------------------------
         // Models: --------------------------------------------------------
         case 'D':
             // one plugin Models
             $this->pluginModels();
             break;
         case 'B':
             // one specific Model
             $this->Model();
             break;
             // Controllers: ---------------------------------------------------
         // Controllers: ---------------------------------------------------
         case 'O':
             // one plugin controllers
             $this->pluginControllers();
             break;
         case 'L':
             // one specific controller
             $this->Controller();
             break;
             // Views: ---------------------------------------------------------
         // Views: ---------------------------------------------------------
         case 'N':
             // one plugin views
             $this->pluginViews();
             break;
         case 'G':
             // View for a given PluginName.ControllerName.ActionName
             $this->View();
             break;
         case 'R':
             // View for a give PluginName.ControllerName
             $this->controllerViews();
             break;
             // Menus: ---------------------------------------------------------
         // Menus: ---------------------------------------------------------
         case 'E':
             //Menus
             $this->Menus();
             break;
             // Files: ---------------------------------------------------------
         // Files: ---------------------------------------------------------
         case 'F':
             // All files
             $this->Files();
             break;
             // Required: ---------------------------------------------------------
         // Required: ---------------------------------------------------------
         case 'I':
             // All files
             $this->Required();
             break;
             // Misc: ---------------------------------------------------------
         // Misc: ---------------------------------------------------------
         case 'J':
             // Outputs a complete config.
             $this->Janitor();
             break;
         case 'Q':
             //Quit
             $this->_stop();
             break;
         default:
             $this->out(__d('superBake', '<warning>You have made an invalid selection. Please choose something to do.</warning>'), 1, 0);
     }
     $this->hr();
     //Loop
     $this->main();
 }