// if we didn't find a comment earlier create one now if (!$comment) { $comment = new Comment(); } $comment->request_id = $parentRequest->id; $comment->message_id = $messageId; $comment->text_comment = $messageParts['text']; $comment->html_comment = $messageParts['html']; $comment->save(); continue; } } // if it doesn't attach to anything else see if it matches up to an existing request // if it does update, otherwise just create a new request if (!$parentRequest) { $request = Request::findOne(array('message_id' => $messageId)); if (!$request) { $request = new Request(); } $request->creator_id = $sender->id; $request->name = trim($message->subject); $request->message_id = $messageId; $request->text_desc = $messageParts['text']; $request->html_desc = $messageParts['html']; $request->short_desc = $messageParts['short']; $request->save(); if (isset($messageParts['attachments'])) { foreach ($messageParts['attachments'] as $info) { $attachment = Attachment::getOne(array('request_id' => $request->id, 'hash' => $info['hash'])); $attachment->name = $info['name']; $attachment->type = $info['type'];