猿问

防止日志中的重复条目

我有一个带有一些代码的垃圾邮件,我试图防止日志发送垃圾邮件“已识别取消”,当运行相同的代码时有 3 个实例并且它是垃圾邮件。如果有重复,我想防止我的日志中出现“取消已识别”垃圾邮件。


有没有办法防止重复输入“已识别取消”的日志?


我有一些用于修复的伪代码,但无法将其转换为 php。


   if($searchfor)

    {

        $searchfor = "Cancellation Identified";

        $searchfor = true;

        continue process_imports();

    }

if(!empty($contract)){

    //Determine if contract has been cancelled based on the presence of a cancellation date.

    if ((isset($data['cancelled_date'])) && (substr_count($data['sold_date'], '/') == 2) && ($contract->cancelled_date >= '2015-01-01')) {

        //If cancelled determine if cancellation is new by comparing to previously cancelled contracts table.

        $IsCancelled = ContractCancellation::LocateCancellation($contract->moxy_contract_id);

        if (!$IsCancelled->first()) { //Contract is not in cancellations table, flag contract for later cancellations processing.

            $contract->cancel_pending = 1;

            if($contract->hold == '1'){

                LogAction::add("Data Adjustment", "Hold Removed Due To Contract Being Cancelled.", 0, "", $contract->moxy_contract_id);

            }

            $contract->hold = 0;

            $contract->save();

            LogAction::add("Data Adjustment", "Cancellation Identified.", 0, "", $contract->moxy_contract_id);                                  

        }

    }

    $contract->cancel_miles = !empty($data['cancel_miles']) ? $data['cancel_miles'] : 0;

    $contract->cancel_reason = !empty($data['cancel_reason']) ? $data['cancel_reason'] : NULL;

    $contract->save();

}


元芳怎么了
浏览 180回答 1
1回答

白板的微信

正如评论中提到的,您可以使用Session helper 来记住日志是否已经生成,以避免垃圾邮件发送您的日志。<?phpif(empty(session('Cancellation_identified')) || session('Cancellation_identified') !== $contract->moxy_contract_id){&nbsp; &nbsp; session(['Cancellation_identified' => $contract->moxy_contract_id]);&nbsp; &nbsp; LogAction::add("Data Adjustment", "Cancellation Identified.", 0, "", $contract->moxy_contract_id);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp;以上将检查Cancellation_identified会话中是否存在。如果没有,它会创建一个日志条目并将Cancellation_identified带有其各自 ID的密钥添加到会话中。在其他2情况下,您可以进行相同的检查。请注意,这对于多个 HTTP 请求也很有用,$contract->moxy_contract_id因为每个请求很可能会有所不同。上面的代码也会处理这个问题,因为我们也在检查 ID 是否相等。
随时随地看视频慕课网APP
我要回答