From 44a0235bb2e10a706e892e34058c4ee5774255a5 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:02:27 -0400 Subject: [PATCH 01/18] Update to use deleted_at instead of deleted * Change field used from deleted to deleted_at * Change binaries test to null / is not null --- system/Model.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/system/Model.php b/system/Model.php index e2a9ef55720e..4a560c7992ea 100644 --- a/system/Model.php +++ b/system/Model.php @@ -120,7 +120,7 @@ class Model /** * If this model should use "softDeletes" and - * simply set a flag when rows are deleted, or + * simply set a date when rows are deleted, or * do hard deletes. * * @var boolean @@ -182,7 +182,7 @@ class Model * * @var string */ - protected $deletedField = 'deleted'; + protected $deletedField = 'deleted_at'; /** * Used by asArray and asObject to provide @@ -356,7 +356,7 @@ public function find($id = null) if ($this->tempUseSoftDeletes === true) { - $builder->where($this->table . '.' . $this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, null); } if (is_array($id)) @@ -427,7 +427,7 @@ public function findAll(int $limit = 0, int $offset = 0) if ($this->tempUseSoftDeletes === true) { - $builder->where($this->table . '.' . $this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, null); } $row = $builder->limit($limit, $offset) @@ -457,7 +457,7 @@ public function first() if ($this->tempUseSoftDeletes === true) { - $builder->where($this->table . '.' . $this->deletedField, 0); + $builder->where($this->table . '.' . $this->deletedField, null); } // Some databases, like PostgreSQL, need order @@ -912,7 +912,7 @@ public function delete($id = null, bool $purge = false) if ($this->useSoftDeletes && ! $purge) { - $set[$this->deletedField] = 1; + $set[$this->deletedField] = $this->setDate(); if ($this->useTimestamps && ! empty($this->updatedField)) { @@ -947,7 +947,7 @@ public function purgeDeleted() } return $this->builder() - ->where($this->deletedField, 1) + ->where($this->deletedField . ' IS NOT NULL') ->delete(); } @@ -981,7 +981,7 @@ public function onlyDeleted() $this->tempUseSoftDeletes = false; $this->builder() - ->where($this->deletedField, 1); + ->where($this->deletedField . ' IS NOT NULL'); return $this; } @@ -1543,7 +1543,7 @@ public function countAllResults(bool $reset = true, bool $test = false) { if ($this->tempUseSoftDeletes === true) { - $this->builder()->where($this->deletedField, 0); + $this->builder()->where($this->deletedField, null); } return $this->builder()->countAllResults($reset, $test); From c46be1c75c86358e8165fa65ef2bd9fe9e76a0ac Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:16:51 -0400 Subject: [PATCH 02/18] Adjust tests for deleted_at * Seed values with date instead of 1 * Test IS NULL / IS NOT NULL instead of binaries --- tests/system/Database/Live/ModelTest.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index b29b5b381762..804521af7ac9 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -143,7 +143,7 @@ public function testFindRespectsSoftDeletes() { $this->db->table('user') ->where('id', 4) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model = new UserModel($this->db); @@ -219,7 +219,7 @@ public function testFindAllRespectsSoftDeletes() { $this->db->table('user') ->where('id', 4) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model = new UserModel($this->db); @@ -254,7 +254,7 @@ public function testFirstRespectsSoftDeletes() { $this->db->table('user') ->where('id', 1) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model = new UserModel(); @@ -403,11 +403,11 @@ public function testDeleteWithSoftDeletes() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL']); $model->delete(1); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 1]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); } //-------------------------------------------------------------------- @@ -416,7 +416,7 @@ public function testDeleteWithSoftDeletesPurge() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL']); $model->delete(1, true); @@ -1403,7 +1403,7 @@ public function testDeleteWithSoftDelete() $model->delete(1); - $this->seeInDatabase('job', ['id' => 1, 'deleted' => 1]); + $this->seeInDatabase('job', ['id' => 1, 'deleted_at IS NOT NULL']); } //-------------------------------------------------------------------- @@ -1414,7 +1414,7 @@ public function testPurgeDeletedWithSoftDeleteFalse() $this->db->table('job') ->where('id', 1) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model->purgeDeleted(); @@ -1629,7 +1629,7 @@ public function testSoftDeleteWithTableJoinsFindAll() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); $results = $model->join('job', 'job.id = user.id') ->findAll(); @@ -1645,7 +1645,7 @@ public function testSoftDeleteWithTableJoinsFind() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); $results = $model->join('job', 'job.id = user.id') ->find(1); @@ -1661,7 +1661,7 @@ public function testSoftDeleteWithTableJoinsFirst() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted' => 0]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); $results = $model->join('job', 'job.id = user.id') ->first(1); From f31d7775b8d2597f0a77031d62e0fef35b4a8d93 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:18:44 -0400 Subject: [PATCH 03/18] Change allowedFields for deleted_at --- tests/_support/Models/UserModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_support/Models/UserModel.php b/tests/_support/Models/UserModel.php index 05018820f380..7be6d889ccca 100644 --- a/tests/_support/Models/UserModel.php +++ b/tests/_support/Models/UserModel.php @@ -10,7 +10,7 @@ class UserModel extends Model 'name', 'email', 'country', - 'deleted', + 'deleted_at', ]; protected $returnType = 'object'; From 5a23efc1e4afa760bd5c8ce8c914a9106214103b Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:25:42 -0400 Subject: [PATCH 04/18] Change guide to reflect deleted_at --- user_guide_src/source/models/model.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index 3d7ee2b4e91d..f8dfc16e68d3 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -106,6 +106,7 @@ what table to use and how we can find the required records:: protected $useTimestamps = false; protected $createdField = 'created_at'; protected $updatedField = 'updated_at'; + protected $deletedField = 'deleted_at'; protected $validationRules = []; protected $validationMessages = []; @@ -137,13 +138,15 @@ method. **$useSoftDeletes** -If true, then any delete* method calls will simply set a flag in the database, instead of +If true, then any delete* method calls will set ``deleted_at`` in the database, instead of actually deleting the row. This can preserve data when it might be referenced elsewhere, or can maintain a "recycle bin" of objects that can be restored, or even simply preserve it as part of a security trail. If true, the find* methods will only return non-deleted rows, unless the withDeleted() method is called prior to calling the find* method. -This requires an INT or TINYINT field to be present in the table for storing state. The default field name is ``deleted`` however this name can be configured to any name of your choice by using $deletedField property. +This requires a DATETIME field to be present in the table for storing state. The default field +name is ``deleted_at`` however this name can be configured to any name of your choice by using +$deletedField property. **$allowedFields** @@ -262,8 +265,8 @@ Returns the first row in the result set. This is best used in combination with t **withDeleted()** -If $useSoftDeletes is true, then the find* methods will not return any rows where 'deleted = 1'. To -temporarily override this, you can use the withDeleted() method prior to calling the find* method. +If $useSoftDeletes is true, then the find* methods will not return any rows where 'deleted_at IS NOT NULL'. +To temporarily override this, you can use the withDeleted() method prior to calling the find* method. :: // Only gets non-deleted rows (deleted = 0) @@ -421,8 +424,8 @@ Takes a primary key value as the first parameter and deletes the matching record $userModel->delete(12); -If the model's $useSoftDeletes value is true, this will update the row to set 'deleted = 1'. You can force -a permanent delete by setting the second parameter as true. +If the model's $useSoftDeletes value is true, this will update the row to set ``deleted_at`` to the current +date and time. You can force a permanent delete by setting the second parameter as true. An array of primary keys can be passed in as the first parameter to delete multiple records at once:: @@ -435,7 +438,7 @@ previously:: **purgeDeleted()** -Cleans out the database table by permanently removing all rows that have 'deleted = 1'. :: +Cleans out the database table by permanently removing all rows that have 'deleted_at IS NOT NULL'. :: $userModel->purgeDeleted(); From d67b48860fa64992ba3bf139c2a7479c5c84828f Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:28:21 -0400 Subject: [PATCH 05/18] Use new deleted_at field --- tests/_support/Models/EntityModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_support/Models/EntityModel.php b/tests/_support/Models/EntityModel.php index 4460242330bf..46abfa59c43e 100644 --- a/tests/_support/Models/EntityModel.php +++ b/tests/_support/Models/EntityModel.php @@ -12,7 +12,7 @@ class EntityModel extends Model protected $dateFormat = 'int'; - protected $deletedField = 'deleted'; + protected $deletedField = 'deleted_at'; protected $allowedFields = [ 'name', From 9ea915bff13801bd85ba9e676a7517fdbc2918bd Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:51:05 -0400 Subject: [PATCH 06/18] Change deleted to deleted_at fields --- .../20160428212500_Create_test_tables.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php index f3e5842ffa8f..b980a80acfbc 100644 --- a/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php +++ b/tests/_support/Database/Migrations/20160428212500_Create_test_tables.php @@ -26,11 +26,6 @@ public function up() 'type' => 'VARCHAR', 'constraint' => 40, ], - 'deleted' => [ - 'type' => 'TINYINT', - 'constraint' => 1, - 'default' => '0', - ], 'created_at' => [ 'type' => 'DATETIME', 'null' => true, @@ -39,6 +34,10 @@ public function up() 'type' => 'DATETIME', 'null' => true, ], + 'deleted_at' => [ + 'type' => 'DATETIME', + 'null' => true, + ], ]); $this->forge->addKey('id', true); $this->forge->createTable('user', true); @@ -58,11 +57,6 @@ public function up() 'type' => 'TEXT', 'null' => true, ], - 'deleted' => [ - 'type' => 'TINYINT', - 'constraint' => 1, - 'default' => '0', - ], 'created_at' => [ 'type' => 'INTEGER', 'constraint' => 11, @@ -73,6 +67,11 @@ public function up() 'constraint' => 11, 'null' => true, ], + 'deleted_at' => [ + 'type' => 'INTEGER', + 'constraint' => 11, + 'null' => true, + ], ]); $this->forge->addKey('id', true); $this->forge->createTable('job', true); From 7dbc8fabd5e9b5e7da68f8e364b0d0a206ed8ea4 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:53:25 -0400 Subject: [PATCH 07/18] Change expected XML return for new deleted_at --- tests/system/Database/Live/DbUtilsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/Live/DbUtilsTest.php b/tests/system/Database/Live/DbUtilsTest.php index f355d94084d3..3e2a6c54ee63 100644 --- a/tests/system/Database/Live/DbUtilsTest.php +++ b/tests/system/Database/Live/DbUtilsTest.php @@ -203,7 +203,7 @@ public function testUtilsXMLFromResult() $data = $util->getXMLFromResult($data); - $expected = '4MusicianOnly Coldplay can actually called Musician'; + $expected = '4MusicianOnly Coldplay can actually called Musician'; $actual = preg_replace('#\R+#', '', $data); $actual = preg_replace('/[ ]{2,}|[\t]/', '', $actual); From 86177766afdbcb3b52c9c038a0b23f2619f59b0e Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:54:06 -0400 Subject: [PATCH 08/18] Implement deleted_at --- tests/_support/Models/EventModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/_support/Models/EventModel.php b/tests/_support/Models/EventModel.php index e9df2ecd6166..ed3312424d41 100644 --- a/tests/_support/Models/EventModel.php +++ b/tests/_support/Models/EventModel.php @@ -16,7 +16,7 @@ class EventModel extends Model 'name', 'email', 'country', - 'deleted', + 'deleted_at', ]; protected $beforeInsert = ['beforeInsertMethod']; From f4c376140149d0b352cb8e8760e1705311c2dace Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 11:57:16 -0400 Subject: [PATCH 09/18] Change deleted example --- user_guide_src/source/testing/database.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/testing/database.rst b/user_guide_src/source/testing/database.rst index 5001aa6108c0..8edfb5089f6a 100644 --- a/user_guide_src/source/testing/database.rst +++ b/user_guide_src/source/testing/database.rst @@ -157,7 +157,7 @@ Asserts that a number of matching rows are found in the database that match ``$c :: $criteria = [ - 'deleted' => 1 + 'active' => 1 ]; $this->seeNumRecords(2, 'users', $criteria); From 8abbef69857f0a1189e92279ea606caae16617e9 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 14:38:38 -0400 Subject: [PATCH 10/18] Fix CSV assertion for null deleted_at --- tests/system/Database/Live/DbUtilsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/Live/DbUtilsTest.php b/tests/system/Database/Live/DbUtilsTest.php index 3e2a6c54ee63..21c7e86fbeac 100644 --- a/tests/system/Database/Live/DbUtilsTest.php +++ b/tests/system/Database/Live/DbUtilsTest.php @@ -188,7 +188,7 @@ public function testUtilsCSVFromResult() $data = array_filter(preg_split('/(\r\n|\n|\r)/', $data)); - $this->assertEquals('"1","Developer","Awesome job, but sometimes makes you bored","0","",""', $data[1]); + $this->assertEquals('"1","Developer","Awesome job, but sometimes makes you bored","","",""', $data[1]); } //-------------------------------------------------------------------- From 48764f20f3724eb2cf91b1a969edffad8dd013d6 Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 14:39:34 -0400 Subject: [PATCH 11/18] Fix order of XML assertion --- tests/system/Database/Live/DbUtilsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/Live/DbUtilsTest.php b/tests/system/Database/Live/DbUtilsTest.php index 21c7e86fbeac..906e7c7809b2 100644 --- a/tests/system/Database/Live/DbUtilsTest.php +++ b/tests/system/Database/Live/DbUtilsTest.php @@ -203,7 +203,7 @@ public function testUtilsXMLFromResult() $data = $util->getXMLFromResult($data); - $expected = '4MusicianOnly Coldplay can actually called Musician'; + $expected = '4MusicianOnly Coldplay can actually called Musician'; $actual = preg_replace('#\R+#', '', $data); $actual = preg_replace('/[ ]{2,}|[\t]/', '', $actual); From 6a41a0999e8e52e836e23c66cb2fa995e747530f Mon Sep 17 00:00:00 2001 From: MGatner Date: Mon, 10 Jun 2019 15:19:03 -0400 Subject: [PATCH 12/18] Change deleted to deleted_at --- tests/system/Database/Live/ModelTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index 804521af7ac9..2790809cd5fb 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -461,7 +461,7 @@ public function testPurgeDeleted() $this->db->table('user') ->where('id', 1) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $model->purgeDeleted(); @@ -479,7 +479,7 @@ public function testOnlyDeleted() $this->db->table('user') ->where('id', 1) - ->update(['deleted' => 1]); + ->update(['deleted_at' => date('Y-m-d H:i:s')]); $users = $model->onlyDeleted() ->findAll(); @@ -757,7 +757,6 @@ public function testPasswordsStoreCorrectly() 'name' => $pass, 'email' => 'foo@example.com', 'country' => 'US', - 'deleted' => 0, ]; $model->insert($data); From 8746183fc82107e4793c1fa05c9c1ab618b5383f Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 11 Jun 2019 09:45:56 -0400 Subject: [PATCH 13/18] Use null strings as keys --- tests/system/Database/Live/ModelTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index 2790809cd5fb..f7ff10d98bf6 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -403,11 +403,11 @@ public function testDeleteWithSoftDeletes() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]); $model->delete(1); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); } //-------------------------------------------------------------------- @@ -416,7 +416,7 @@ public function testDeleteWithSoftDeletesPurge() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NULL' => null]); $model->delete(1, true); @@ -1402,7 +1402,7 @@ public function testDeleteWithSoftDelete() $model->delete(1); - $this->seeInDatabase('job', ['id' => 1, 'deleted_at IS NOT NULL']); + $this->seeInDatabase('job', ['id' => 1, 'deleted_at IS NOT NULL' => null]); } //-------------------------------------------------------------------- @@ -1628,7 +1628,7 @@ public function testSoftDeleteWithTableJoinsFindAll() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); $results = $model->join('job', 'job.id = user.id') ->findAll(); @@ -1644,7 +1644,7 @@ public function testSoftDeleteWithTableJoinsFind() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); $results = $model->join('job', 'job.id = user.id') ->find(1); @@ -1660,7 +1660,7 @@ public function testSoftDeleteWithTableJoinsFirst() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL']); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); $results = $model->join('job', 'job.id = user.id') ->first(1); From a461930adb592183da29043ae1d4b3da6b497596 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 11 Jun 2019 10:37:59 -0400 Subject: [PATCH 14/18] Fix logic error for un-deleted row tests --- tests/system/Database/Live/ModelTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index f7ff10d98bf6..57e6636e9159 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -1628,7 +1628,7 @@ public function testSoftDeleteWithTableJoinsFindAll() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); $results = $model->join('job', 'job.id = user.id') ->findAll(); @@ -1644,7 +1644,7 @@ public function testSoftDeleteWithTableJoinsFind() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); $results = $model->join('job', 'job.id = user.id') ->find(1); @@ -1660,7 +1660,7 @@ public function testSoftDeleteWithTableJoinsFirst() { $model = new UserModel(); - $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at IS NOT NULL' => null]); + $this->seeInDatabase('user', ['name' => 'Derek Jones', 'deleted_at' => null]); $results = $model->join('job', 'job.id = user.id') ->first(1); From 7830843a03d2b01ee48cd10c35f310e7655e89d3 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 11 Jun 2019 14:04:59 -0400 Subject: [PATCH 15/18] Use INT for job table deleted_at --- tests/system/Database/Live/ModelTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system/Database/Live/ModelTest.php b/tests/system/Database/Live/ModelTest.php index 57e6636e9159..b3ec505751a0 100644 --- a/tests/system/Database/Live/ModelTest.php +++ b/tests/system/Database/Live/ModelTest.php @@ -1413,7 +1413,7 @@ public function testPurgeDeletedWithSoftDeleteFalse() $this->db->table('job') ->where('id', 1) - ->update(['deleted_at' => date('Y-m-d H:i:s')]); + ->update(['deleted_at' => time()]); $model->purgeDeleted(); From d0df68aaddebfcf3b1d571e6a44a2834c9a71de9 Mon Sep 17 00:00:00 2001 From: MGatner Date: Tue, 11 Jun 2019 16:03:58 -0400 Subject: [PATCH 16/18] Add INT option for deleted_at --- user_guide_src/source/models/model.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index f8dfc16e68d3..0647adb17035 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -144,9 +144,9 @@ can maintain a "recycle bin" of objects that can be restored, or even simply pre part of a security trail. If true, the find* methods will only return non-deleted rows, unless the withDeleted() method is called prior to calling the find* method. -This requires a DATETIME field to be present in the table for storing state. The default field -name is ``deleted_at`` however this name can be configured to any name of your choice by using -$deletedField property. +This requires requires either a DATETIME or INTEGER field in the database as per the model's +$dateFormat setting. The default field name is ``deleted_at`` however this name can be +configured to any name of your choice by using $deletedField property. **$allowedFields** From ad20714c66649974f4101f8f3f2b32192b8383ff Mon Sep 17 00:00:00 2001 From: MGatner Date: Wed, 12 Jun 2019 09:17:23 -0400 Subject: [PATCH 17/18] Less requires --- user_guide_src/source/models/model.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index 0647adb17035..70b78e837543 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -144,7 +144,7 @@ can maintain a "recycle bin" of objects that can be restored, or even simply pre part of a security trail. If true, the find* methods will only return non-deleted rows, unless the withDeleted() method is called prior to calling the find* method. -This requires requires either a DATETIME or INTEGER field in the database as per the model's +This requires either a DATETIME or INTEGER field in the database as per the model's $dateFormat setting. The default field name is ``deleted_at`` however this name can be configured to any name of your choice by using $deletedField property. From ee0f8feff1e30dbc2adf881de872b1f75de2829a Mon Sep 17 00:00:00 2001 From: MGatner Date: Wed, 12 Jun 2019 10:01:16 -0400 Subject: [PATCH 18/18] Add table prefixes for `deleted_at` fields --- system/Model.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/system/Model.php b/system/Model.php index 4a560c7992ea..821c512ecb79 100644 --- a/system/Model.php +++ b/system/Model.php @@ -947,8 +947,8 @@ public function purgeDeleted() } return $this->builder() - ->where($this->deletedField . ' IS NOT NULL') - ->delete(); + ->where($this->table . '.' . $this->deletedField . ' IS NOT NULL') + ->delete(); } //-------------------------------------------------------------------- @@ -981,7 +981,7 @@ public function onlyDeleted() $this->tempUseSoftDeletes = false; $this->builder() - ->where($this->deletedField . ' IS NOT NULL'); + ->where($this->table . '.' . $this->deletedField . ' IS NOT NULL'); return $this; } @@ -1543,7 +1543,7 @@ public function countAllResults(bool $reset = true, bool $test = false) { if ($this->tempUseSoftDeletes === true) { - $this->builder()->where($this->deletedField, null); + $this->builder()->where($this->table . '.' . $this->deletedField, null); } return $this->builder()->countAllResults($reset, $test);