Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseModel/Model - Attempt to rework escape parameter #4072

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,11 @@ abstract protected function doFirst();
* Inserts data into the current database
* This methods works only with dbCalls
*
* @param array $data Data
* @param boolean|null $escape Escape
* @param array $data Data
*
* @return object|integer|string|false
*/
abstract protected function doInsert(array $data, ?bool $escape = null);
abstract protected function doInsert(array $data);

/**
* Compiles batch insert and runs the queries, validating each row prior.
Expand Down Expand Up @@ -708,13 +707,12 @@ public function getInsertID()
*
* @param array|object|null $data Data
* @param boolean $returnID Whether insert ID should be returned or not.
* @param boolean|null $escape Escape
*
* @return BaseResult|object|integer|string|false
*
* @throws ReflectionException
*/
public function insert($data = null, bool $returnID = true, ?bool $escape = null)
public function insert($data = null, bool $returnID = true)
{
$this->insertID = 0;

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

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

$eventData = [
'id' => $this->insertID,
Expand Down Expand Up @@ -866,15 +864,14 @@ public function insertBatch(?array $set = null, ?bool $escape = null, int $batch
* Updates a single record in the database. If an object is provided,
* it will attempt to convert it into an array.
*
* @param integer|array|string|null $id ID
* @param array|object|null $data Data
* @param boolean|null $escape Escape
* @param integer|array|string|null $id ID
* @param array|object|null $data Data
*
* @return boolean
*
* @throws ReflectionException
*/
public function update($id = null, $data = null, ?bool $escape = null): bool
public function update($id = null, $data = null): bool
{
if (is_numeric($id) || is_string($id))
{
Expand Down Expand Up @@ -936,7 +933,7 @@ public function update($id = null, $data = null, ?bool $escape = null): bool
$eventData = [
'id' => $id,
'data' => $eventData['data'],
'result' => $this->doUpdate($id, $eventData['data'], $escape),
'result' => $this->doUpdate($id, $eventData['data']),
];

if ($this->tempAllowCallbacks)
Expand Down
36 changes: 23 additions & 13 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ class Model extends BaseModel
*/
protected $tempData = [];

/**
* Escape Parameter to be passed in do methods
*
* @var boolean|null
*/
protected $escape = null;

// endregion

// region Constructor
Expand Down Expand Up @@ -243,13 +250,15 @@ protected function doFirst()
* Inserts data into the current table.
* This methods works only with dbCalls
*
* @param array $data Data
* @param boolean|null $escape Escape
* @param array $data Data
*
* @return BaseResult|integer|string|false
*/
protected function doInsert(array $data, ?bool $escape = null)
protected function doInsert(array $data)
{
$escape = $this->escape;
$this->escape = null;

// Require non empty primaryKey when
// not using auto-increment feature
if (! $this->useAutoIncrement && empty($data[$this->primaryKey]))
Expand Down Expand Up @@ -320,6 +329,9 @@ protected function doInsertBatch(?array $set = null, ?bool $escape = null, int $
*/
protected function doUpdate($id = null, $data = null, ?bool $escape = null): bool
{
$escape = $this->escape;
$this->escape = null;

$builder = $this->builder();

if ($id)
Expand Down Expand Up @@ -654,46 +666,44 @@ protected function shouldUpdate($data) : bool
*
* @param array|object|null $data Data
* @param boolean $returnID Whether insert ID should be returned or not.
* @param boolean|null $escape Escape
*
* @return BaseResult|object|integer|string|false
*
* @throws ReflectionException
*/
public function insert($data = null, bool $returnID = true, ?bool $escape = null)
public function insert($data = null, bool $returnID = true)
{
if (empty($data))
{
$data = $this->tempData['data'] ?? null;
$escape = $this->tempData['escape'] ?? null;
$this->escape = $this->tempData['escape'] ?? null;
$this->tempData = [];
}

return parent::insert($data, $returnID, $escape);
return parent::insert($data, $returnID);
}

/**
* Updates a single record in the database. If an object is provided,
* it will attempt to convert it into an array.
*
* @param integer|array|string|null $id ID
* @param array|object|null $data Data
* @param boolean|null $escape Escape
* @param integer|array|string|null $id ID
* @param array|object|null $data Data
*
* @return boolean
*
* @throws ReflectionException
*/
public function update($id = null, $data = null, ?bool $escape = null): bool
public function update($id = null, $data = null): bool
{
if (empty($data))
{
$data = $this->tempData['data'] ?? null;
$escape = $this->tempData['escape'] ?? null;
$this->escape = $this->tempData['escape'] ?? null;
$this->tempData = [];
}

return parent::update($id, $data, $escape);
return parent::update($id, $data);
}

// endregion
Expand Down