Esempio n. 1
0
 /**
  * @param string          $dataClass Parent entity class name
  * @param File|Attachment $entity    File entity
  * @param string          $fieldName Field name where new file/image field was added
  *
  * @return \Symfony\Component\Validator\ConstraintViolationListInterface
  */
 public function validate($dataClass, $entity, $fieldName = '')
 {
     /** @var Config $entityAttachmentConfig */
     if ($fieldName === '') {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass);
         $mimeTypes = $this->getMimeArray($entityAttachmentConfig->get('mimetypes'));
         if (!$mimeTypes) {
             $mimeTypes = array_merge($this->getMimeArray($this->config->get('oro_attachment.upload_file_mime_types')), $this->getMimeArray($this->config->get('oro_attachment.upload_image_mime_types')));
         }
     } else {
         $entityAttachmentConfig = $this->attachmentConfigProvider->getConfig($dataClass, $fieldName);
         /** @var FieldConfigId $fieldConfigId */
         $fieldConfigId = $entityAttachmentConfig->getId();
         if ($fieldConfigId->getFieldType() === 'file') {
             $configValue = 'upload_file_mime_types';
         } else {
             $configValue = 'upload_image_mime_types';
         }
         $mimeTypes = $this->getMimeArray($this->config->get('oro_attachment.' . $configValue));
     }
     $fileSize = $entityAttachmentConfig->get('maxsize') * 1024 * 1024;
     foreach ($mimeTypes as $id => $value) {
         $mimeTypes[$id] = trim($value);
     }
     return $this->validator->validate($entity->getFile(), [new FileConstraint(['maxSize' => $fileSize, 'mimeTypes' => $mimeTypes])]);
 }
 /**
  * Applies the given notifications to the given object
  *
  * @param mixed                        $object
  * @param EmailNotificationInterface[] $notifications
  * @param LoggerInterface              $logger Override for default logger. If this parameter is specified
  *                                             this logger will be used instead of a logger specified
  *                                             in the constructor
  */
 public function process($object, $notifications, LoggerInterface $logger = null)
 {
     if (!$logger) {
         $logger = $this->logger;
     }
     foreach ($notifications as $notification) {
         $emailTemplate = $notification->getTemplate();
         try {
             list($subjectRendered, $templateRendered) = $this->renderer->compileMessage($emailTemplate, ['entity' => $object]);
         } catch (\Twig_Error $e) {
             $identity = method_exists($emailTemplate, '__toString') ? (string) $emailTemplate : $emailTemplate->getSubject();
             $logger->error(sprintf('Rendering of email template "%s" failed. %s', $identity, $e->getMessage()), ['exception' => $e]);
             continue;
         }
         $senderEmail = $this->cm->get('oro_notification.email_notification_sender_email');
         $senderName = $this->cm->get('oro_notification.email_notification_sender_name');
         if ($notification instanceof SenderAwareEmailNotificationInterface && $notification->getSenderEmail()) {
             $senderEmail = $notification->getSenderEmail();
             $senderName = $notification->getSenderName();
         }
         if ($emailTemplate->getType() == 'txt') {
             $type = 'text/plain';
         } else {
             $type = 'text/html';
         }
         foreach ((array) $notification->getRecipientEmails() as $email) {
             $message = \Swift_Message::newInstance()->setSubject($subjectRendered)->setFrom($senderEmail, $senderName)->setTo($email)->setBody($templateRendered, $type);
             $this->mailer->send($message);
         }
         $this->addJob(self::SEND_COMMAND);
     }
 }
 /**
  * @param string $name
  * @return array|string
  */
 protected function getConfigValue($name)
 {
     if (!$this->configManager) {
         $this->configManager = $this->container->get('oro_config.manager');
     }
     return $this->configManager->get($name);
 }
 /**
  * Applies the given notifications to the given object
  *
  * @param mixed                        $object
  * @param EmailNotificationInterface[] $notifications
  * @param LoggerInterface              $logger Override for default logger. If this parameter is specified
  *                                             this logger will be used instead of a logger specified
  *                                             in the constructor
  */
 public function process($object, $notifications, LoggerInterface $logger = null)
 {
     if (!$logger) {
         $logger = $this->logger;
     }
     foreach ($notifications as $notification) {
         /** @var EmailTemplate $emailTemplate */
         $emailTemplate = $notification->getTemplate();
         try {
             list($subjectRendered, $templateRendered) = $this->renderer->compileMessage($emailTemplate, array('entity' => $object));
         } catch (\Twig_Error $e) {
             $logger->error(sprintf('Rendering of email template "%s"%s failed. %s', $emailTemplate->getSubject(), method_exists($emailTemplate, 'getId') ? sprintf(' (id: %d)', $emailTemplate->getId()) : '', $e->getMessage()), array('exception' => $e));
             continue;
         }
         $senderEmail = $this->cm->get('oro_notification.email_notification_sender_email');
         $senderName = $this->cm->get('oro_notification.email_notification_sender_name');
         $type = $emailTemplate->getType() == 'txt' ? 'text/plain' : 'text/html';
         $recipients = $notification->getRecipientEmails();
         foreach ((array) $recipients as $email) {
             $message = \Swift_Message::newInstance()->setSubject($subjectRendered)->setFrom($senderEmail, $senderName)->setTo($email)->setBody($templateRendered, $type);
             $this->mailer->send($message);
         }
         $this->addJob(self::SEND_COMMAND);
     }
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $defaultWysiwygOptions = ['plugins' => ['textcolor', 'code', 'link', 'bdesk_photo'], 'toolbar_type' => self::TOOLBAR_DEFAULT, 'skin_url' => 'bundles/oroform/css/tinymce', 'valid_elements' => implode(',', $this->htmlTagProvider->getAllowedElements()), 'menubar' => false, 'statusbar' => false, 'relative_urls' => false, 'remove_script_host' => false, 'convert_urls' => true];
     $defaults = ['wysiwyg_enabled' => (bool) $this->configManager->get('oro_form.wysiwyg_enabled'), 'wysiwyg_options' => $defaultWysiwygOptions, 'page-component' => ['module' => 'oroui/js/app/components/view-component', 'options' => ['view' => 'oroform/js/app/views/wysiwig-editor/wysiwyg-editor-view', 'content_css' => 'bundles/oroform/css/wysiwyg-editor.css']]];
     $resolver->setDefaults($defaults);
     $resolver->setNormalizers(['wysiwyg_options' => function (Options $options, $wysiwygOptions) use($defaultWysiwygOptions) {
         if (empty($wysiwygOptions['toolbar_type']) || !array_key_exists($wysiwygOptions['toolbar_type'], $this->toolbars)) {
             $toolbarType = self::TOOLBAR_DEFAULT;
         } else {
             $toolbarType = $wysiwygOptions['toolbar_type'];
         }
         $wysiwygOptions['toolbar'] = $this->toolbars[$toolbarType];
         $wysiwygOptions = array_merge($defaultWysiwygOptions, $wysiwygOptions);
         unset($wysiwygOptions['toolbar_type']);
         return $wysiwygOptions;
     }, 'attr' => function (Options $options, $attr) {
         $pageComponent = $options->get('page-component');
         $wysiwygOptions = (array) $options->get('wysiwyg_options');
         if ($this->assetHelper) {
             if (!empty($pageComponent['options']['content_css'])) {
                 $pageComponent['options']['content_css'] = $this->assetHelper->getUrl($pageComponent['options']['content_css']);
             }
             if (!empty($wysiwygOptions['skin_url'])) {
                 $wysiwygOptions['skin_url'] = $this->assetHelper->getUrl($wysiwygOptions['skin_url']);
             }
         }
         $pageComponent['options'] = array_merge($pageComponent['options'], $wysiwygOptions);
         $pageComponent['options']['enabled'] = (bool) $options->get('wysiwyg_enabled');
         $attr['data-page-component-module'] = $pageComponent['module'];
         $attr['data-page-component-options'] = json_encode($pageComponent['options']);
         return $attr;
     }]);
 }
 /**
  * Check whenever given language package up to date
  *
  * @param string $languageCode
  *
  * @return bool
  */
 public function isFresh($languageCode)
 {
     if (!isset($this->processedLanguages[$languageCode])) {
         $configData = $this->cm->get(TranslationStatusInterface::META_CONFIG_KEY);
         $stats = $this->statisticProvider->get();
         if (isset($configData[$languageCode])) {
             $stats = array_filter($stats, function ($langInfo) use($languageCode) {
                 return $langInfo['code'] === $languageCode;
             });
             $lang = array_pop($stats);
             if ($lang) {
                 $installationDate = $this->getDateTimeFromString($configData[$languageCode]['lastBuildDate']);
                 $currentBuildDate = $this->getDateTimeFromString($lang['lastBuildDate']);
                 $this->processedLanguages[$languageCode] = $installationDate >= $currentBuildDate;
             } else {
                 // could not retrieve current language stats, so assume that it's fresh
                 $this->processedLanguages[$languageCode] = true;
             }
         } else {
             // if we do not have information about installed time then assume that needs update
             $this->processedLanguages[$languageCode] = false;
         }
     }
     return $this->processedLanguages[$languageCode];
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $isWysiwygEnabled = $this->configManager->get('oro_form.wysiwyg_enabled');
     $resolver->setDefaults(['translatable_class' => 'Oro\\Bundle\\EmailBundle\\Entity\\EmailTemplate', 'intention' => 'emailtemplate_translation', 'extra_fields_message' => 'This form should not contain extra fields: "{{ extra_fields }}"', 'cascade_validation' => true, 'labels' => [], 'content_options' => [], 'subject_options' => [], 'fields' => function (Options $options) use($isWysiwygEnabled) {
         return ['subject' => array_merge(['field_type' => 'text'], $options->get('subject_options')), 'content' => array_merge(['field_type' => 'oro_rich_text', 'attr' => ['class' => 'template-editor', 'data-wysiwyg-enabled' => $isWysiwygEnabled], 'wysiwyg_options' => ['height' => '250px']], $options->get('content_options'))];
     }]);
 }
 public function isDefaultBranch(Branch $branch)
 {
     $defaultBranchId = $this->manager->get('diamante_email_processing.default_branch');
     if (empty($defaultBranchId)) {
         return false;
     }
     return (int) $defaultBranchId === $branch->getId();
 }
 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('name', 'text', ['label' => 'orob2b.rfp.requeststatus.name.label', 'required' => true])->add('sortOrder', 'integer', ['label' => 'orob2b.rfp.requeststatus.sort_order.label', 'required' => true]);
     $lang = $this->localeSettings->getLanguage();
     $notificationLangs = $this->userConfig->get('oro_locale.languages');
     $notificationLangs = array_unique(array_merge($notificationLangs, [$lang]));
     $localeLabels = $this->localeSettings->getLocalesByCodes($notificationLangs, $lang);
     $builder->add('translations', 'orob2b_rfp_request_status_translation', ['label' => 'orob2b.rfp.requeststatus.label.label', 'required' => false, 'locales' => $notificationLangs, 'labels' => $localeLabels]);
 }
Esempio n. 10
0
 /**
  * @param array $result
  * @param bool  $addValue
  */
 protected function addApplicationUrl(array &$result, $addValue)
 {
     if ($addValue) {
         $val = $this->configManager->get('oro_ui.application_url');
     } else {
         $val = ['type' => 'string', 'label' => $this->translator->trans('oro.email.emailtemplate.app_url')];
     }
     $result['appURL'] = $val;
 }
 /**
  * Modify menu by adding, removing or editing items.
  *
  * @param \Knp\Menu\ItemInterface $menu
  * @param array                   $options
  * @param string|null             $alias
  */
 public function build(ItemInterface $menu, array $options = array(), $alias = null)
 {
     $options['orderBy'] = array(array('field' => NavigationHistoryItem::NAVIGATION_HISTORY_COLUMN_VISIT_COUNT));
     $maxItems = $this->configOptions->get('oro_navigation.maxItems');
     if (!is_null($maxItems)) {
         $options['maxItems'] = $maxItems;
     }
     parent::build($menu, $options, $alias);
 }
Esempio n. 12
0
 /**
  * @param UserInterface $user
  * @param array         $templateData
  * @param string        $type
  *
  * @return int          The return value is the number of recipients who were accepted for delivery
  */
 protected function sendEmail(UserInterface $user, array $templateData, $type)
 {
     list($subjectRendered, $templateRendered) = $templateData;
     $senderEmail = $this->configManager->get('oro_notification.email_notification_sender_email');
     $senderName = $this->configManager->get('oro_notification.email_notification_sender_name');
     $email = $this->emailHolderHelper->getEmail($user);
     $message = \Swift_Message::newInstance()->setSubject($subjectRendered)->setFrom($senderEmail, $senderName)->setTo($email)->setBody($templateRendered, $type);
     return $this->mailer->send($message);
 }
Esempio n. 13
0
 /**
  * Preset default values if default checkbox set
  *
  * @param FormEvent $event
  */
 public function preSubmit(FormEvent $event)
 {
     $data = $event->getData();
     foreach ($data as $key => $val) {
         if (!empty($val['use_parent_scope_value'])) {
             $data[$key]['value'] = $this->configManager->get(str_replace(ConfigManager::SECTION_VIEW_SEPARATOR, ConfigManager::SECTION_MODEL_SEPARATOR, $key), true);
         }
     }
     $event->setData($data);
 }
 /**
  * Get the current configuration
  *
  * @AclAncestor("oro_config_system")
  *
  * @return JsonResponse
  */
 public function getAction()
 {
     $data = [];
     foreach ($this->options as $option) {
         $viewKey = $option['section'] . ConfigManager::SECTION_VIEW_SEPARATOR . $option['name'];
         $modelKey = $option['section'] . ConfigManager::SECTION_MODEL_SEPARATOR . $option['name'];
         $data[$viewKey] = ['value' => $this->configManager->get($modelKey), 'scope' => 'app', 'use_parent_scope_value' => false];
     }
     return new JsonResponse($data);
 }
 /**
  * Configure credentials
  *
  * @param ConfigManager $configManager
  */
 public function configureCredentials(ConfigManager $configManager)
 {
     $clientIdKey = sprintf('oro_sso.%s_sso_client_id', $this->getName());
     if ($clientId = $configManager->get($clientIdKey)) {
         $this->options['client_id'] = $clientId;
     }
     $clientSecretKey = sprintf('oro_sso.%s_sso_client_secret', $this->getName());
     if ($clientSecret = $configManager->get($clientSecretKey)) {
         $this->options['client_secret'] = $clientSecret;
     }
 }
 /**
  * @return RequestContext
  */
 private function updateRequestContext()
 {
     $url = $this->config->get('oro_ui.application_url');
     if (empty($url)) {
         throw new \RuntimeException('No Application URL configured, unable to generate links');
     }
     $context = $this->router->getContext();
     $origContext = clone $context;
     $this->setUrlInContext($url, $context);
     return $origContext;
 }
 /**
  * Get the current configuration
  *
  * @AclAncestor("oro_config_system")
  *
  * @return JsonResponse
  */
 public function getAction()
 {
     $data = [];
     foreach ($this->options as $option) {
         $viewKey = $option['section'] . ConfigManager::SECTION_VIEW_SEPARATOR . $option['name'];
         $modelKey = $option['section'] . ConfigManager::SECTION_MODEL_SEPARATOR . $option['name'];
         $value = $option['name'] === 'loading_messages' ? file_get_contents($this->getMessagesFilePath()) : $this->configManager->get($modelKey);
         $data[$viewKey] = ['value' => $value, 'scope' => 'app', 'use_parent_scope_value' => false];
     }
     return new JsonResponse($data);
 }
 /**
  * Configure credentials
  *
  * @param ConfigManager $configManager
  */
 public function configureCredentials(ConfigManager $configManager)
 {
     $clientIdKey = 'oro_google_integration.client_id';
     if ($clientId = $configManager->get($clientIdKey)) {
         $this->options['client_id'] = $clientId;
     }
     $clientSecretKey = 'oro_google_integration.client_secret';
     if ($clientSecret = $configManager->get($clientSecretKey)) {
         $this->options['client_secret'] = $clientSecret;
     }
 }
 /**
  * @param string $colorSchema
  *
  * @return mixed
  *
  * @throws \RuntimeException if the given color schema is unknown
  */
 protected function getColors($colorSchema)
 {
     if (isset(static::$colorSchema[$colorSchema])) {
         return static::$colorSchema[$colorSchema]['colors'];
     }
     $colors = $this->configManager->get($colorSchema);
     if ($colors) {
         return array_combine($colors, $colors);
     }
     throw new \RuntimeException(sprintf('Unknown color schema: "%s".', $colorSchema));
 }
Esempio n. 20
0
 /**
  * Gets all configuration data of the specified section
  *
  * @param string $path The path to API section. For example: look-and-feel/grid
  *
  * @return array
  */
 public function getData($path)
 {
     $variables = $this->configProvider->getApiTree($path)->getVariables(true);
     $result = [];
     foreach ($variables as $variable) {
         $var = $variable->toArray();
         $var['value'] = $this->configManager->get($variable->getKey());
         $var = array_merge($var, $this->configManager->getInfo($variable->getKey()));
         $result[] = $var;
     }
     return $result;
 }
 /**
  * Get default channels for new products.
  * @return array $qb
  */
 public function getDefaultChannels()
 {
     $config = $this->configManager->get('marello_sales.default_channels');
     if (!$config) {
         return [];
     }
     $defaultChannels = [];
     foreach ($config as $channel) {
         $defaultChannels[] = $channel->getName();
     }
     return $this->em->getRepository('MarelloSalesBundle:SalesChannel')->createQueryBuilder('sc')->where('sc.name IN(:channels)')->setParameter('channels', $defaultChannels)->orderBy('sc.name', 'ASC')->getQuery()->getResult();
 }
Esempio n. 22
0
 /**
  * @return array
  */
 protected function getLanguageChoices()
 {
     // ensure that default value is always in choice list
     $defaultValue = $this->cm->get(self::CONFIG_KEY, true);
     $availableTranslations = (array) $this->cm->get(TranslationStatusInterface::CONFIG_KEY);
     $availableTranslations = array_filter($availableTranslations, function ($languageStatus) {
         return $languageStatus === TranslationStatusInterface::STATUS_ENABLED;
     });
     $availableLanguages = array_merge(array_keys($availableTranslations), [$defaultValue]);
     $allLanguages = Intl::getLocaleBundle()->getLocaleNames('en');
     return array_intersect_key($allLanguages, array_flip($availableLanguages));
 }
Esempio n. 23
0
 /**
  * Checks if the given template contains several parts and if so translate each part individually
  *
  * @param string $titleTemplate
  * @param array  $params
  *
  * @return string
  */
 public function trans($titleTemplate, array $params = [])
 {
     if (!$titleTemplate) {
         return $titleTemplate;
     }
     $delimiter = ' ' . $this->userConfigManager->get('oro_navigation.title_delimiter') . ' ';
     $transItems = explode($delimiter, $titleTemplate);
     foreach ($transItems as $key => $transItem) {
         $transItems[$key] = $this->translator->trans($transItem, $params);
     }
     return implode($delimiter, $transItems);
 }
Esempio n. 24
0
 /**
  * Returns if given email can be used for oauth
  *
  * @param string $email
  *
  * @return boolean
  */
 protected function isEmailEnabledForOauth($email)
 {
     $enabledDomains = $this->cm->get('oro_sso.google_sso_domains');
     if (!$enabledDomains) {
         return true;
     }
     foreach ($enabledDomains as $enabledDomain) {
         if (preg_match(sprintf('/@%s$/', $enabledDomain), $email)) {
             return true;
         }
     }
     return false;
 }
 private function updateRequestContext()
 {
     $url = $this->config->get('oro_ui.application_url');
     if (empty($url)) {
         throw new \RuntimeException('No Application URL configured, unable to generate links');
     }
     list($scheme, $host, $baseUrl) = $this->getUrlParts($url);
     $context = $this->router->getContext();
     $context->setScheme($scheme);
     $context->setHost($host);
     if (!empty($baseUrl)) {
         $context->setBaseUrl($baseUrl);
     }
 }
Esempio n. 26
0
 /**
  * @param EmailModel $emailModel
  */
 protected function applySignature(EmailModel $emailModel)
 {
     $signature = $this->configManager->get('oro_email.signature');
     if ($signature) {
         $emailModel->setSignature($signature);
     }
 }
Esempio n. 27
0
 /**
  * @return string
  */
 protected function getSenderName()
 {
     if ($senderName = $this->emailCampaign->getSenderName()) {
         return $senderName;
     }
     return $this->configManager->get('oro_crm_campaign.campaign_sender_name');
 }
 /**
  * @param Notification $notification
  *
  * @return \Swift_Message
  */
 private function message(Notification $notification)
 {
     /** @var \Swift_Message $message */
     $message = $this->mailer->createMessage();
     $message->setSubject(ucfirst($notification->getHeaderText()));
     $senderName = $this->configManager->get('oro_notification.email_notification_sender_name');
     $message->setFrom($this->senderEmail, $senderName);
     $mail = $notification->getAuthor()->getEmail();
     $message->setTo($mail);
     $options = array('user' => $this->getFormattedUserName($notification), 'header' => $notification->getHeaderText());
     $txtTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_TXT);
     $htmlTemplate = $this->templateResolver->resolve($notification, TemplateResolver::TYPE_HTML);
     $message->setBody($this->twig->render($txtTemplate, $options), 'text/plain');
     $message->addPart($this->twig->render($htmlTemplate, $options), 'text/html');
     return $message;
 }
Esempio n. 29
0
 public function testGetEmptyValueSettings()
 {
     $parameterName = 'oro_test.emptystring';
     $this->userScopeManager->expects($this->once())->method('getSettingValue')->with($parameterName, false)->willReturn('');
     $this->globalScopeManager->expects($this->never())->method('getSettingValue');
     $this->assertEquals('', $this->manager->get($parameterName));
 }
 /**
  * @param Message $message
  * @param Ticket $ticket
  */
 private function processWatchers(Message $message, $ticket)
 {
     if (!$ticket) {
         return;
     }
     /** @var Message\MessageRecipient $recipient */
     foreach ($message->getRecipients() as $recipient) {
         $email = $recipient->getEmail();
         if ($email == $this->configManager->get(self::EMAIL_NOTIFIER_CONFIG_PATH)) {
             continue;
         }
         $diamanteUser = $this->diamanteUserRepository->findUserByEmail($email);
         $oroUser = $this->oroUserManager->findUserByEmail($email);
         if ($oroUser) {
             $user = new User($oroUser->getId(), User::TYPE_ORO);
         } elseif ($diamanteUser) {
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         } else {
             $diamanteUser = $this->diamanteUserFactory->create($email, $recipient->getFirstName(), $recipient->getLastName());
             $this->diamanteUserRepository->store($diamanteUser);
             $user = new User($diamanteUser->getId(), User::TYPE_DIAMANTE);
         }
         $this->watchersService->addWatcher($ticket, $user);
     }
 }