Skip to content

Commit

Permalink
Merge pull request #2332 from MGatner/afterinsert
Browse files Browse the repository at this point in the history
Change after methods to use actual data
  • Loading branch information
lonnieezell authored Oct 16, 2019
2 parents 0213516 + 24eccc8 commit 65cc1f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
15 changes: 3 additions & 12 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,6 @@ public function insert($data = null, bool $returnID = true)
}
}

// Save the original data so it can be passed to
// any Model Event callbacks and not stripped
// by doProtectFields
$originalData = $data;

// Must be called first so we don't
// strip out created_at values.
$data = $this->doProtectFields($data);
Expand Down Expand Up @@ -722,7 +717,8 @@ public function insert($data = null, bool $returnID = true)
$this->insertID = $this->db->insertID();
}

$this->trigger('afterInsert', ['data' => $originalData, 'result' => $result]);
// Trigger afterInsert events with the inserted data and new ID
$this->trigger('afterInsert', ['id' => $this->insertID, 'data' => $data, 'result' => $result]);

// If insertion failed, get out of here
if (! $result)
Expand Down Expand Up @@ -821,11 +817,6 @@ public function update($id = null, $data = null): bool
}
}

// Save the original data so it can be passed to
// any Model Event callbacks and not stripped
// by doProtectFields
$originalData = $data;

// Must be called first so we don't
// strip out updated_at values.
$data = $this->doProtectFields($data);
Expand All @@ -849,7 +840,7 @@ public function update($id = null, $data = null): bool
->set($data['data'], '', $escape)
->update();

$this->trigger('afterUpdate', ['id' => $id, 'data' => $originalData, 'result' => $result]);
$this->trigger('afterUpdate', ['id' => $id, 'data' => $data, 'result' => $result]);

return $result;
}
Expand Down
5 changes: 3 additions & 2 deletions user_guide_src/source/models/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,14 @@ Event $data contents
================ =========================================================================================================
beforeInsert **data** = the key/value pairs that are being inserted. If an object or Entity class is passed to the
insert method, it is first converted to an array.
afterInsert **data** = the original key/value pairs being inserted.
afterInsert **id** = the primary key of the new row, or 0 on failure.
**data** = the key/value pairs being inserted.
**result** = the results of the insert() method used through the Query Builder.
beforeUpdate **id** = the primary key of the row being updated.
**data** = the key/value pairs that are being inserted. If an object or Entity class is passed to the
insert method, it is first converted to an array.
afterUpdate **id** = the primary key of the row being updated.
**data** = the original key/value pairs being updated.
**data** = the key/value pairs being updated.
**result** = the results of the update() method used through the Query Builder.
afterFind Varies by find* method. See the following:
- find() **id** = the primary key of the row being searched for.
Expand Down

0 comments on commit 65cc1f4

Please sign in to comment.