This topic contains 5 replies, has 2 voices, and was last updated by Mike Kudelya 6 years, 11 months ago.
-
Topic
-
Hi,
I’m using OroPlatform 1.10.5 to perform some workflows. In one of my transition definitions, many post_actions are defined, like this :
12345678910batch_validated_definition:post_actions:- @send_email_validated:attribute: $subscriptionfrom: 'geoffroycochard@gmail.com'to: 'geoffroycochard@gmail.com'template: 'subscription_confirmation'entity: $.entity- @assign_value:[$status, 5]In my custom action @send_email_validated, it very similar to @send_email_template but with an attachment assignment, file generated through ImportExport service like this :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111/*** {@inheritdoc}*/protected function executeAction($context){$emailModel = $this->getEmailModel();$from = $this->getEmailAddress($context, $this->options['from']);$this->validateAddress($from);$emailModel->setFrom($from);$to = [];foreach ($this->options['to'] as $email) {if ($email) {$address = $this->getEmailAddress($context, $email);$this->validateAddress($address);$to[] = $this->getEmailAddress($context, $address);}}$emailModel->setTo($to);$entity = $this->contextAccessor->getValue($context, $this->options['entity']);$template = $this->contextAccessor->getValue($context, $this->options['template']);$emailTemplate = $this->objectManager->getRepository('OroEmailBundle:EmailTemplate')->findByName($template);if (!$emailTemplate) {$errorMessage = sprintf('Template "%s" not found.', $template);$this->logger->error('Workflow send email action.' . $errorMessage);throw new EntityNotFoundException($errorMessage);}$templateData = $this->renderer->compileMessage($emailTemplate, ['entity' => $entity]);list ($subjectRendered, $templateRendered) = $templateData;$emailModel->setSubject($subjectRendered);$emailModel->setBody($templateRendered);$emailModel->setType($emailTemplate->getType());$attachmentEntity = $this->getEmailAttachmentEntity($entity);$emailModel->addAttachment($attachmentEntity);$emailUser = $this->emailProcessor->process($emailModel,$this->emailProcessor->getEmailOrigin($emailModel->getFrom(), $emailModel->getOrganization()));if (array_key_exists('attribute', $this->options)) {$this->contextAccessor->setValue($context, $this->options['attribute'], $emailUser->getEmail());}}/*** @param string $email** @throws \Symfony\Component\Validator\Exception\ValidatorException*/protected function validateAddress($email){$emailConstraint = new EmailConstraints();$emailConstraint->message = 'Invalid email address';if ($email) {$errorList = $this->validator->validate($email,$emailConstraint);if ($errorList && $errorList->count() > 0) {throw new ValidatorException($errorList->get(0)->getMessage());}}}protected function getEmailAttachmentEntity(Subscription $subscription){#TODO : check error from export handler// Export xlsx$options = ['filters' => ['codeBroker' => [$subscription->getCodeBroker()->getId()],'status' => ['comparator' => 'lte','value' => 5]]];$handler = $this->exportHandler->getExportResult('dawkins_subscription_export_to_xlsx','dawkins_subscription_subscription','export','xlsx',null,$options);// Get fileName$a = explode('/', $handler['url']);$fileName = end($a);// $fileName = 'dawkins_subscription_subscription_2016_10_11_21_12_54_57fd55d6d6bb3.xlsx';$fullFileName = $this->fileSystemOperator->getTemporaryFile($fileName)->getRealPath();$uploadedFile = new UploadedFile($fullFileName, $fileName);$emailAttachment = $this->emailAttachmentTransformer->entityFromUploadedFile($uploadedFile);$emailBody = new EmailBody();$emailAttachment->setEmailBody($emailBody);return $this->emailAttachmentTransformer->entityToModel($emailAttachment);}When i use ImportExport service in my custom post_actions,@assign_value and transit don’t seem executed (no database update) and when i don’t use ImportExport->handler service transition work.
Is something in ImportExport->handler() service like manager->flush / clear, getting wrong in post_action execution ?
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.