From ba9981cd8285c57e7f60597d66916f01b23be807 Mon Sep 17 00:00:00 2001 From: Michal Asgraf Turek Date: Fri, 20 Apr 2018 17:13:00 +0200 Subject: [PATCH 1/6] cakephp 3.6 deprecation fixes --- src/Listener/ViewListener.php | 24 +++++++++---------- src/Listener/ViewSearchListener.php | 2 +- src/Template/Element/actions.ctp | 4 ++-- .../Element/index/bulk_actions/form_end.ctp | 2 +- src/Template/Element/search.ctp | 2 +- src/Template/Layout/default.ctp | 2 +- src/View/Widget/DateTimeWidget.php | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index abc08d42..229ab319 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -78,7 +78,7 @@ public function beforePaginate(Event $event) */ public function beforeRender(Event $event) { - if ($this->_controller()->name === 'Error') { + if ($this->_controller()->getName() === 'Error') { return; } @@ -147,7 +147,7 @@ protected function _getPageTitle() $scope = $action->getConfig('scope'); $request = $this->_request(); - $actionName = Inflector::humanize(Inflector::underscore($request->action)); + $actionName = Inflector::humanize(Inflector::underscore($request->getParam('action'))); $controllerName = $this->_controllerName(); if ($scope === 'table') { @@ -218,7 +218,7 @@ protected function _getRelatedModels($associationTypes = []) $models = []; foreach ($associations as $assoc) { - $models[] = $assoc->name(); + $models[] = $assoc->getName(); } } @@ -265,9 +265,9 @@ protected function _getPageVariables() 'modelSchema' => $table->getSchema(), 'displayField' => $table->getDisplayField(), 'singularHumanName' => Inflector::humanize(Inflector::underscore(Inflector::singularize($controller->modelClass))), - 'pluralHumanName' => Inflector::humanize(Inflector::underscore($controller->name)), - 'singularVar' => Inflector::singularize($controller->name), - 'pluralVar' => Inflector::variable($controller->name), + 'pluralHumanName' => Inflector::humanize(Inflector::underscore($controller->getName())), + 'singularVar' => Inflector::singularize($controller->getName()), + 'pluralVar' => Inflector::variable($controller->getName()), 'primaryKey' => $table->getPrimaryKey(), ]; @@ -351,7 +351,7 @@ protected function _controllerName() $inflections[] = 'singularize'; } - $baseName = $this->_controller()->name; + $baseName = $this->_controller()->getName(); foreach ($inflections as $inflection) { $baseName = Inflector::$inflection($baseName); } @@ -539,13 +539,13 @@ protected function _associations(array $whitelist = []) $associationConfiguration[$type] = []; } - $assocKey = $association->name(); + $assocKey = $association->getName(); $associationConfiguration[$type][$assocKey]['model'] = $assocKey; $associationConfiguration[$type][$assocKey]['type'] = $type; - $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->target()->getPrimaryKey(); - $associationConfiguration[$type][$assocKey]['displayField'] = $association->target()->getDisplayField(); - $associationConfiguration[$type][$assocKey]['foreignKey'] = $association->foreignKey(); - $associationConfiguration[$type][$assocKey]['propertyName'] = $association->property(); + $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->getTarget()->getPrimaryKey(); + $associationConfiguration[$type][$assocKey]['displayField'] = $association->getTarget()->getDisplayField(); + $associationConfiguration[$type][$assocKey]['foreignKey'] = $association->getForeignKey(); + $associationConfiguration[$type][$assocKey]['propertyName'] = $association->getProperty(); $associationConfiguration[$type][$assocKey]['plugin'] = pluginSplit($association->className())[0]; $associationConfiguration[$type][$assocKey]['controller'] = $assocKey; $associationConfiguration[$type][$assocKey]['entity'] = Inflector::singularize(Inflector::underscore($assocKey)); diff --git a/src/Listener/ViewSearchListener.php b/src/Listener/ViewSearchListener.php index f1444ce7..bdff204f 100644 --- a/src/Listener/ViewSearchListener.php +++ b/src/Listener/ViewSearchListener.php @@ -122,7 +122,7 @@ protected function _deriveFields() $input['value'] = $request->getQuery($field); - if (empty($input['options']) && $schema->columnType($field) === 'boolean') { + if (empty($input['options']) && $schema->getColumnType($field) === 'boolean') { $input['options'] = ['No', 'Yes']; $input['type'] = 'select'; } diff --git a/src/Template/Element/actions.ctp b/src/Template/Element/actions.ctp index 815d6205..92f6d951 100644 --- a/src/Template/Element/actions.ctp +++ b/src/Template/Element/actions.ctp @@ -3,8 +3,8 @@ $links = []; foreach ($actions as $name => $config) { $config += ['method' => 'GET']; - if ((empty($config['url']['controller']) || $this->request->controller === $config['url']['controller']) && - (!empty($config['url']['action']) && $this->request->action === $config['url']['action']) + if ((empty($config['url']['controller']) || $this->request->getParam('controller') === $config['url']['controller']) && + (!empty($config['url']['action']) && $this->request->getParam('action') === $config['url']['action']) ) { continue; } diff --git a/src/Template/Element/index/bulk_actions/form_end.ctp b/src/Template/Element/index/bulk_actions/form_end.ctp index 4cdd2035..2c47546c 100644 --- a/src/Template/Element/index/bulk_actions/form_end.ctp +++ b/src/Template/Element/index/bulk_actions/form_end.ctp @@ -8,7 +8,7 @@ $submitButton = $this->Form->button(__d('crud', 'Apply'), [ 'name' => '_bulk', ]); -echo $this->Form->input('action', [ +echo $this->Form->control('action', [ 'empty' => __d('crud', 'Bulk Actions'), 'label' => [ 'class' => 'col-sm-2 control-label', diff --git a/src/Template/Element/search.ctp b/src/Template/Element/search.ctp index b2677e4d..42fa2f2c 100644 --- a/src/Template/Element/search.ctp +++ b/src/Template/Element/search.ctp @@ -14,7 +14,7 @@ if (empty($searchInputs)) { ?>
- Form->inputs($searchInputs, ['fieldset' => false]); ?> + Form->controls($searchInputs, ['fieldset' => false]); ?> Form->button(__d('crud', 'Filter results'), ['type' => 'submit', 'class' => 'btn btn-primary']); ?>
diff --git a/src/Template/Layout/default.ctp b/src/Template/Layout/default.ctp index 4c4cccbd..bdccb581 100644 --- a/src/Template/Layout/default.ctp +++ b/src/Template/Layout/default.ctp @@ -1,5 +1,5 @@ - + Html->charset(); ?> <?= $this->get('title');?> diff --git a/src/View/Widget/DateTimeWidget.php b/src/View/Widget/DateTimeWidget.php index c8b2ec5e..7602e038 100644 --- a/src/View/Widget/DateTimeWidget.php +++ b/src/View/Widget/DateTimeWidget.php @@ -29,7 +29,7 @@ public function render(array $data, ContextInterface $context) $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : ''; $role = isset($data['role']) ? $data['role'] : 'datetime-picker'; $format = null; - $locale = isset($data['locale']) ? $data['locale'] : I18n::locale(); + $locale = isset($data['locale']) ? $data['locale'] : I18n::getLocale(); $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget'); From 84076d5ab7fb3b91004091651896f55436da4b9b Mon Sep 17 00:00:00 2001 From: ADmad Date: Fri, 20 Apr 2018 23:02:40 +0530 Subject: [PATCH 2/6] Use interface instead of concrete class in docblock --- src/View/Helper/CrudViewHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index 3868bbe0..566c228e 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -390,7 +390,7 @@ public function currentModel() /** * Get model schema. * - * @return \Cake\Database\Schema\Table + * @return \Cake\Database\Schema\TableSchemaInterface */ public function schema() { From 88f5a609839d84409bdda6eb1b0616802d836926 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 26 Apr 2018 14:01:21 +0530 Subject: [PATCH 3/6] Update deprecated method usage. --- src/View/Helper/CrudViewHelper.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/View/Helper/CrudViewHelper.php b/src/View/Helper/CrudViewHelper.php index 566c228e..3d0e577e 100644 --- a/src/View/Helper/CrudViewHelper.php +++ b/src/View/Helper/CrudViewHelper.php @@ -171,11 +171,8 @@ public function introspect($field, $value, array $options = []) public function columnType($field) { $schema = $this->schema(); - if (method_exists($schema, 'baseColumnType')) { - return $schema->baseColumnType($field); - } - return $schema->columnType($field); + return $schema->getColumnType($field); } /** From ea888d4ceb2e329e181b7d9408f7a4de3638540b Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 26 Apr 2018 14:01:56 +0530 Subject: [PATCH 4/6] Update deprecated method usage. --- src/View/Cell/TablesListCell.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View/Cell/TablesListCell.php b/src/View/Cell/TablesListCell.php index 0dbc1085..1d9a485f 100644 --- a/src/View/Cell/TablesListCell.php +++ b/src/View/Cell/TablesListCell.php @@ -19,7 +19,7 @@ public function display($tables = null, $blacklist = null) { if (empty($tables)) { $connection = ConnectionManager::get('default'); - $schema = $connection->schemaCollection(); + $schema = $connection->getSchemaCollection(); $tables = $schema->listTables(); ksort($tables); From 4f273f9f465f7f70fa37f113eb52d5c88d3cdd35 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 26 Apr 2018 14:04:32 +0530 Subject: [PATCH 5/6] Update dependency versions. --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 0f0b331a..4159d3f8 100644 --- a/composer.json +++ b/composer.json @@ -29,14 +29,14 @@ } ], "require": { - "cakephp/cakephp": "~3.4", - "friendsofcake/crud": "*", - "friendsofcake/bootstrap-ui": "~1.2" + "cakephp/cakephp": "^3.5", + "friendsofcake/crud": "^5.4", + "friendsofcake/bootstrap-ui": "^1.4" }, "require-dev": { "friendsofcake/cakephp-test-utilities": "^1.0", "markstory/asset_compress": "^3.2", - "phpunit/phpunit": "^5.7|^6.0" + "phpunit/phpunit": "^5.7.14|^6.0" }, "autoload": { "psr-4": { From 74251de72fd6f9631cb7c2c6d42e6ba0a47a817c Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 5 May 2018 17:35:31 -0400 Subject: [PATCH 6/6] fix: drop a few more deprecated method calls --- src/Listener/ViewListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Listener/ViewListener.php b/src/Listener/ViewListener.php index 229ab319..06a3c489 100644 --- a/src/Listener/ViewListener.php +++ b/src/Listener/ViewListener.php @@ -65,7 +65,7 @@ public function beforePaginate(Event $event) $this->associations = $this->_associations(array_keys($related)); } - if (!$event->getSubject()->query->contain()) { + if (!$event->getSubject()->query->getContain()) { $event->getSubject()->query->contain($this->_getRelatedModels(['manyToOne', 'oneToOne'])); } } @@ -211,7 +211,7 @@ protected function _getRelatedModels($associationTypes = []) foreach ($associationTypes as $assocType) { $associations = array_merge( $associations, - $this->_table()->associations()->type($assocType) + $this->_table()->associations()->getByType($assocType) ); } }