diff --git a/src/Database/Model.php b/src/Database/Model.php index 974ccd4d..9da17c5d 100644 --- a/src/Database/Model.php +++ b/src/Database/Model.php @@ -213,7 +213,7 @@ protected function bootNicerEvents() return; } - $radicals = ['creat', 'sav', 'updat', 'delet', 'fetch']; + $radicals = ['creat', 'sav', 'updat', 'delet', 'fetch', 'prun', 'replicat']; $hooks = ['before' => 'ing', 'after' => 'ed']; foreach ($radicals as $radical) { @@ -221,6 +221,10 @@ protected function bootNicerEvents() $eventMethod = $radical . $event; // saving / saved $method = $hook . ucfirst($radical); // beforeSave / afterSave + if ($radical === 'replicat' || $radical === 'prun') { + continue; + } + if ($radical != 'fetch') { $method .= 'e'; } @@ -479,6 +483,44 @@ protected function afterFetch() */ } + /** + * Handle the "replicating" model event + */ + protected function beforeReplicate() + { + /** + * @event model.beforeReplicate + * Called before the model is replicated + * > **Note:** also triggered in Winter\Storm\Halcyon\Model + * + * Example usage: + * + * $model->bindEvent('model.beforeReplicate', function () use (\Winter\Storm\Database\Model $model) { + * $model->name = $model->name . ' copy'; + * }); + * + */ + } + + /** + * Handle the "pruning" model event + */ + protected function beforePrune() + { + /** + * @event model.beforePrune + * Called before the model is pruned + * > **Note:** also triggered in Winter\Storm\Halcyon\Model + * + * Example usage: + * + * $model->bindEvent('model.beforePrune', function () use (\Winter\Storm\Database\Model $model) { + * $model->attachment->delete(); + * }); + * + */ + } + /** * Flush the memory cache. * @return void @@ -579,7 +621,7 @@ public function getObservableEvents() [ 'creating', 'created', 'updating', 'updated', 'deleting', 'deleted', 'saving', 'saved', - 'restoring', 'restored', 'fetching', 'fetched' + 'restoring', 'restored', 'fetching', 'fetched', 'pruning', 'replicating' ], $this->observables );