/** * This method is invoked after saving a record successfully. * The default implementation does nothing. * You may override this method to do postprocessing after record saving. * * @param mixed $data The model or action's data * @param mixed $configType the class name or instance of class that is configured in 'config/activityNotice.php' * @param string $action the action, the possible values: "add", "update", "batch" * @param mixed $attributeNames the attributes * @param array $modelList1 if $action is "batchSave", this will be the inserted models, if action is "batchDelete" and * there's multiple deletion executed, this will be the deleted models * @param array $modelList2 if $action is "batchSave", this will be the updated models, if action is "batchDelete", this parameter is ignored. * @return ActivityNotice The activity notice data that sent to AMQP Server. If the notification action is failed, FALSE will be returned. */ public function noticeAfterModelAction($data, $configType, $action, $attributeNames = null, $modelList1 = null, $modelList2 = null) { if (is_object($configType)) { $classId = get_class($configType); } else { $classId = $configType; } $noticeAction = $action === 'delete' && is_array($modelList1) ? 'batchDelete' : $action; $serializer = $this->getSerializer(); $config = $serializer->getActivityNoticeConfig($classId, $noticeAction, $attributeNames); if (!isset($config)) { return false; } $a = explode('\\', $classId); $shortClassId = array_pop($a); $notice = new ActivityNotice(['kind' => lcfirst($shortClassId) . 'AUD', 'dispatchTime' => DateTimeHelper::currentDateTime(), 'dispatcher' => $this->getDispatcher(), 'contentUpdatedFields' => $attributeNames]); if ($action === 'batchSave') { if (count($modelList1) > 0) { $notice->action = 'add'; $notice->content = $serializer->getSerializeListData($modelList1, $config); $this->sendActivityNotice($notice); } if (count($modelList2) > 0) { $notice->action = 'update'; $notice->content = $serializer->getSerializeListData($modelList2, $config); $this->sendActivityNotice($notice); } } else { $notice->action = $noticeAction; if ($noticeAction === 'batchDelete') { if (isset($modelList1)) { $notice->content = $serializer->getSerializeListData($modelList1, $config); } else { $notice->content = $data; } } elseif ($noticeAction === 'delete' && !empty($modelList1) && !is_array($modelList1)) { $notice->content = $serializer->getSerializeData($modelList1, $config); } else { $notice->content = $serializer->getSerializeData($data, $config); } $this->sendActivityNotice($notice); } return $notice; }