From a921f81853f734362d4c67e79045dd08eb943ea5 Mon Sep 17 00:00:00 2001 From: David Yell Date: Tue, 25 Jun 2019 11:51:53 +0100 Subject: [PATCH] Fixed the deprecations and bumped the minimum cakephp version --- composer.json | 4 +- src/Template/Bake/Element/Controller/add.ctp | 2 +- src/Template/Bake/Element/Controller/edit.ctp | 2 +- src/Template/Bake/Element/form.ctp | 6 +- src/Template/Bake/Model/table.ctp | 172 ------------------ src/Template/Bake/Template/index.ctp | 16 +- src/Template/Bake/Template/view.ctp | 4 +- 7 files changed, 17 insertions(+), 189 deletions(-) delete mode 100644 src/Template/Bake/Model/table.ctp diff --git a/composer.json b/composer.json index 22d6128..aed6e05 100644 --- a/composer.json +++ b/composer.json @@ -13,8 +13,8 @@ } ], "require": { - "php": ">=5.6", - "cakephp/cakephp": "^3.4", + "php": ">=7.0", + "cakephp/cakephp": "^3.7", "friendsofcake/bootstrap-ui": "~1.0" }, "suggest": { diff --git a/src/Template/Bake/Element/Controller/add.ctp b/src/Template/Bake/Element/Controller/add.ctp index 082e494..a8360d9 100644 --- a/src/Template/Bake/Element/Controller/add.ctp +++ b/src/Template/Bake/Element/Controller/add.ctp @@ -11,7 +11,7 @@ $compact = ["'" . $singularName . "'"]; { $<%= $singularName %> = $this-><%= $currentModelName %>->newEntity(); if ($this->request->is('post')) { - $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->request->data); + $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->getRequest()->getData()); if ($this-><%= $currentModelName; %>->save($<%= $singularName %>)) { $this->Flash->success(__('The <%= strtolower($singularHumanName) %> has been saved.')); diff --git a/src/Template/Bake/Element/Controller/edit.ctp b/src/Template/Bake/Element/Controller/edit.ctp index 41c965b..1d99db0 100644 --- a/src/Template/Bake/Element/Controller/edit.ctp +++ b/src/Template/Bake/Element/Controller/edit.ctp @@ -28,7 +28,7 @@ $compact = ["'" . $singularName . "'"]; ]); if ($this->request->is(['patch', 'post', 'put'])) { - $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->request->getData()); + $<%= $singularName %> = $this-><%= $currentModelName %>->patchEntity($<%= $singularName %>, $this->getRequest()->getData()); if ($this-><%= $currentModelName; %>->save($<%= $singularName %>)) { $this->Flash->success(__('The <%= strtolower($singularHumanName) %> has been saved.')); diff --git a/src/Template/Bake/Element/form.ctp b/src/Template/Bake/Element/form.ctp index b28280d..ef8f0a8 100644 --- a/src/Template/Bake/Element/form.ctp +++ b/src/Template/Bake/Element/form.ctp @@ -3,7 +3,7 @@ use Cake\Utility\Inflector; $fields = collection($fields) ->filter(function($field) use ($schema) { - return $schema->columnType($field) !== 'binary'; + return $schema->getColumnType($field) !== 'binary'; }); %>
@@ -17,7 +17,7 @@ $fields = collection($fields) continue; } if (isset($keyFields[$field])) { - $fieldData = $schema->column($field); + $fieldData = $schema->getColumn($field); if (!empty($fieldData['null'])) { %> echo $this->Form->control('<%= $field %>', ['options' => $<%= $keyFields[$field] %>, 'empty' => true]); @@ -30,7 +30,7 @@ $fields = collection($fields) continue; } if (!in_array($field, ['created', 'modified', 'updated'])) { - $fieldData = $schema->column($field); + $fieldData = $schema->getColumn($field); if (($fieldData['type'] === 'date') && (!empty($fieldData['null']))) { %> echo $this->Form->control('<%= $field %>', ['empty' => true, 'default' => '']); diff --git a/src/Template/Bake/Model/table.ctp b/src/Template/Bake/Model/table.ctp deleted file mode 100644 index 48eb54e..0000000 --- a/src/Template/Bake/Model/table.ctp +++ /dev/null @@ -1,172 +0,0 @@ -<% -use Cake\Utility\Inflector; -%> -\Model\Table; - -<% -$uses = [ - "use $namespace\\Model\\Entity\\$entity;", - 'use Cake\ORM\Query;', - 'use Cake\ORM\RulesChecker;', - 'use Cake\ORM\Table;', - 'use Cake\Validation\Validator;' -]; -sort($uses); -echo implode("\n", $uses); -%> - - -/** - * <%= $name %> Model -<% if ($associations): %> - * -<% foreach ($associations as $type => $assocs): %> -<% foreach ($assocs as $assoc): %> - * @property \Cake\ORM\Association\<%= Inflector::camelize($type) %> $<%= $assoc['alias'] %> -<% endforeach %> -<% endforeach; %> -<% endif; %> - */ -class <%= $name %>Table extends Table -{ - - /** - * Initialize method - * - * @param array $config The configuration for the Table. - * - * @return void - */ - public function initialize(array $config) - { -<% if (!empty($table)): %> - $this->setTable('<%= $table %>'); -<% endif %> -<% if (!empty($displayField)): %> - $this->setDisplayField('<%= $displayField %>'); -<% endif %> -<% if (!empty($primaryKey)): %> -<% if (count($primaryKey) > 1): %> - $this->setPrimaryKey([<%= $this->Bake->stringifyList((array)$primaryKey, ['indent' => false]) %>]); -<% else: %> - $this->setPrimaryKey('<%= current((array)$primaryKey) %>'); -<% endif %> -<% endif %> - -<% foreach ($behaviors as $behavior => $behaviorData): %> - $this->addBehavior('<%= $behavior %>'<%= $behaviorData ? ", [" . implode(', ', $behaviorData) . ']' : '' %>); -<% endforeach %> - -<% foreach ($associations as $type => $assocs): %> -<% foreach ($assocs as $assoc): - $alias = $assoc['alias']; - unset($assoc['alias']); -%> - $this-><%= $type %>('<%= $alias %>', [<%= $this->Bake->stringifyList($assoc, ['indent' => 3]) %>]); -<% endforeach %> -<% endforeach %> - } -<% if (!empty($validation)): %> - - /** - * Default validation rules. - * - * @param \Cake\Validation\Validator $validator Validator instance. - * - * @return \Cake\Validation\Validator - */ - public function validationDefault(Validator $validator) - { - $validator -<% $validationMethods = []; %> -<% -$firstField = true; -foreach ($validation as $field => $rules): - if ($firstField !== true): - $validationMethods[] = "\n \$validator"; - endif; - - foreach ($rules as $ruleName => $rule): - if ($rule['rule'] && !isset($rule['provider'])): - $validationMethods[] = sprintf( - "->add('%s', '%s', ['rule' => '%s'])", - $field, - $ruleName, - $rule['rule'] - ); - elseif ($rule['rule'] && isset($rule['provider'])): - $validationMethods[] = sprintf( - "->add('%s', '%s', ['rule' => '%s', 'provider' => '%s'])", - $field, - $ruleName, - $rule['rule'], - $rule['provider'] - ); - endif; - - if (isset($rule['allowEmpty'])): - if (is_string($rule['allowEmpty'])): - $validationMethods[] = sprintf( - "->allowEmpty('%s', '%s')", - $field, - $rule['allowEmpty'] - ); - elseif ($rule['allowEmpty']): - $validationMethods[] = sprintf( - "->allowEmpty('%s')", - $field - ); - else: - $validationMethods[] = sprintf( - "->requirePresence('%s', 'create')", - $field - ); - $validationMethods[] = sprintf( - "->notBlank('%s')", - $field - ); - endif; - endif; - endforeach; - $firstField = false; - $validationMethods[] = array_pop($validationMethods) . ";"; -endforeach; -%> -<%= " " . implode("\n ", $validationMethods) %> - - - return $validator; - } -<% endif %> -<% if (!empty($rulesChecker)): %> - - /** - * Returns a rules checker object that will be used for validating - * application integrity. - * - * @param \Cake\ORM\RulesChecker $rules The rules object to be modified. - * - * @return \Cake\ORM\RulesChecker - */ - public function buildRules(RulesChecker $rules) - { - <%- foreach ($rulesChecker as $field => $rule): %> - $rules->add($rules-><%= $rule['name'] %>(['<%= $field %>']<%= !empty($rule['extra']) ? ", '$rule[extra]'" : '' %>)); - <%- endforeach; %> - return $rules; - } -<% endif; %> -<% if ($connection != 'default'): %> - - /** - * Returns the database connection name to use by default. - * - * @return string - */ - public static function defaultConnectionName() - { - return '<%= $connection %>'; - } -<% endif; %> -} diff --git a/src/Template/Bake/Template/index.ctp b/src/Template/Bake/Template/index.ctp index 1542b53..ecf8d21 100644 --- a/src/Template/Bake/Template/index.ctp +++ b/src/Template/Bake/Template/index.ctp @@ -3,11 +3,11 @@ use Cake\Utility\Inflector; $fields = collection($fields) ->filter(function($field) use ($schema) { - return !in_array($schema->columnType($field), ['binary', 'text']); + return !in_array($schema->getColumnType($field), ['binary', 'text']); }) ->take(7); %> -

request->controller?>

+

getRequest()->getParam('controller')?>

Html->link(' Add new', ['action' => 'add'], ['class' => 'btn btn-primary', 'escape' => false]);?> @@ -29,11 +29,11 @@ $fields = collection($fields) <% foreach ($fields as $field): $class = ''; - if (in_array($schema->columnType($field), ['integer', 'biginteger', 'decimal', 'float'])) { + if (in_array($schema->getColumnType($field), ['integer', 'biginteger', 'decimal', 'float'])) { $class = ' class="number"'; - } elseif (in_array($schema->columnType($field), ['date', 'datetime', 'timestamp', 'time'])) { + } elseif (in_array($schema->getColumnType($field), ['date', 'datetime', 'timestamp', 'time'])) { $class = ' class="time"'; - } elseif (in_array($schema->columnType($field), ['boolean'])) { + } elseif (in_array($schema->getColumnType($field), ['boolean'])) { $class = ' class="boolean"'; } %> @@ -61,15 +61,15 @@ $fields = collection($fields) } } if ($isKey !== true) { - if (in_array($schema->columnType($field), ['integer', 'biginteger', 'decimal', 'float'])) { + if (in_array($schema->getColumnType($field), ['integer', 'biginteger', 'decimal', 'float'])) { %> Number->format($<%= $singularVar %>->get('<%= $field %>')) ?> <% - } elseif (in_array($schema->columnType($field), ['date', 'datetime', 'timestamp', 'time'])) { + } elseif (in_array($schema->getColumnType($field), ['date', 'datetime', 'timestamp', 'time'])) { %> Time->timeAgoInWords($<%= $singularVar %>->get('<%= $field %>')) ?> <% - } elseif (in_array($schema->columnType($field), ['boolean'])) { + } elseif (in_array($schema->getColumnType($field), ['boolean'])) { %> ->get('<%= $field %>')) { diff --git a/src/Template/Bake/Template/view.ctp b/src/Template/Bake/Template/view.ctp index 99697a6..0a7b455 100644 --- a/src/Template/Bake/Template/view.ctp +++ b/src/Template/Bake/Template/view.ctp @@ -18,10 +18,10 @@ $associationFields = collection($fields) $groupedFields = collection($fields) ->filter(function($field) use ($schema) { - return $schema->columnType($field) !== 'binary'; + return $schema->getColumnType($field) !== 'binary'; }) ->groupBy(function($field) use ($schema, $associationFields) { - $type = $schema->columnType($field); + $type = $schema->getColumnType($field); if (isset($associationFields[$field])) { return 'string'; }