Merge pull request #2387 from pratik-joshi/CRM-13973
[civicrm-core.git] / CRM / Core / Config.php
index be3bf7c53cf052d002f48c792b0836a9cfcd753b..ee12caba087bb1a71aecc402b900ac427e319478 100644 (file)
@@ -167,7 +167,7 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
    * @param $loadFromDB boolean  whether to load from the database
    * @param $force      boolean  whether to force a reconstruction
    *
-   * @return object
+   * @return CRM_Core_Config
    * @static
    */
   static function &singleton($loadFromDB = TRUE, $force = FALSE) {
@@ -242,6 +242,9 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
           array(1 => array($userID, 'Integer'))
         );
       }
+
+      // initialize authentication source
+      self::$_singleton->initAuthSrc();
     }
     return self::$_singleton;
   }
@@ -503,12 +506,10 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
   }
 
   /**
-   * retrieve a mailer to send any mail from the applciation
+   * Retrieve a mailer to send any mail from the application
    *
    * @param boolean $persist open a persistent smtp connection, should speed up mailings
-   *
    * @access private
-   *
    * @return object
    */
   static function &getMailer($persist = FALSE) {
@@ -574,7 +575,7 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
         CRM_Core_Error::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Session::setStatus(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
       }
-      else{
+      else {
         CRM_Core_Error::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Session::setStatus(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))));
         CRM_Core_Error::debug_var('mailing_info', $mailingInfo);
@@ -584,17 +585,20 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
   }
 
   /**
+   * Create a new instance of a PEAR Mail driver
+   *
    * @param string $driver 'CRM_Mailing_BAO_Spool' or a name suitable for Mail::factory()
    * @param array $params
-   * @return Mail|NULL
+   * @return Mail (More specifically, a class which implements the "send()" function)
    */
   public static function _createMailer($driver, $params) {
     if ($driver == 'CRM_Mailing_BAO_Spool') {
       $mailer = new CRM_Mailing_BAO_Spool($params);
-    } else {
+    }
+    else {
       $mailer = Mail::factory($driver, $params);
     }
-    CRM_Utils_Hook::hook_civicrm_alterMailer($mailer, $driver, $params);
+    CRM_Utils_Hook::alterMail($mailer, $driver, $params);
     return $mailer;
   }
 
@@ -651,6 +655,17 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
     CRM_Core_DAO::executeQuery($query);
   }
 
+  // This method should initialize auth sources
+  function initAuthSrc() {
+    $session = CRM_Core_Session::singleton();
+    if ($session->get('userID') && !$session->get('authSrc')) {
+      $session->set('authSrc', CRM_Core_Permission::AUTH_SRC_LOGIN);
+    }
+
+    // checksum source
+    CRM_Contact_BAO_Contact_Permission::initChecksumAuthSrc();
+  }
+
   /**
    * one function to get domain ID
    */