我有一個帶有一些代碼的垃圾郵件,我試圖防止日志發送垃圾郵件“已識別取消”,當運行相同的代碼時有 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();}
1 回答
白板的微信
TA貢獻1883條經驗 獲得超3個贊
正如評論中提到的,您可以使用Session helper 來記住日志是否已經生成,以避免垃圾郵件發送您的日志。
<?php
if(empty(session('Cancellation_identified')) || session('Cancellation_identified') !== $contract->moxy_contract_id){
session(['Cancellation_identified' => $contract->moxy_contract_id]);
LogAction::add("Data Adjustment", "Cancellation Identified.", 0, "", $contract->moxy_contract_id);
}
以上將檢查Cancellation_identified會話中是否存在。如果沒有,它會創建一個日志條目并將Cancellation_identified帶有其各自 ID的密鑰添加到會話中。在其他2情況下,您可以進行相同的檢查。
請注意,這對于多個 HTTP 請求也很有用,$contract->moxy_contract_id因為每個請求很可能會有所不同。上面的代碼也會處理這個問題,因為我們也在檢查 ID 是否相等。
- 1 回答
- 0 關注
- 215 瀏覽
添加回答
舉報
0/150
提交
取消
