protected function SendSynchronous(&$aIssues, $oLog = null) { $this->LoadConfig(); $sTransport = self::$m_oConfig->Get('email_transport'); switch ($sTransport) { case 'SMTP': $sHost = self::$m_oConfig->Get('email_transport_smtp.host'); $sPort = self::$m_oConfig->Get('email_transport_smtp.port'); $sEncryption = self::$m_oConfig->Get('email_transport_smtp.encryption'); $sUserName = self::$m_oConfig->Get('email_transport_smtp.username'); $sPassword = self::$m_oConfig->Get('email_transport_smtp.password'); $oTransport = Swift_SmtpTransport::newInstance($sHost, $sPort, $sEncryption); if (strlen($sUserName) > 0) { $oTransport->setUsername($sUserName); $oTransport->setPassword($sPassword); } break; case 'Null': $oTransport = Swift_NullTransport::newInstance(); break; case 'LogFile': $oTransport = Swift_LogFileTransport::newInstance(); $oTransport->setLogFile(APPROOT . 'log/mail.log'); break; case 'PHPMail': default: $oTransport = Swift_MailTransport::newInstance(); } $oMailer = Swift_Mailer::newInstance($oTransport); $aFailedRecipients = array(); $iSent = $oMailer->send($this->m_oMessage, $aFailedRecipients); if ($iSent === 0) { // Beware: it seems that $aFailedRecipients sometimes contains the recipients that actually received the message !!! IssueLog::Warning('Email sending failed: Some recipients were invalid, aFailedRecipients contains: ' . implode(', ', $aFailedRecipients)); $aIssues = array('Some recipients were invalid.'); return EMAIL_SEND_ERROR; } else { $aIssues = array(); return EMAIL_SEND_OK; } }
/** * Get the context definitions from the parameters / configuration. The format of the "key" string is: * <module>/relation_context/<class>/<relation>/<direction> * The values will be retrieved for the given class and all its parents and merged together as a single array. * Entries with an invalid query are removed from the list. * @param string $sContextKey The key to fetch the queries in the configuration. Example: itop-tickets/relation_context/UserRequest/impacts/down * @param bool $bDevelopParams Whether or not to substitute the parameters inside the queries with the supplied "context params" * @param array $aContextParams Arguments for the queries (via ToArgs()) if $bDevelopParams == true * @return multitype:multitype:string */ public static function GetContextDefinitions($sContextKey, $bDevelopParams = true, $aContextParams = array()) { $aContextDefs = array(); $aLevels = explode('/', $sContextKey); if (count($aLevels) < 5) { IssueLog::Warning("GetContextDefinitions: invalid 'sContextKey' = '{$sContextKey}'. 5 levels of / are expected !"); } else { $sLeafClass = $aLevels[2]; if (!MetaModel::IsValidClass($sLeafClass)) { IssueLog::Warning("GetContextDefinitions: invalid 'sLeafClass' = '{$sLeafClass}'. A valid class name is expected in 3rd position inside '{$sContextKey}' !"); } else { $aRelationContext = MetaModel::GetConfig()->GetModuleSetting($aLevels[0], $aLevels[1], array()); foreach (MetaModel::EnumParentClasses($sLeafClass, ENUM_PARENT_CLASSES_ALL) as $sClass) { if (isset($aRelationContext[$sClass][$aLevels[3]][$aLevels[4]]['items'])) { $aContextDefs = array_merge($aContextDefs, $aRelationContext[$sClass][$aLevels[3]][$aLevels[4]]['items']); } } // Check if the queries are valid foreach ($aContextDefs as $sKey => $sDefs) { $sOQL = $aContextDefs[$sKey]['oql']; try { // Expand the parameters. If anything goes wrong, then the query is considered as invalid and removed from the list $oSearch = DBObjectSearch::FromOQL($sOQL); $aContextDefs[$sKey]['oql'] = $oSearch->ToOQL($bDevelopParams, $aContextParams); } catch (Exception $e) { IssueLog::Warning('Invalid OQL query: ' . $sOQL . ' in the parameter ' . $sContextKey); unset($aContextDefs[$sKey]); } } } } return $aContextDefs; }