/** * @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); } }
/** * @dataProvider visibilityDataProvider * @param string $visibility * @param bool $expected */ public function testChecksVisibilityFromConfig($visibility, $expected) { $this->configManager->expects($this->once())->method('get')->with('orob2b_product.default_visibility')->willReturn($visibility); $product = $this->getProductMock(); $product->expects($this->once())->method('getVisibility')->willReturn(Product::VISIBILITY_BY_CONFIG); $this->assertEquals($expected, $this->service->isVisible($product)); }
/** * 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); } }
/** * @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); }
/** * {@inheritdoc} */ protected function setUp() { $this->record = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecordInterface'); $this->configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->configManager->expects($this->any())->method('get')->with('oro_b2b_rfp.default_request_status')->will($this->returnValue(self::CONFIG_DEFAULT_STATUS)); $this->actionPermissionProvider = new ActionPermissionProvider($this->configManager); }
/** * {@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]; }
/** * Set the current configuration * * @AclAncestor("oro_config_system") * * @return JsonResponse */ public function postAction(Request $request) { $this->configManager->save(json_decode($request->getContent(), true)); $data = json_decode($request->getContent(), true); file_put_contents($this->getMessagesFilePath(), $data['pim_ui___loading_messages']['value']); return $this->getAction(); }
/** * {@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]); }
/** * @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); }
/** * @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); }
public function testProcessEvent() { $user = new User(); $user->setId(1); $this->configManager->expects($this->once())->method('get')->with('diamante_desk.email_notification')->will($this->returnValue(true)); $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user)); $event = $this->event(); $this->notificationDeliveryManager->expects($this->once())->method('add')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\Notifications\\TicketNotification'), $this->attributeEqualTo('ticketUniqueId', $event->getAggregateId()), $this->attributeEqualTo('author', $user), $this->attributeEqualTo('headerText', $event->getHeaderText()), $this->attributeEqualTo('subject', $event->getSubject()), $this->attributeEqualTo('attachments', $event->attachments()), $this->attribute($this->logicalAnd($this->isInstanceOf('\\ArrayIterator'), $this->arrayHasKey('Description'), $this->contains('New Description')), 'changeList'))); $this->subscriber->processEvent($event); }
/** * 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); }
/** * @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)); }
/** * @dataProvider isFreshDataProvider * * @param array $configData * @param array $statisticData * @param string $langCode * @param bool $expectedResult */ public function testIsFresh(array $configData, array $statisticData, $langCode, $expectedResult) { $this->cm->expects($this->once())->method('get')->with($this->equalTo(TranslationStatusInterface::META_CONFIG_KEY))->will($this->returnValue($configData)); $this->sp->expects($this->once())->method('get')->will($this->returnValue($statisticData)); $result1 = $this->extension->isFresh($langCode); // second call should not fail expectation above // result should be cached $result2 = $this->extension->isFresh($langCode); $this->assertSame($result1, $result2); $this->assertSame($expectedResult, $result1); }
/** * 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; } }
/** * @dataProvider submitProvider * * @param AccountUser $defaultData * @param array $submittedData * @param AccountUser $expectedData * @param User $owner */ public function testSubmit($defaultData, array $submittedData, $expectedData, User $owner) { $this->configManager->expects($this->once())->method('get')->with('oro_b2b_account.default_account_owner')->willReturn(42); $repository = $this->assertUserRepositoryCall(); $repository->expects($this->once())->method('find')->with(42)->willReturn($owner); $form = $this->factory->create($this->formType, $defaultData, []); $this->assertEquals($defaultData, $form->getData()); $form->submit($submittedData); $this->assertTrue($form->isValid()); $this->assertEquals($expectedData, $form->getData()); }
/** * 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; } }
/** * @param bool $expected * @param [] $data * @param bool $configSyncEnabled * @param int $configSyncMaxSize * * @dataProvider addAttachmentProvider */ public function testAddAttachment($expected, $data, $configSyncEnabled, $configSyncMaxSize) { $this->emailBodyBuilder->setEmailBody('test', true); $this->configManager->expects($this->at(0))->method('get')->with(EmailBodyBuilder::ORO_EMAIL_ATTACHMENT_SYNC_ENABLE)->willReturn($configSyncEnabled); if ($configSyncEnabled) { $this->configManager->expects($this->at(1))->method('get')->with(EmailBodyBuilder::ORO_EMAIL_ATTACHMENT_SYNC_MAX_SIZE)->willReturn($configSyncMaxSize); } $this->emailBodyBuilder->addEmailAttachment('test', 'content', 'ct', $data['contentTransferEncoding'], $data['embeddedContentId'], $data['contentSize']); $body = $this->emailBodyBuilder->getEmailBody(); $this->assertEquals($expected, $body->getHasAttachments()); }
/** * @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; }
/** * 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); }
/** * 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(); }
/** * @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)); }
/** * 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; }
/** * 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; }
protected function setUp() { $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->entityPool = $this->getMockBuilder('Oro\\Bundle\\NotificationBundle\\Doctrine\\EntityPool')->disableOriginalConstructor()->getMock(); $this->emailRenderer = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailRenderer')->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMockBuilder('Swift_Mailer')->disableOriginalConstructor()->getMock(); $this->cm = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->cm->expects($this->any())->method('get')->will($this->returnValueMap([['oro_notification.email_notification_sender_email', false, false, self::TEST_SENDER_EMAIL], ['oro_notification.email_notification_sender_name', false, false, self::TEST_SENDER_NAME]])); $this->processor = new EmailNotificationProcessor($this->logger, $this->entityManager, $this->entityPool, $this->emailRenderer, $this->mailer, $this->cm); $this->processor->setEnv(self::TEST_ENV); $this->processor->setMessageLimit(self::TEST_MESSAGE_LIMIT); }