Skip to content

Commit d1002d9

Browse files
authored
Add exception for missing/invalid $dateFormat
1 parent 8ae976f commit d1002d9

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

system/Model.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public function find($id = null)
395395
* @param string $columnName
396396
*
397397
* @return array|null The resulting row of data, or null if no data found.
398+
* @throws \CodeIgniter\Database\Exceptions\DataException
398399
*/
399400
public function findColumn(string $columnName)
400401
{
@@ -947,8 +948,8 @@ public function purgeDeleted()
947948
}
948949

949950
return $this->builder()
950-
->where($this->table . '.' . $this->deletedField . ' IS NOT NULL')
951-
->delete();
951+
->where($this->deletedField . ' IS NOT NULL')
952+
->delete();
952953
}
953954

954955
//--------------------------------------------------------------------
@@ -981,7 +982,7 @@ public function onlyDeleted()
981982
$this->tempUseSoftDeletes = false;
982983

983984
$this->builder()
984-
->where($this->table . '.' . $this->deletedField . ' IS NOT NULL');
985+
->where($this->deletedField . ' IS NOT NULL');
985986

986987
return $this;
987988
}
@@ -1152,6 +1153,7 @@ public function protect(bool $protect = true)
11521153
* @param string $table
11531154
*
11541155
* @return BaseBuilder
1156+
* @throws \CodeIgniter\Exceptions\ModelException;
11551157
*/
11561158
protected function builder(string $table = null)
11571159
{
@@ -1226,8 +1228,8 @@ protected function doProtectFields(array $data): array
12261228
/**
12271229
* A utility function to allow child models to use the type of
12281230
* date/time format that they prefer. This is primarily used for
1229-
* setting created_at and updated_at values, but can be used
1230-
* by inheriting classes.
1231+
* setting created_at, updated_at and deleted_at values, but can be
1232+
* used by inheriting classes.
12311233
*
12321234
* The available time formats are:
12331235
* - 'int' - Stores the date as an integer timestamp
@@ -1237,6 +1239,7 @@ protected function doProtectFields(array $data): array
12371239
* @param integer $userData An optional PHP timestamp to be converted.
12381240
*
12391241
* @return mixed
1242+
* @throws \CodeIgniter\Exceptions\ModelException;
12401243
*/
12411244
protected function setDate(int $userData = null)
12421245
{
@@ -1253,6 +1256,8 @@ protected function setDate(int $userData = null)
12531256
case 'date':
12541257
return date('Y-m-d', $currentDate);
12551258
break;
1259+
default:
1260+
throw ModelException::forNoDateFormat(get_class($this));
12561261
}
12571262
}
12581263

@@ -1543,7 +1548,7 @@ public function countAllResults(bool $reset = true, bool $test = false)
15431548
{
15441549
if ($this->tempUseSoftDeletes === true)
15451550
{
1546-
$this->builder()->where($this->table . '.' . $this->deletedField, null);
1551+
$this->builder()->where($this->deletedField, null);
15471552
}
15481553

15491554
return $this->builder()->countAllResults($reset, $test);

0 commit comments

Comments
 (0)