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

Issue #180: Process the install.sql in Smarty to support installation on multi-lingual. #181

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 37 additions & 8 deletions CRM/Volunteer/Upgrader/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,41 @@ protected static function executeCustomDataFileByAbsPath($xml_file) {
* @param string $relativePath the SQL file path (relative to this extension's dir)
* @return bool
*/
public function executeSqlFile($relativePath) {
CRM_Utils_File::sourceSQLFile(
CIVICRM_DSN,
$this->extensionDir . '/' . $relativePath
);
public function executeSqlFile($relativePath, $smarty = FALSE) {
if ($smarty) {
$smarty = CRM_Core_Smarty::singleton();
$smarty->assign('domainID', CRM_Core_Config::domainID());
$smarty->assign('extDir', $this->extensionDir);

// FIXME: need this for {localize} in sql files to work.
$domain = new CRM_Core_DAO_Domain();
$domain->find(TRUE);
$smarty->assign('multilingual', (bool) $domain->locales);
$smarty->assign('locales', explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales));

// FIXME: needs discussion with CiviCRM devs
// this sets the template dir to the extension main directory, so that
// we can do a smarty include for sql/ or message_template/ files.
$extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
if (is_array($smarty->template_dir)) {
array_unshift($smarty->template_dir, $extRoot . '../../../');
} else {
$smarty->template_dir = array($extRoot . '../../../', $smarty->template_dir);
}

CRM_Utils_File::sourceSQLFile(
CIVICRM_DSN,
$smarty->fetch($this->extensionDir . '/' . $relativePath),
NULL,
TRUE
);
}
else {
CRM_Utils_File::sourceSQLFile(
CIVICRM_DSN,
$this->extensionDir . '/' . $relativePath
);
}
return TRUE;
}

Expand Down Expand Up @@ -238,9 +268,8 @@ public function setCurrentRevision($revision) {
// ******** Hook delegates ********

public function onInstall() {
foreach (glob($this->extensionDir . '/sql/*_install.sql') as $file) {
CRM_Utils_File::sourceSQLFile(CIVICRM_DSN, $file);
}
$this->executeSqlFile('sql/volunteer_install.sql', TRUE);

foreach (glob($this->extensionDir . '/xml/*_install.xml') as $file) {
$this->executeCustomDataFileByAbsPath($file);
}
Expand Down
6 changes: 4 additions & 2 deletions sql/volunteer_install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ CREATE TABLE IF NOT EXISTS civicrm_volunteer_need (
SELECT @opGId := id FROM civicrm_option_group WHERE name = 'report_template';
SELECT @ovWeight := MAX(weight)+1 FROM civicrm_option_value WHERE option_group_id = @opGId;

INSERT IGNORE INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`,`weight`,`description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES
(@opGId, 'Volunteer Report', 'volunteer', 'CRM_Volunteer_Form_VolunteerReport', NULL, 0, 0, @ovWeight, 'Volunteer Report', 0, 0, 1, NULL, NULL, NULL);
INSERT IGNORE INTO `civicrm_option_value` (`option_group_id`, {localize field='label'}label{/localize}, `value`, `name`, `grouping`, `filter`, `is_default`,`weight`,{localize field='description'}description{/localize}, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `domain_id`, `visibility_id`) VALUES
(@opGId, {localize}'{ts escape="sql"}Volunteer Report{/ts}'{/localize}, 'volunteer', 'CRM_Volunteer_Form_VolunteerReport', NULL, 0, 0, @ovWeight, {localize}'{ts escape="sql"}Volunteer Report{/ts}'{/localize}, 0, 0, 1, NULL, NULL, NULL);

{literal}
INSERT INTO `civicrm_report_instance` (`domain_id`, `title`, `report_id`, `name`, `args`, `description`, `permission`, `grouprole`, `form_values`, `is_active`, `email_subject`, `email_to`, `email_cc`, `header`, `footer`, `navigation_id`, `drilldown_id`, `is_reserved`) VALUES
(1, 'Volunteer Report', 'volunteer', NULL, NULL, 'Volunteer Report', 'access CiviReport', NULL, 'a:39:{s:6:"fields";a:10:{s:16:"contact_assignee";s:1:"1";s:14:"contact_target";s:1:"0";s:7:"project";s:1:"1";s:16:"activity_type_id";s:1:"1";s:16:"activity_subject";s:1:"1";s:18:"activity_date_time";s:1:"1";s:9:"status_id";s:1:"1";s:4:"role";s:1:"1";s:14:"time_scheduled";s:1:"1";s:14:"time_completed";s:1:"1";}s:17:"contact_source_op";s:3:"has";s:20:"contact_source_value";s:0:"";s:19:"contact_assignee_op";s:3:"has";s:22:"contact_assignee_value";s:0:"";s:17:"contact_target_op";s:3:"has";s:20:"contact_target_value";s:0:"";s:15:"current_user_op";s:2:"eq";s:18:"current_user_value";s:1:"0";s:27:"activity_date_time_relative";s:10:"this.month";s:23:"activity_date_time_from";s:0:"";s:21:"activity_date_time_to";s:0:"";s:19:"activity_subject_op";s:3:"has";s:22:"activity_subject_value";s:0:"";s:5:"id_op";s:2:"in";s:8:"id_value";a:0:{}s:12:"status_id_op";s:2:"in";s:15:"status_id_value";a:0:{}s:8:"tagid_op";s:2:"in";s:11:"tagid_value";a:0:{}s:6:"gid_op";s:2:"in";s:9:"gid_value";a:0:{}s:12:"custom_9_min";s:0:"";s:12:"custom_9_max";s:0:"";s:11:"custom_9_op";s:3:"lte";s:14:"custom_9_value";s:0:"";s:13:"custom_10_min";s:0:"";s:13:"custom_10_max";s:0:"";s:12:"custom_10_op";s:3:"lte";s:15:"custom_10_value";s:0:"";s:9:"order_bys";a:2:{i:1;a:2:{s:6:"column";s:5:"title";s:5:"order";s:3:"ASC";}i:2;a:2:{s:6:"column";s:9:"sort_name";s:5:"order";s:3:"ASC";}}s:11:"description";s:16:"Volunteer Report";s:13:"email_subject";s:0:"";s:8:"email_to";s:0:"";s:8:"email_cc";s:0:"";s:10:"permission";s:17:"access CiviReport";s:9:"parent_id";s:0:"";s:6:"groups";s:0:"";s:11:"instance_id";s:2:"36";}', 1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0);
{/literal}