Skip to content

Commit d09a546

Browse files
authored
Merge pull request #4072 from najdanovicivan/nosql/base-model-escape
BaseModel/Model - Attempt to rework escape parameter
2 parents eb0cf46 + 210a3ab commit d09a546

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

system/BaseModel.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,11 @@ abstract protected function doFirst();
354354
* Inserts data into the current database
355355
* This methods works only with dbCalls
356356
*
357-
* @param array $data Data
358-
* @param boolean|null $escape Escape
357+
* @param array $data Data
359358
*
360359
* @return object|integer|string|false
361360
*/
362-
abstract protected function doInsert(array $data, ?bool $escape = null);
361+
abstract protected function doInsert(array $data);
363362

364363
/**
365364
* Compiles batch insert and runs the queries, validating each row prior.
@@ -708,13 +707,12 @@ public function getInsertID()
708707
*
709708
* @param array|object|null $data Data
710709
* @param boolean $returnID Whether insert ID should be returned or not.
711-
* @param boolean|null $escape Escape
712710
*
713711
* @return BaseResult|object|integer|string|false
714712
*
715713
* @throws ReflectionException
716714
*/
717-
public function insert($data = null, bool $returnID = true, ?bool $escape = null)
715+
public function insert($data = null, bool $returnID = true)
718716
{
719717
$this->insertID = 0;
720718

@@ -774,7 +772,7 @@ public function insert($data = null, bool $returnID = true, ?bool $escape = null
774772
$eventData = $this->trigger('beforeInsert', $eventData);
775773
}
776774

777-
$result = $this->doInsert($eventData['data'], $escape);
775+
$result = $this->doInsert($eventData['data']);
778776

779777
$eventData = [
780778
'id' => $this->insertID,
@@ -866,15 +864,14 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
866864
* Updates a single record in the database. If an object is provided,
867865
* it will attempt to convert it into an array.
868866
*
869-
* @param integer|array|string|null $id ID
870-
* @param array|object|null $data Data
871-
* @param boolean|null $escape Escape
867+
* @param integer|array|string|null $id ID
868+
* @param array|object|null $data Data
872869
*
873870
* @return boolean
874871
*
875872
* @throws ReflectionException
876873
*/
877-
public function update($id = null, $data = null, ?bool $escape = null): bool
874+
public function update($id = null, $data = null): bool
878875
{
879876
if (is_numeric($id) || is_string($id))
880877
{
@@ -936,7 +933,7 @@ public function update($id = null, $data = null, ?bool $escape = null): bool
936933
$eventData = [
937934
'id' => $id,
938935
'data' => $eventData['data'],
939-
'result' => $this->doUpdate($id, $eventData['data'], $escape),
936+
'result' => $this->doUpdate($id, $eventData['data']),
940937
];
941938

942939
if ($this->tempAllowCallbacks)

system/Model.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ class Model extends BaseModel
8484
*/
8585
protected $tempData = [];
8686

87+
/**
88+
* Escape Parameter to be passed in do methods
89+
*
90+
* @var boolean|null
91+
*/
92+
protected $escape = null;
93+
8794
// endregion
8895

8996
// region Constructor
@@ -243,13 +250,15 @@ protected function doFirst()
243250
* Inserts data into the current table.
244251
* This methods works only with dbCalls
245252
*
246-
* @param array $data Data
247-
* @param boolean|null $escape Escape
253+
* @param array $data Data
248254
*
249255
* @return BaseResult|integer|string|false
250256
*/
251-
protected function doInsert(array $data, ?bool $escape = null)
257+
protected function doInsert(array $data)
252258
{
259+
$escape = $this->escape;
260+
$this->escape = null;
261+
253262
// Require non empty primaryKey when
254263
// not using auto-increment feature
255264
if (! $this->useAutoIncrement && empty($data[$this->primaryKey]))
@@ -320,6 +329,9 @@ protected function doInsertBatch(?array $set = null, ?bool $escape = null, int $
320329
*/
321330
protected function doUpdate($id = null, $data = null, ?bool $escape = null): bool
322331
{
332+
$escape = $this->escape;
333+
$this->escape = null;
334+
323335
$builder = $this->builder();
324336

325337
if ($id)
@@ -655,46 +667,44 @@ protected function shouldUpdate($data) : bool
655667
*
656668
* @param array|object|null $data Data
657669
* @param boolean $returnID Whether insert ID should be returned or not.
658-
* @param boolean|null $escape Escape
659670
*
660671
* @return BaseResult|object|integer|string|false
661672
*
662673
* @throws ReflectionException
663674
*/
664-
public function insert($data = null, bool $returnID = true, ?bool $escape = null)
675+
public function insert($data = null, bool $returnID = true)
665676
{
666677
if (empty($data))
667678
{
668679
$data = $this->tempData['data'] ?? null;
669-
$escape = $this->tempData['escape'] ?? null;
680+
$this->escape = $this->tempData['escape'] ?? null;
670681
$this->tempData = [];
671682
}
672683

673-
return parent::insert($data, $returnID, $escape);
684+
return parent::insert($data, $returnID);
674685
}
675686

676687
/**
677688
* Updates a single record in the database. If an object is provided,
678689
* it will attempt to convert it into an array.
679690
*
680-
* @param integer|array|string|null $id ID
681-
* @param array|object|null $data Data
682-
* @param boolean|null $escape Escape
691+
* @param integer|array|string|null $id ID
692+
* @param array|object|null $data Data
683693
*
684694
* @return boolean
685695
*
686696
* @throws ReflectionException
687697
*/
688-
public function update($id = null, $data = null, ?bool $escape = null): bool
698+
public function update($id = null, $data = null): bool
689699
{
690700
if (empty($data))
691701
{
692702
$data = $this->tempData['data'] ?? null;
693-
$escape = $this->tempData['escape'] ?? null;
703+
$this->escape = $this->tempData['escape'] ?? null;
694704
$this->tempData = [];
695705
}
696706

697-
return parent::update($id, $data, $escape);
707+
return parent::update($id, $data);
698708
}
699709

700710
// endregion

0 commit comments

Comments
 (0)