From 76ab63096a25f5bf7b9d076cdc9ab3fc5218d216 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Thu, 19 Jul 2018 00:27:58 +0200 Subject: bake all : skip some models and actions, via configuration --- app-from-scratch.sh | 5 ++++ .../plugins/CustomTheme/src/Shell/BakeShell.php | 29 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/app-from-scratch.sh b/app-from-scratch.sh index bbd0352..6b9ebb3 100644 --- a/app-from-scratch.sh +++ b/app-from-scratch.sh @@ -287,4 +287,9 @@ git commit -m "Add Copyright & GPL3+ notice to Templates" editor src/View/AppView.php git add ../app-from-scratch.sh src/View/AppView.php git commit -m "Date picker in DD/MM/YYYY order" +# 7de45a8e4b595856de2f0af78b13e4d2efc5e716 +# bake all : skip some models and actions, via configuration +editor plugins/CustomTheme/src/Shell/BakeShell.php +git add ../app-from-scratch.sh plugins/CustomTheme/src/Shell/BakeShell.php +git commit -m "bake all : skip some models and actions, via configuration" diff --git a/fai_gestion/plugins/CustomTheme/src/Shell/BakeShell.php b/fai_gestion/plugins/CustomTheme/src/Shell/BakeShell.php index 6734006..0e42919 100644 --- a/fai_gestion/plugins/CustomTheme/src/Shell/BakeShell.php +++ b/fai_gestion/plugins/CustomTheme/src/Shell/BakeShell.php @@ -28,14 +28,22 @@ class BakeShell extends BaseShell { /** * Assign $this->connection to the active task if a connection param is set. + * Add values to $this->Model->skipTables if config/bake_extra.php define it * * @return void */ public function startup() { parent::startup(); - } + $this->extra = include(ROOT . DS . 'config' . DS . 'bake_extra.php'); + /* Allow skipping more tables than bake' ModelTask default */ + if ( array_key_exists('skipTables', $this->extra) ) { + $skipTables = $this->extra['skipTables']; + array_walk($skipTables, 'Cake\Utility\Inflector::tableize'); + $this->Model->skipTables = array_merge($this->Model->skipTables, $skipTables); + } + } /** * Quickly bake the MVC * @@ -44,7 +52,7 @@ class BakeShell extends BaseShell { */ public function all($name = null) { - $this->out('Bake All'); + $this->out('CustomTheme Bake All'); $this->hr(); if (!empty($this->params['connection'])) { @@ -73,13 +81,28 @@ class BakeShell extends BaseShell { foreach (['Model', 'Controller', 'Template'] as $task) { $filteredTables->each(function ($tableName) use ($task) { $tableName = $this->_camelize($tableName); + + /* Allow feedding some parameters to each *Task run */ + if ( array_key_exists('taskParams', $this->extra) ){ + $extra = $this->extra['taskParams']; + /* Cake\Console\Shell __get($name) for lazy building of tasks do: + * $this->{$task}->params =& $this->params; + * We want different params at each use of tasks, so reset it + */ + $task_params = $this->params; + if ( array_key_exists('default', $extra) ) + $task_params = array_merge($task_params, $extra['default']); + if ( array_key_exists($tableName, $extra) ) + $task_params = array_merge($task_params, $extra[$tableName]); + $this->{$task}->params = $task_params; + } $this->{$task}->connection = $this->connection; $this->{$task}->interactive = $this->interactive; $this->{$task}->main($tableName); }); } - $this->out('Bake All complete.', 1, Shell::QUIET); + $this->out('CustomTheme Bake All complete.', 1, Shell::QUIET); return true; } -- cgit v1.1