| @@ 33-57 (lines=25) @@ | ||
| 30 | * |
|
| 31 | * @return void |
|
| 32 | */ |
|
| 33 | public function queue($name, Model $model, $changeBy) |
|
| 34 | { |
|
| 35 | // Get modified attributes |
|
| 36 | $dirty = $model->getDirty(); |
|
| 37 | $isNew = strpos($name, 'add_') === 0; |
|
| 38 | ||
| 39 | // Stop if nothing changed |
|
| 40 | if (!$model->isDirty() && !$isNew) { |
|
| 41 | return; |
|
| 42 | } |
|
| 43 | ||
| 44 | // Get the original value of the modified attributes |
|
| 45 | $origin = []; |
|
| 46 | foreach ($dirty as $field => $value) { |
|
| 47 | $origin[$field] = $model->getOriginal($field, $value); |
|
| 48 | } |
|
| 49 | ||
| 50 | // Fill and save to message queue |
|
| 51 | $fill = $this->getFillAttributes($name, $model, $changeBy, [ |
|
| 52 | 'dirty' => $dirty, |
|
| 53 | 'origin' => $origin, |
|
| 54 | ]); |
|
| 55 | ||
| 56 | return $this->model->fill($fill)->save(); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Insert a record into the message queue about a delete event. |
|
| @@ 37-61 (lines=25) @@ | ||
| 34 | * |
|
| 35 | * @return void |
|
| 36 | */ |
|
| 37 | public function queue($name, Model $model, $changeBy) |
|
| 38 | { |
|
| 39 | // Get modified attributes |
|
| 40 | $dirty = $model->getDirty(); |
|
| 41 | $isNew = strpos($name, 'add_') === 0; |
|
| 42 | ||
| 43 | // Stop if nothing changed |
|
| 44 | if (!$model->isDirty() && !$isNew) { |
|
| 45 | return; |
|
| 46 | } |
|
| 47 | ||
| 48 | // Get the original value of the modified attributes |
|
| 49 | $origin = []; |
|
| 50 | foreach ($dirty as $field => $value) { |
|
| 51 | $origin[$field] = $model->getOriginal($field, $value); |
|
| 52 | } |
|
| 53 | ||
| 54 | // Fill and save to message queue |
|
| 55 | $fill = $this->getFillAttributes($name, $model, $changeBy, [ |
|
| 56 | 'dirty' => $dirty, |
|
| 57 | 'origin' => $origin, |
|
| 58 | ]); |
|
| 59 | ||
| 60 | return $this->fill($fill)->save(); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * Insert a record into the message queue about a delete event. |
|