我有一个带有某些代码的垃圾邮件,我试图防止日志被垃圾邮件“已取消标识”,当运行相同的代码时,有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();
}
答案 0 :(得分:0)
如评论中所述,您可以使用Session 帮手记住日志是否已经制作,以免向日志发送垃圾邮件。
<?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
。如果没有,它将创建一个日志条目,并将带有其各自ID的Cancellation_identified
键添加到会话中。在其他2
实例中,您可以进行相同的检查。
请注意,这对于多个HTTP请求也很有用,因为每个请求的$contract->moxy_contract_id
很有可能会有所不同。上面的代码也可以解决这个问题,因为我们也在检查ID的相等性。