public static function changeRequestTypeAndPutToResend($vks_id, $request_type) { if (in_array($request_type, [OutlookCalendarRequest::REQUEST_TYPE_NEW, OutlookCalendarRequest::REQUEST_TYPE_UPDATE])) { $requests = OutlookCalendarRequest::where('vks_id', $vks_id)->get(); if (count($requests)) { foreach ($requests as $request) { $request->request_type = $request_type; $request->send_status = OutlookCalendarRequest::SEND_STATUS_REQUIRED; $request->save(); } } return true; } else { return false; } }
$vc = new Vks_controller(); $callback_func = function (AMQPEnvelope $message, AMQPQueue $q) use(&$max_consume, $vc) { $data = json_decode($message->getBody()); print '---------------query--------------' . "\r\n"; echo sprintf(" QueueName: %s", $q->getName()), PHP_EOL; print '---------------received!--------------' . "\r\n"; try { $vks = Vks::approved()->notEnded()->findOrFail($data->vks_id); $vc->humanize($vks); $user = User::find($data->user_id); if (!OutlookCalendarRequest::where('user_id', $user->id)->where('vks_id', $vks->id)->count()) { $reSend = OutlookCalendarRequest::create(array('user_id' => $user->id, 'vks_id' => $vks->id, 'request_type' => $data->request_type, 'send_status' => OutlookCalendarRequest::SEND_STATUS_COMPLETED)); App::$instance->log->logWrite(LOG_OTHER_EVENTS, "New Outlook request create for " . $user->id . ', vks: ' . $vks->id); } else { if ($data->force) { $reSend = OutlookCalendarRequest::where('user_id', $user->id)->where('vks_id', $vks->id)->first(); $reSend->request_type = $data->request_type; $reSend->send_status = OutlookCalendarRequest::SEND_STATUS_COMPLETED; $reSend->save(); App::$instance->log->logWrite(LOG_OTHER_EVENTS, "New Outlook request create for " . $user->id . ', vks: ' . $vks->id); } else { echo sprintf("Outlook Request to: user_id %s, and vks_id %s already sended, no force KEY detected", $data->user_id, $data->vks_id), PHP_EOL; } } Mail::sendIcalEvent($vks, $reSend->request_type, $user); App::$instance->log->logWrite(LOG_MAIL_SENDED, 'Outlook event invite sended to: ' . $user->email); } catch (Exception $e) { echo sprintf("Outlook Request to: user_id %s, and vks_id %s broken", $data->user_id, $data->vks_id), PHP_EOL; } $q->ack($message->getDeliveryTag()); print '---------------ready!--------------' . "\r\n";