Job did not complete, save a few stats so we can see what went wrong.

@param $id
@param null $message
@return bool|\Cake\Datasource\EntityInterface|mixed
323706
public function markJobFailed($id, $message = null)
    {
        $entity = $this->get($id);
        $data = ['completed' => false, 'stats' => ['tries' => ($entity->stats['tries'] + 1), 'message' => $entity->stats['message'] . ($entity->stats['tries'] + 1) . '. ' . $message . PHP_EOL]];
        $this->patchEntity($entity, $data, ['validate' => false]);
        return $this->save($entity);
    }
1169156
public function jsonSuccess($data = null, $message = null) {
        if (!is_array($message)) {
            $message = ['messages' => $message];
        }
        if ($data instanceof ArrayAble) {
            $data = $data->toArray();
        }
        return $this->json(array_merge(array(
            'code' => 200,
            'status' => __('success'),
            'data' => $data
        ), $message));
    }
1290649
public function sendUserMessage($id, $message, $type = 'popup_chat')
    {
        if ($this->isEmptyId($id)) {
            throw new InvalidArgumentException;
        }

        if (!$message) {
            throw new InvalidArgumentException;
        }

        if (!in_array($type, ['popup_chat', 'popup_small', 'popup_big', 'email'])) {
            throw new InvalidArgumentException;
        }

        $params = [
            'body' => $message,
            'type' => $type
        ];
        $res = $this->call('users/' . $id . '/sendmessage', $params, 'post');

        if ($res) {
            return true;
        }

        return false;
    }
102369
public static function create($validator, $message = null)
    {
        $class = self::checkValidator($validator);

        /** @var ValidatorInterface $object */
        $object = new $class;
        if (!is_null($message)) {
            $object->setMessage($message);
        }
        return $object;
    }
118610
public function updateEventMessageById($id, $fields) {
        $event = new \CEventMessage;
        if ($event->Update($id, $fields)) {
            return $id;
        }

        $this->throwException(__METHOD__, $event->LAST_ERROR);
    }
1045638
public function send(MessageInterface $message, &$failures = null)
    {
        return $this->mailer->send($message(), $failures);
    }
486238
public function delete($message)
    {
        if (!$message instanceof QueueMessage) {
            $msg = new QueueMessage();
            $msg->setId($message);
        }

        $this->driver->delete($message);

        $message->isDeleted(true);
    }
606442
public function refresh($id, $entity)
    {
        $label = $this->classMetadata->getLabel();
        $query = sprintf('MATCH (n:%s) WHERE id(n) = {%s} RETURN n', $label, 'id');
        $result = $this->entityManager->getDatabaseDriver()->run($query, ['id' => $id]);

        if ($result->size() > 0) {
            $node = $result->firstRecord()->nodeValue('n');
            $this->entityManager->getEntityHydrator($this->className)->refresh($node, $entity);
        }
    }
380881
public function populate($id)
    {
        if (empty($id)) {
            throw new EntityException('No messages id supplied', EntityException::NO_MESSAGE_ID_SUPPLIED);
        }

        $this->sendApiCall(self::ACTION_RETRIEVE, $this->getCreateUrl() . '/' . $id);
    }
967859
public function getConnection($id = null)
    {
        if (null === $id) {
            $result = self::$connection;

        } else {
            if (false === isset(self::$connection[$id])) {
                throw new \Doozr_Exception(
                    sprintf(
                        'EntityManager connection with Id "%s" does not exist!',
                        $id
                    )
                );
            }

            $result = self::$connection[$id];
        }

        return $result;
    }
1157201
public function markEmailAsSent($id) {

        $emailMessage = $this->model->find($id);

        $emailMessage->sent = 1;

        return $emailMessage->save();
    }
54500
public function emailAction(Request $request, $id)
    {
        $em = $this->getDoctrine()->getManager();
        /** @var Newsletter $entity */
        $entity = $em->getRepository('CoreBundle:BaseActor')->find($id);
        
        $form = $this->createForm(ActorEmailType::class, null, array('email' => $entity->getEmail()));
       
        if($request->getMethod() == 'POST'){
            $form->handleRequest($request);

            if ($form->isValid()) {
                //Get params
                $data = $form->getData();
                $email = $data['email'];            
                if($entity->getEmail() == $email){
                    
                    $news = new Newsletter();
                    $news->setTitle($data['subject']);
                    $news->setBody($data['body']);
                    $news->setActive(true);
                    $em->persist($news);
                    
                    $shipping = new NewsletterShipping();
                    $shipping->setNewsletter($news);
                    $shipping->setActor($entity);
                    $shipping->setTotalSent(1);
                    $shipping->setType(NewsletterShipping::TYPE_PERSONAL);
                    $em->persist($shipping);
                    $em->flush();
                    
                    $this->get('core.mailer')->sendActorEmail($email, $data['subject'], $data['body']);
                    
                    //if come from popup
                    if ($request->isXMLHttpRequest()) {         
                        return new JsonResponse(array(
                                    'id' => $shipping->getId()
                                ));
                    }

                    $this->get('session')->getFlashBag()->add('success', 'user.email.created');
                    return $this->redirect($this->generateUrl('core_baseactor_show', array('id' => $entity->getId())));
                }

            }
        }

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
1345420
protected function _post($id = null)
    {
        $subject = $this->_subject();
        $subject->set(['id' => $id]);

        $entity = $this->_findRecord($id, $subject);

        $event = $this->_trigger('beforeDelete', $subject);
        if ($event->isStopped()) {
            return $this->_stopped($subject);
        }

        $method = $this->getConfig('deleteMethod');
        if ($this->_table()->$method($entity)) {
            $this->_success($subject);
        } else {
            $this->_error($subject);
        }

        return $this->_redirect($subject, ['action' => 'index']);
    }
362784
public function actionSend($id)
    {
        $message = Message::findOne($id);
        if ($message !== null) {
            try {
                $message->status = $this->send($message) > 0 ? Message::STATUS_SUCCESS : Message::STATUS_ERROR;
                $message->save(true, ['status']);
            } catch (\Exception $e) {
                $message->status = Message::STATUS_ERROR;
                $message->save(true, ['status']);
                $this->stderr($e->getMessage());
            }
        } else {
            $this->stdout("Message not found\n");
            exit(1);
        }
    }
1341083
protected function doProcess($input, array &$messages)
    {
        if (is_string($input) && strpos($input, EntityCollection::ENTITY_WITHOUT_ID_PREFIX) === 0) {
            return $input;
        }

        if (is_int($input) || ctype_digit($input)) {
            return (int)$input;
        }

        $messages[] = new Message(ObjectIdValidator::MESSAGE);

        return null;
    }
541800
public function smtpGetEmailInfoById($id)
    {
        if (empty($id)) {
            return $this->handleError('Empty id');
        }

        $requestResult = $this->sendRequest('/smtp/emails/' . $id);

        return $this->handleResult($requestResult);
    }
344004
public function destroyFailedMessage($number, $message = null)
    {
        if (Lang::has('resource-controller.destroyfailed')) {
            return trans(
                'resource-controller.destroyfailed', [
                    'number' => $number,
                    'message' => $message
                ]
            );
        }

        return 'Operation failed while destroying the record '.$number.' with message: '.$message;
    }