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

Change after methods to use actual data #2332

Merged
merged 1 commit into from
Oct 16, 2019
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
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