/** * get listeners for the named queue * * @param string $queueName * @return array<Tx_Amqp_Messaging_ConsumerInterface> * @throws InvalidArgumentException */ protected function getConsumers($queueName) { $consumerConfigurations = Tx_Amqp_Util_ConfigurationHelper::getRegisteredConsumerConfiguration($queueName); $consumers = array(); foreach ($consumerConfigurations as $key => $consumerConfiguration) { $className = trim($consumerConfiguration['className']); $consumerInstance = $this->objectManager->get($className); if (!$consumerInstance instanceof Tx_Amqp_Messaging_ConsumerInterface) { throw new InvalidArgumentException(sprintf('%s does not implement the Tx_Amqp_Messaging_ConsumerInterface interface', $className)); } $consumers[] = $consumerInstance; } return $consumers; }
/** * @param string $value * @return bool */ public function isValid($value) { if ($this->options['repository'] && $this->options['property']) { $repository = $this->objectManager->get($this->options['repository']); $methodName = 'countBy' . ucfirst($this->options['property']); $count = $repository->{$methodName}($value); if ($count == 0) { return true; } else { $this->addError($this->options['property'] . ' is not unique', 1398325655); return false; } } }
/** * Build the rendering context * @author Sebastian Kurfürst <*****@*****.**> */ protected function buildRenderingContext($templateVariables) { $variableContainer = $this->objectManager->create('Tx_Fluid_Core_ViewHelper_TemplateVariableContainer', $templateVariables); $renderingContext = $this->objectManager->create('Tx_Fluid_Core_Rendering_RenderingContext'); $viewHelperVariableContainer = $this->objectManager->create('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer'); if (method_exists($renderingContext, 'setTemplateVariableContainer')) { $renderingContext->setTemplateVariableContainer($variableContainer); $renderingContext->setViewHelperVariableContainer($viewHelperVariableContainer); } else { $renderingContext->injectTemplateVariableContainer($variableContainer); $renderingContext->injectViewHelperVariableContainer($viewHelperVariableContainer); } return $renderingContext; }
/** * Sets up this test case * * @return void */ public function setUp() { $this->view = $this->getAccessibleMock('Tx_Fluid_View_StandaloneView', array('dummy'), array(), '', FALSE); $this->mockTemplateParser = $this->getMock('Tx_Fluid_Core_Parser_TemplateParser'); $this->mockParsedTemplate = $this->getMock('Tx_Fluid_Core_Parser_ParsedTemplateInterface'); $this->mockTemplateParser->expects($this->any())->method('parse')->will($this->returnValue($this->mockParsedTemplate)); $this->mockConfigurationManager = $this->getMock('Tx_Extbase_Configuration_ConfigurationManagerInterface'); $this->mockObjectManager = $this->getMock('Tx_Extbase_Object_ObjectManager'); $this->mockObjectManager->expects($this->any())->method('get')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $this->mockObjectManager->expects($this->any())->method('create')->will($this->returnCallback(array($this, 'objectManagerCallback'))); $this->mockRequest = $this->getMock('Tx_Extbase_MVC_Web_Request'); $this->mockUriBuilder = $this->getMock('Tx_Extbase_MVC_Web_Routing_UriBuilder'); $this->mockFlashMessages = $this->getMock('Tx_Extbase_MVC_Controller_FlashMessages'); $this->mockContentObject = $this->getMock('tslib_cObj'); $this->mockControllerContext = $this->getMock('Tx_Extbase_MVC_Controller_ControllerContext'); $this->mockControllerContext->expects($this->any())->method('getRequest')->will($this->returnValue($this->mockRequest)); $this->mockViewHelperVariableContainer = $this->getMock('Tx_Fluid_Core_ViewHelper_ViewHelperVariableContainer'); $this->mockRenderingContext = $this->getMock('Tx_Fluid_Core_Rendering_RenderingContextInterface'); $this->mockRenderingContext->expects($this->any())->method('getControllerContext')->will($this->returnValue($this->mockControllerContext)); $this->mockRenderingContext->expects($this->any())->method('getViewHelperVariableContainer')->will($this->returnValue($this->mockViewHelperVariableContainer)); $this->view->injectTemplateParser($this->mockTemplateParser); $this->view->injectObjectManager($this->mockObjectManager); $this->view->setRenderingContext($this->mockRenderingContext); t3lib_div::setSingletonInstance('Tx_Extbase_Object_ObjectManager', $this->mockObjectManager); t3lib_div::addInstance('tslib_cObj', $this->mockContentObject); }
/** * Copies $sourceFilename to $destinationFilename, returns new filename * * @param mixed $sourceFile FileObjectStorage, File Resource or string filename * @param string $destinationFilename Destination filename or path * @throws Exception * @return mixed * @api */ public function copy($sourceFile, $destinationFilename) { $pathinfo = pathinfo($destinationFilename); if ($sourceFile instanceof Tx_Tool_Resource_FileResourceObjectStorage) { foreach ($sourceFile as $childFile) { $this->copy($childFile, $pathinfo['dirname']); } } elseif ($sourceFile instanceof Tx_Tool_Resource_FileResource) { $sourceFilename = $sourceFile->getAbsolutePath(); } else { $sourceFilename = $sourceFile; } if (is_file($sourceFilename) === FALSE) { $sourceFilename = PATH_site . $sourceFilename; } $fileFunctions = $this->objectManager->get('t3lib_basicFileFunctions'); $pathinfo = pathinfo($destinationFilename); $desiredFilename = $pathinfo['basename'] != '' ? $pathinfo['basename'] : basename($sourceFilename); $newFilename = $fileFunctions->getUniqueName($desiredFilename, $pathinfo['dirname']); $targetFile = $newFilename; $copied = copy($sourceFilename, $targetFile); if ($copied === FALSE) { throw new Exception('Could not copy file ' . $sourceFilename . ' to ' . $targetFile, 1311895454); } return $newFilename; }
/** * Sets storage objects by CSV relative to basePath * * @param string $csv */ public function attachFromCsv($csv) { foreach (explode(',', $csv) as $filename) { $object = $this->objectManager->get($this->objectType, $this->basePath . $filename); $this->attach($object); } }
public function syncAll() { $syncConfigs = $this->syncConfigurationRepository->findAll(); foreach ($syncConfigs as $syncConfig) { /** @var $syncConfig Tx_DlDropboxsync_Domain_Model_SyncConfiguration */ if ($syncConfig->getSyncType() == 'in') { $syncRun = $this->objectManager->get('Tx_DlDropboxsync_Domain_Dropbox_SyncRun_SyncIn'); /** @var $syncRun Tx_DlDropboxsync_Domain_Dropbox_SyncRun_SyncIn */ } else { $syncRun = $this->objectManager->get('Tx_DlDropboxsync_Domain_Dropbox_SyncRun_SyncOut'); /** @var $syncRun Tx_DlDropboxsync_Domain_Dropbox_SyncRun_SyncOut */ } $runInfo = $syncRun->setSyncConfiguration($syncConfig)->startSync(); $syncConfig->setLastSyncInfo(serialize($runInfo)); $this->syncConfigurationRepository->update($syncConfig); $this->persistenceManager->persistAll(); } }
/** * Initialize environment * * @return void */ protected function initialize() { // Dummy Extension configuration for Dispatcher $configuration = array('extensionName' => 'Randombanners', 'pluginName' => 'List'); // Get TypoScript configuration $setup = Tx_Randombanners_Utility_TypoScript::getSetup(); $this->settings = Tx_Randombanners_Utility_TypoScript::parse($setup['settings.'], FALSE); $configuration = array_merge($configuration, $setup); // Load Dispatcher $dispatcher = t3lib_div::makeInstance('Tx_Extbase_Core_Bootstrap'); $dispatcher->initialize($configuration); // Load required objects $this->objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager'); $this->bannerRepository = t3lib_div::makeInstance('Tx_Randombanners_Domain_Repository_BannerRepository'); $this->htmlMail = t3lib_div::makeInstance('t3lib_htmlmail'); $this->persistenceManager = $this->objectManager->get('Tx_Extbase_Persistence_Manager'); }
/** * Dispatch actions to take according to current bounce level */ public function dispatch() { $this->findEmail(); // If couldn't find the original email we cannot do anything if (!$this->email) { Tx_Newsletter_Tools::log("Bounced email found but cannot find corresponding record in database. Skipped.", 1); return; } if ($this->bounceLevel != self::NEWSLETTER_NOT_A_BOUNCE) { if ($this->recipientList) { $this->recipientList->registerBounce($this->email->getRecipientAddress(), $this->bounceLevel); } $this->email->setBounceTime(new DateTime()); $emailRepository = $this->objectManager->get('Tx_Newsletter_Domain_Repository_EmailRepository'); $emailRepository->updateNow($this->email); } Tx_Newsletter_Tools::log("Bounced email found with bounce level " . $this->bounceLevel); }
/** * Creates a new event * * @param Tx_CzSimpleCal_Domain_Model_Event $newEvent * @return void * @dontvalidate $newEvent */ public function createAction(Tx_CzSimpleCal_Domain_Model_Event $newEvent) { $this->abortOnMissingUser(); $this->setDefaults($newEvent); $newEvent->setCruserFe($this->getFrontendUserId()); $this->view->assign('newEvent', $newEvent); if ($this->isEventValid($newEvent)) { $this->eventRepository->add($newEvent); // persist event as the indexer needs an uid $this->objectManager->get('Tx_Extbase_Persistence_Manager')->persistAll(); // create index for event $this->getObjectManager()->get('Tx_CzSimpleCal_Indexer_Event')->create($newEvent); $this->flashMessageContainer->add(sprintf('The event "%s" was created.', $newEvent->getTitle()), '', t3lib_FlashMessage::OK); $this->clearCache(); $this->logEventLifecycle($newEvent, 1); $this->redirect('list'); } }
/** * Hydrate a category record with the given array * * @param array $importItem * @return Tx_News_Domain_Model_Category */ protected function hydrateCategory(array $importItem) { if (is_null($category = $this->categoryRepository->findOneByImportSourceAndImportId($importItem['import_source'], $importItem['import_id']))) { /** @var $category Tx_News_Domain_Model_Category */ $category = $this->objectManager->get('Tx_News_Domain_Model_Category'); $this->categoryRepository->add($category); } $category->setPid($importItem['pid']); $category->setHidden($importItem['hidden']); $category->setStarttime($importItem['starttime']); $category->setEndtime($importItem['endtime']); $category->setTitle($importItem['title']); $category->setDescription($importItem['description']); $category->setImage($importItem['image']); $category->setShortcut($importItem['shortcut']); $category->setSinglePid($importItem['single_pid']); $category->setImportId($importItem['import_id']); $category->setImportSource($importItem['import_source']); return $category; }
/** * Execute all checks * * @return void */ private function executeAllChecks() { $issues = 0; $registry = Tx_Smoothmigration_Service_Check_Registry::getInstance(); $checks = $registry->getActiveChecks(); /** @var Tx_Smoothmigration_Domain_Interface_Check $singleCheck */ foreach ($checks as $singleCheck) { $processor = $singleCheck->getProcessor(); $this->messageBus->headerMessage('Check: ' . $singleCheck->getTitle(), 'info'); $processor->execute(); foreach ($processor->getIssues() as $issue) { $this->issueRepository->add($issue); } $issues = $issues + count($processor->getIssues()); $this->messageBus->infoMessage(count($processor->getIssues()) . ' issues found'); } $persistenceManger = $this->objectManager->get('Tx_Extbase_Persistence_Manager'); $persistenceManger->persistAll(); $this->messageBus->infoMessage(LF . 'Total Issues : ' . $issues); }
/** * Gets the TCA-defined uploadfolder for $object. If no propertyName, then * all all properties with uploadfolders are returned as keys along with * their respective upload folders as value * @param mixed $object * @param string $propertyName * @return mixed * @api */ public function getUploadFolder($object, $propertyName = NULL) { if (is_object($object) === FALSE) { $className = $object; $object = $this->objectManager->get($className); } if ($propertyName === NULL) { $properties = Tx_Extbase_Reflection_ObjectAccess::getGettablePropertyNames($object); $folders = array(); foreach ($properties as $propertyName) { $uploadFolder = $this->getUploadFolder($object, $propertyName); if (is_dir(PATH_site . $uploadFolder)) { $folders[$propertyName] = $uploadFolder; } } return $folders; } $tableName = $this->getDatabaseTable($object); t3lib_div::loadTCA($tableName); $underscoredPropertyName = $this->convertCamelCaseToLowerCaseUnderscored($propertyName); $uploadFolder = $GLOBALS['TCA'][$tableName]['columns'][$underscoredPropertyName]['config']['uploadfolder']; return $uploadFolder; }
/** * @param Tx_News_Domain_Model_News $news * @param array $importItem * @param array $importItemOverwrite * @return Tx_News_Domain_Model_News */ protected function hydrateNewsRecord(Tx_News_Domain_Model_News $news, array $importItem, array $importItemOverwrite) { if (!empty($importItemOverwrite)) { $importItem = array_merge($importItem, $importItemOverwrite); } $news->setPid($importItem['pid']); $news->setHidden($importItem['hidden']); $news->setStarttime($importItem['starttime']); $news->setEndtime($importItem['endtime']); $news->setTitle($importItem['title']); $news->setTeaser($importItem['teaser']); $news->setBodytext($importItem['bodytext']); $news->setType($importItem['type']); $news->setKeywords($importItem['keywords']); $news->setDatetime(new DateTime(date('Y-m-d H:i:sP', $importItem['datetime']))); $news->setArchive(new DateTime(date('Y-m-d H:i:sP', $importItem['archive']))); $contentElementUidArray = Tx_Extbase_Utility_Arrays::trimExplode(',', $importItem['content_elements'], TRUE); foreach ($contentElementUidArray as $contentElementUid) { if (is_object($contentElement = $this->ttContentRepository->findByUid($contentElementUid))) { $news->addContentElement($contentElement); } } $news->setInternalurl($importItem['internalurl']); $news->setExternalurl($importItem['externalurl']); $news->setType($importItem['type']); $news->setKeywords($importItem['keywords']); $news->setAuthor($importItem['author']); $news->setAuthorEmail($importItem['author_email']); $news->setImportid($importItem['import_id']); $news->setImportSource($importItem['import_source']); if (is_array($importItem['categories'])) { foreach ($importItem['categories'] as $categoryUid) { if ($this->settings['findCategoriesByImportSource']) { $category = $this->categoryRepository->findOneByImportSourceAndImportId($this->settings['findCategoriesByImportSource'], $categoryUid); } else { $category = $this->categoryRepository->findByUid($categoryUid); } if ($category) { $news->addCategory($category); } } } /** @var $basicFileFunctions t3lib_basicFileFunctions */ $basicFileFunctions = t3lib_div::makeInstance('t3lib_basicFileFunctions'); // media relation if (is_array($importItem['media'])) { foreach ($importItem['media'] as $mediaItem) { if (!($media = $this->getMediaIfAlreadyExists($news, $mediaItem['image']))) { $uniqueName = $basicFileFunctions->getUniqueName($mediaItem['image'], PATH_site . self::UPLOAD_PATH); copy(PATH_site . $mediaItem['image'], $uniqueName); $media = $this->objectManager->get('Tx_News_Domain_Model_Media'); $news->addMedia($media); $media->setImage(basename($uniqueName)); } $media->setTitle($mediaItem['title']); $media->setAlt($mediaItem['alt']); $media->setCaption($mediaItem['caption']); $media->setType($mediaItem['type']); $media->setShowinpreview($mediaItem['showinpreview']); $media->setPid($importItem['pid']); } } // related files if (is_array($importItem['related_files'])) { foreach ($importItem['related_files'] as $file) { if (!($relatedFile = $this->getRelatedFileIfAlreadyExists($news, $file['file']))) { $uniqueName = $basicFileFunctions->getUniqueName($file['file'], PATH_site . self::UPLOAD_PATH); copy(PATH_site . $file['file'], $uniqueName); $relatedFile = $this->objectManager->get('Tx_News_Domain_Model_File'); $news->addRelatedFile($relatedFile); $relatedFile->setFile(basename($uniqueName)); } $relatedFile->setTitle($file['title']); $relatedFile->setDescription($file['description']); $relatedFile->setPid($importItem['pid']); } } if (is_array($importItem['related_links'])) { foreach ($importItem['related_links'] as $link) { /** @var $relatedLink Tx_News_Domain_Model_Link */ $relatedLink = $this->objectManager->get('Tx_News_Domain_Model_Link'); $relatedLink->setUri($link['uri']); $relatedLink->setTitle($link['title']); $relatedLink->setDescription($link['description']); $relatedLink->setPid($importItem['pid']); $news->addRelatedLink($relatedLink); } } return $news; }
/** * This is the main-function for sending Mails * * @param array $mail Array with all needed mail information * $mail['receiverName'] = 'Name'; * $mail['receiverEmail'] = '*****@*****.**'; * $mail['senderName'] = 'Name'; * $mail['senderEmail'] = '*****@*****.**'; * $mail['subject'] = 'Subject line'; * $mail['template'] = 'PathToTemplate/'; * $mail['rteBody'] = 'This is the <b>content</b> of the RTE'; * $mail['format'] = 'both'; // or plain or html * @param array $fields All arguments from POST or GET * @param array $settings TypoScript Settings * @param string $type Email to "sender" or "receiver" * @param Tx_Extbase_Object_ObjectManager $objectManager * @param object $configurationManager * @return boolean Mail was successfully sent? */ public function sendTemplateEmail($mail, $fields, $settings, $type, $objectManager, $configurationManager) { /***************** * Settings ****************/ $cObj = $configurationManager->getContentObject(); $typoScriptService = $objectManager->get('Tx_Extbase_Service_TypoScriptService'); $conf = $typoScriptService->convertPlainArrayToTypoScriptArray($settings); // parsing variables with fluid engine to allow viewhelpers and variables in some flexform fields $parse = array( 'receiverName', 'receiverEmail', 'senderName', 'senderEmail', 'subject' ); foreach ($parse as $value) { $mail[$value] = $this->fluidParseString($mail[$value], $objectManager, $this->getVariablesWithMarkers($fields)); } // Debug Output if ($settings['debug']['mail']) { t3lib_utility_Debug::debug($mail, 'powermail debug: Show Mail'); } // stop mail process if receiver or sender email is not valid if (!t3lib_div::validEmail($mail['receiverEmail']) || !t3lib_div::validEmail($mail['senderEmail'])) { return false; } // stop mail process if subject is empty if (empty($mail['subject'])) { return false; } // generate mail body $extbaseFrameworkConfiguration = $configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $templatePathAndFilename = t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['templateRootPath']) . $mail['template'] . '.html'; $emailView = $objectManager->create('Tx_Fluid_View_StandaloneView'); $emailView->getRequest()->setControllerExtensionName('Powermail'); // extension name for translate viewhelper $emailView->getRequest()->setPluginName('Pi1'); $emailView->getRequest()->setControllerName('Forms'); $emailView->setFormat('html'); $emailView->setTemplatePathAndFilename($templatePathAndFilename); $emailView->setPartialRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['partialRootPath'])); $emailView->setLayoutRootPath(t3lib_div::getFileAbsFileName($extbaseFrameworkConfiguration['view']['layoutRootPath'])); // get variables // additional variables if (isset($mail['variables']) && is_array($mail['variables'])) { $emailView->assignMultiple($mail['variables']); } // markers in HTML Template $variablesWithMarkers = $this->getVariablesWithMarkers($fields); $emailView->assign('variablesWithMarkers', $this->htmlspecialcharsOnArray($variablesWithMarkers)); $emailView->assignMultiple($variablesWithMarkers); // powermail_all $variables = $this->getVariablesWithLabels($fields); $content = $this->powermailAll($variables, $configurationManager, $objectManager, 'mail', $settings); $emailView->assign('powermail_all', $content); // from rte $emailView->assign('powermail_rte', $mail['rteBody']); $variablesWithLabels = $this->getVariablesWithLabels($fields); $emailView->assign('variablesWithLabels', $variablesWithLabels); $emailView->assign('marketingInfos', self::getMarketingInfos()); $emailBody = $emailView->render(); /***************** * generate mail ****************/ $message = t3lib_div::makeInstance('t3lib_mail_Message'); $message ->setTo(array($mail['receiverEmail'] => $mail['receiverName'])) ->setFrom(array($mail['senderEmail'] => $mail['senderName'])) ->setSubject($mail['subject']) ->setCharset($GLOBALS['TSFE']->metaCharset); // overwrite subject if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['subject'], $conf[$type . '.']['overwrite.']['subject.'])) { $message->setSubject($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['subject'], $conf[$type . '.']['overwrite.']['subject.'])); } // add cc receivers if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['cc'], $conf[$type . '.']['overwrite.']['cc.'])) { $ccArray = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['cc'], $conf[$type . '.']['overwrite.']['cc.']), 1); $message->setCc($ccArray); } // add bcc receivers if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['bcc'], $conf[$type . '.']['overwrite.']['bcc.'])) { $bccArray = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['bcc'], $conf[$type . '.']['overwrite.']['bcc.']), 1); $message->setBcc($bccArray); } // add Return Path if ($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['returnPath'], $conf[$type . '.']['overwrite.']['returnPath.'])) { $message->setReturnPath($cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['returnPath'], $conf[$type . '.']['overwrite.']['returnPath.'])); } // add Reply Addresses if ( $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToEmail'], $conf[$type . '.']['overwrite.']['replyToEmail.']) && $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToName'], $conf[$type . '.']['overwrite.']['replyToName.']) ) { $replyArray = array( $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToEmail'], $conf[$type . '.']['overwrite.']['replyToEmail.']) => $cObj->cObjGetSingle($conf[$type . '.']['overwrite.']['replyToName'], $conf[$type . '.']['overwrite.']['replyToName.']) ); $message->setReplyTo($replyArray); } // add priority if ($settings[$type]['overwrite']['priority']) { $message->setPriority(intval($settings[$type]['overwrite']['priority'])); } // add attachments from upload fields if ($settings[$type]['attachment']) { $uploadsFromSession = Tx_Powermail_Utility_Div::getSessionValue('upload'); // read upload session foreach ((array) $uploadsFromSession as $file) { $message->attach(Swift_Attachment::fromPath($file)); } } // add attachments from typoscript if ($cObj->cObjGetSingle($conf[$type . '.']['addAttachment'], $conf[$type . '.']['addAttachment.'])) { $files = t3lib_div::trimExplode(',', $cObj->cObjGetSingle($conf[$type . '.']['addAttachment'], $conf[$type . '.']['addAttachment.']), 1); foreach ($files as $file) { $message->attach(Swift_Attachment::fromPath($file)); } } if ($mail['format'] != 'plain') { $message->setBody($emailBody, 'text/html'); } if ($mail['format'] != 'html') { $message->addPart($this->makePlain($emailBody), 'text/plain'); } $message->send(); return $message->isSent(); }