Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db dsn #7663

Closed
wants to merge 2 commits into from
Closed

Db dsn #7663

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CRM/Core/CodeGen/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class CRM_Core_CodeGen_Main {
*/
var $digest;

/**
* @var string|NULL authentication credentials, for connecting to the database during character type conversions, and escaping.
*/
var $dbDsn;

/**
* @param $CoreDAOCodePath
* @param $sqlCodePath
Expand All @@ -35,13 +40,15 @@ class CRM_Core_CodeGen_Main {
* @param $argVersion
* @param $schemaPath
* @param $digestPath
* @param $dbDsn
*/
public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $smartyPluginDirs, $argCms, $argVersion, $schemaPath, $digestPath) {
public function __construct($CoreDAOCodePath, $sqlCodePath, $phpCodePath, $tplCodePath, $smartyPluginDirs, $argCms, $argVersion, $schemaPath, $digestPath, $dbDsn) {
$this->CoreDAOCodePath = $CoreDAOCodePath;
$this->sqlCodePath = $sqlCodePath;
$this->phpCodePath = $phpCodePath;
$this->tplCodePath = $tplCodePath;
$this->digestPath = $digestPath;
$this->dbDsn = $dbDsn;
$this->digest = NULL;

// default cms is 'drupal', if not specified
Expand Down
10 changes: 5 additions & 5 deletions CRM/Core/CodeGen/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function run() {
*/
public function generateCreateSql($fileName = 'civicrm.mysql') {
echo "Generating sql file\n";
$template = new CRM_Core_CodeGen_Util_Template('sql');
$template = new CRM_Core_CodeGen_Util_Template('sql', $this->config->dbDsn);

$template->assign('database', $this->config->database);
$template->assign('tables', $this->tables);
Expand All @@ -49,19 +49,19 @@ public function generateCreateSql($fileName = 'civicrm.mysql') {
public function generateDropSql($fileName = 'civicrm_drop.mysql') {
echo "Generating sql drop tables file\n";
$dropOrder = array_reverse(array_keys($this->tables));
$template = new CRM_Core_CodeGen_Util_Template('sql');
$template = new CRM_Core_CodeGen_Util_Template('sql', $this->config->dbDsn);
$template->assign('dropOrder', $dropOrder);
$template->run('drop.tpl', $this->config->sqlCodePath . $fileName);
}

public function generateNavigation() {
echo "Generating navigation file\n";
$template = new CRM_Core_CodeGen_Util_Template('sql');
$template = new CRM_Core_CodeGen_Util_Template('sql', $this->config->dbDsn);
$template->run('civicrm_navigation.tpl', $this->config->sqlCodePath . "civicrm_navigation.mysql");
}

public function generateLocaleDataSql() {
$template = new CRM_Core_CodeGen_Util_Template('sql');
$template = new CRM_Core_CodeGen_Util_Template('sql', $this->config->dbDsn);

global $tsLocale;
$oldTsLocale = $tsLocale;
Expand Down Expand Up @@ -91,7 +91,7 @@ public function generateLocaleDataSql() {
}

public function generateSample() {
$template = new CRM_Core_CodeGen_Util_Template('sql');
$template = new CRM_Core_CodeGen_Util_Template('sql', $this->config->dbDsn);
$sections = array(
'civicrm_sample.tpl',
'civicrm_acl.tpl',
Expand Down
9 changes: 8 additions & 1 deletion CRM/Core/CodeGen/Util/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
class CRM_Core_CodeGen_Util_Template {
protected $filetype;

protected $dbDsn;

protected $smarty;
protected $beautifier;

/**
* @param string $filetype
*/
public function __construct($filetype) {
public function __construct($filetype, $dbDsn = "mysql://username:password@localhost/database") {
$this->filetype = $filetype;
$this->dbDsn = $dbDsn;

$this->smarty = CRM_Core_CodeGen_Util_Smarty::singleton()->getSmarty();

Expand All @@ -36,6 +39,10 @@ public function __construct($filetype) {
$this->beautifier->setIndentNumber(2);
$this->beautifier->setNewLine("\n");
}
if ($this->filetype === 'sql') {
// localization needs a database connection.
$this->assign('dbDsn', $this->dbDsn);
}
}

/**
Expand Down
18 changes: 16 additions & 2 deletions CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ class CRM_Core_I18n {
*/
private $locale;

/**
* A dbDsn, for when we are connecting to the database server, for localization.
*
* @var string
* the dbDsn string used to connect to the database.
*/

var $dbDsn = "";

/**
* A locale-based constructor that shouldn't be called from outside of this class (use singleton() instead).
*
Expand Down Expand Up @@ -225,8 +234,9 @@ public static function getResourceDir() {
* where n is 1 for the first parameter. The following parameters are reserved:
* - escape - sets escape mode:
* - 'html' for HTML escaping, this is the default.
* - 'sql' for SQL escaping. Requires connecting to the database engine to perform escaping.
* - 'js' for javascript escaping.
* - 'no'/'off'/0 - turns off escaping
* - 'no'/'off'/0 - turns off escaping.
* - plural - The plural version of the text (2nd parameter of ngettext())
* - count - The item count for plural mode (3rd parameter of ngettext())
* - context - gettext context of that string (for homonym handling)
Expand Down Expand Up @@ -315,7 +325,11 @@ public function crm_translate($text, $params = array()) {

// escape SQL if we were asked for it
if (isset($escape) and ($escape == 'sql')) {
$text = CRM_Core_DAO::escapeString($text);
if ($DAO === NULL) {
$DAO = new CRM_Core_DAO;
$DAO->setDsn($this->dbDsn);
}
$text = $DAO->escapeString($text);
}

// escape for JavaScript (if requested)
Expand Down
6 changes: 6 additions & 0 deletions CRM/Core/Smarty/plugins/block.ts.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@
* the string, translated by gettext
*/
function smarty_block_ts($params, $text, &$smarty) {
static $i18n = NULL;
if (!isset($params['domain'])) {
$params['domain'] = $smarty->get_template_vars('extensionKey');
}

if(!$i18n) {
$i18n = CRM_Core_I18n::singleton();
$i18n->dbDsn=$smarty->get_template_vars('dbDsn');
}
return ts($text, $params);
}
3 changes: 2 additions & 1 deletion xml/GenCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
@$argv[3], // cms
empty($argv[2]) ? NULL : $argv[2], // db version
empty($argv[1]) ? 'schema/Schema.xml' : $argv[1], // schema file
getenv('CIVICRM_GENCODE_DIGEST') ? getenv('CIVICRM_GENCODE_DIGEST') : NULL // path to digest file
getenv('CIVICRM_GENCODE_DIGEST') ? getenv('CIVICRM_GENCODE_DIGEST') : NULL, // path to digest file
empty($argv[4]) ? "mysql://username:password@localhost/database" : $argv[4] // db connect string
);
$genCode->main();