示例#1
0
 /**
  * Protected constructor to prevent creating a new instance of the
  * *Singleton* via the `new` operator from outside of this class.
  */
 protected function __construct($locale = null, $databaseConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     // initialize language and user locale
     if (isset($locale)) {
         $this->locale = $locale;
     } else {
         if (\creamy\DatabaseConnectorFactory::instantiationAvailableForConnectorOfType($databaseConnectorType)) {
             // else if we have access to database, check the CRM locale setting.
             $dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($databaseConnectorType);
             $dbConnector->where("setting", CRM_SETTING_LOCALE);
             if ($settingRow = $dbConnector->getOne(CRM_SETTINGS_TABLE_NAME)) {
                 $this->locale = $settingRow["value"];
             }
         }
     }
     // if locale could not be stablished, fallback to default.
     if (!isset($this->locale)) {
         $this->locale = CRM_LANGUAGE_DEFAULT_LOCALE;
     }
     // initialize map of language texts.
     $filepath = dirname(dirname(__FILE__)) . CRM_LANGUAGE_BASE_DIR . $this->locale;
     $translations = $this->getTranslationsFromFile($filepath);
     if (!isset($translations)) {
         // fallback to en_US installation (everybody knows english, don't they?)
         $filepath = dirname(dirname(__FILE__)) . CRM_LANGUAGE_BASE_DIR . "en_US";
         $this->locale = "en_US";
         $translations = $this->getTranslationsFromFile($filepath);
     }
     $this->texts = $translations;
 }
示例#2
0
 /** Creation and class lifetime management */
 function __construct($dbConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     // Database connector
     $this->dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($dbConnectorType);
     // language handler
     $locale = $this->getLocaleSetting();
     $this->lh = \creamy\LanguageHandler::getInstance($locale, $dbConnectorType);
 }
示例#3
0
 /**
  * Constructor.
  */
 function __construct($dbConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     // database
     require_once 'DatabaseConnectorFactory.php';
     $this->dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($dbConnectorType);
     // system versions
     $this->currendDatabaseVersion = $this->checkCurrentDatabaseVersion();
     $this->currentFilesystemVersion = $this->checkCurrentFilesystemVersion();
 }
示例#4
0
 public function __construct($dbhost, $dbname, $dbuser, $dbpass, $dbport = CRM_DEFAULT_DB_PORT, $dbConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     $this->lh = \creamy\LanguageHandler::getInstance();
     try {
         $dbConnectorFactory = \creamy\DatabaseConnectorFactory::getInstance();
         $this->dbConnector = $dbConnectorFactory->getDatabaseConnectorOfType($dbConnectorType, $dbhost, $dbname, $dbuser, $dbpass, $dbport);
         $this->state = CRM_INSTALL_STATE_SUCCESS;
     } catch (\Exception $e) {
         $this->state = CRM_INSTALL_STATE_ERROR;
         $this->error = CRM_INSTALL_STATE_DATABASE_ERROR . ". Unable to instantiate database connector of type {$dbConnectorType}. Incorrect credentials or access denied.";
     }
 }
示例#5
0
 /**
  * Convenience method that returns the Database Connector to be used by module's subclasses.
  * @return the module instance of DbConnector.
  */
 public function db($dbConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     if (!isset($this->dbConnector)) {
         $this->dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($dbConnectorType);
     }
     return $this->dbConnector;
 }
示例#6
0
 /** 
  * Returns true if the module system is enabled. 
  * @return true if the module system is enabled. False otherwise.
  */
 public static function moduleSystemEnabled($dbConnectorType = CRM_DB_CONNECTOR_TYPE_MYSQL)
 {
     require_once 'DatabaseConnectorFactory.php';
     if ($dbConnector = \creamy\DatabaseConnectorFactory::getInstance()->getDatabaseConnectorOfType($dbConnectorType)) {
         $dbConnector->where("setting", CRM_SETTING_MODULE_SYSTEM_ENABLED);
         $result = $dbConnector->getOne(CRM_SETTINGS_TABLE_NAME);
         if (isset($result) && array_key_exists("value", $result)) {
             return $result["value"];
         }
     }
     return false;
 }