From 2764ad730da254e2a655d5b67954657d907a4583 Mon Sep 17 00:00:00 2001 From: Tomohiro Ukawa Date: Tue, 1 May 2018 15:18:58 +0900 Subject: [PATCH 1/2] MInor: following with cake3.6 update --- src/Model/Table/SoftDeleteTrait.php | 10 +++---- src/ORM/Query.php | 6 ++-- .../Model/Table/SoftDeleteTraitTest.php | 29 ++++++++++--------- tests/bootstrap.php | 6 ++-- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/Model/Table/SoftDeleteTrait.php b/src/Model/Table/SoftDeleteTrait.php index 88a4675..f9c6bf5 100644 --- a/src/Model/Table/SoftDeleteTrait.php +++ b/src/Model/Table/SoftDeleteTrait.php @@ -22,11 +22,11 @@ public function getSoftDeleteField() $field = 'deleted'; } - if ($this->schema()->column($field) === null) { + if ($this->getSchema()->getColumn($field) === null) { throw new MissingColumnException( __('Configured field `{0}` is missing from the table `{1}`.', $field, - $this->alias() + $this->getAlias() ) ); } @@ -36,7 +36,7 @@ public function getSoftDeleteField() public function query() { - return new Query($this->connection(), $this); + return new Query($this->getConnection(), $this); } /** @@ -57,7 +57,7 @@ protected function _processDelete($entity, $options) return false; } - $primaryKey = (array)$this->primaryKey(); + $primaryKey = (array)$this->getPrimaryKey(); if (!$entity->has($primaryKey)) { $msg = 'Deleting requires all primary key values.'; throw new \InvalidArgumentException($msg); @@ -125,7 +125,7 @@ public function hardDelete(EntityInterface $entity) if(!$this->delete($entity)) { return false; } - $primaryKey = (array)$this->primaryKey(); + $primaryKey = (array)$this->getPrimaryKey(); $query = $this->query(); $conditions = (array)$entity->extract($primaryKey); $statement = $query->delete() diff --git a/src/ORM/Query.php b/src/ORM/Query.php index 141c9b3..be4d412 100644 --- a/src/ORM/Query.php +++ b/src/ORM/Query.php @@ -10,11 +10,11 @@ class Query extends CakeQuery { /** * Overwriting triggerBeforeFind() to let queries not return soft deleted records - * + * * Cake\ORM\Query::triggerBeforeFind() overwritten to add the condition `deleted IS NULL` to every find request * in order to not return soft deleted records. * If the query contains the option `withDeleted`, the condition `deleted IS NULL` is not applied. - * + * * @return void */ public function triggerBeforeFind() @@ -22,7 +22,7 @@ public function triggerBeforeFind() if (!$this->_beforeFindFired && $this->_type === 'select') { parent::triggerBeforeFind(); - $repository = $this->repository(); + $repository = $this->getRepository(); $options = $this->getOptions(); if (!is_array($options) || !in_array('withDeleted', $options)) { diff --git a/tests/TestCase/Model/Table/SoftDeleteTraitTest.php b/tests/TestCase/Model/Table/SoftDeleteTraitTest.php index 5370c84..de924a9 100644 --- a/tests/TestCase/Model/Table/SoftDeleteTraitTest.php +++ b/tests/TestCase/Model/Table/SoftDeleteTraitTest.php @@ -1,4 +1,5 @@ usersTable->find()->where(['id' => 1])->first(); $this->assertEquals(null, $user); - } /** @@ -86,7 +87,10 @@ public function testFindWithOrWhere() $user = $this->usersTable->get(2); $this->usersTable->delete($user); - $query = $this->usersTable->find()->where(['id' => 1])->orWhere(['id' => 2]); + $query = $this->usersTable->find()->where(function($exp){ + return $exp->in('id', [1, 2]); + }); + $this->assertEquals(1, $query->count()); } @@ -106,9 +110,9 @@ public function testFindBelongsToMany() public function testFindMatching() { $users = $this->usersTable->find() - ->matching('Posts', function($q) { - return $q->where(['Posts.id' => 1]); - }); + ->matching('Posts', function($q) { + return $q->where(['Posts.id' => 1]); + }); $this->assertEquals(1, $users->count()); $post = $this->postsTable->get(1); @@ -118,13 +122,12 @@ public function testFindMatching() $this->assertEquals(1, $posts->count()); $users = $this->usersTable->find() - ->matching('Posts', function($q) { - return $q->where(['Posts.id' => 1]); - }); + ->matching('Posts', function($q) { + return $q->where(['Posts.id' => 1]); + }); $this->assertEquals(0, $users->count()); } - /** * Tests that Table::deleteAll() does not hard delete */ @@ -251,14 +254,14 @@ public function testDeleteWithCustomField() public function testHardDeleteWithCustomField() { $tag = $this->tagsTable->find('all', ['withDeleted']) - ->where(['id' => 2]) - ->first(); + ->where(['id' => 2]) + ->first(); $this->tagsTable->hardDelete($tag); $tag = $this->tagsTable->find('all', ['withDeleted']) - ->where(['id' => 2]) - ->first(); + ->where(['id' => 2]) + ->first(); $this->assertEquals(null, $tag); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ceacb60..729f011 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -52,7 +52,7 @@ 'defaults' => 'php' ]); -Cache::config([ +Cache::setConfig([ '_cake_core_' => [ 'engine' => 'File', 'prefix' => 'cake_core_', @@ -76,7 +76,7 @@ putenv('db_dsn=sqlite::memory:'); } -ConnectionManager::config('test', [ +ConnectionManager::setConfig('test', [ 'className' => 'Cake\Database\Connection', 'driver' => getenv('db_class'), 'dsn' => getenv('db_dsn'), @@ -86,7 +86,7 @@ 'timezone' => 'UTC' ]); -Log::config([ +Log::setConfig([ 'debug' => [ 'engine' => 'Cake\Log\Engine\FileLog', 'levels' => ['notice', 'info', 'debug'], From c023b005022f236d619ab8149c878312ef3df30b Mon Sep 17 00:00:00 2001 From: Tomohiro Ukawa Date: Wed, 24 Jul 2019 15:02:50 +0900 Subject: [PATCH 2/2] Update composer.json --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 9076a54..b0b2b9f 100644 --- a/composer.json +++ b/composer.json @@ -1,12 +1,12 @@ { - "name": "pgbi/cakephp3-soft-delete", + "name": "tomohiroukawa/cakephp3-soft-delete", "description": "SoftDelete plugin for CakePHP", "keywords": ["cakephp", "cakephp 3", "plugin", "soft", "delete", "deletable"], - "homepage": "https://github.com/pgbi/cakephp3-soft-delete", + "homepage": "https://github.com/tomohiroukawa/cakephp3-soft-delete", "type": "cakephp-plugin", "license": "MIT", "support": { - "source": "https://github.com/pgbi/cakephp3-soft-delete" + "source": "https://github.com/tomohiroukawa/cakephp3-soft-delete" }, "require": { "php": ">=5.4",