From 0825dc24f02878475711ac29424bbffcddaf1b06 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 15 Jan 2020 17:22:33 -0800 Subject: [PATCH] GenCode - Allow execution when civicrm-packages is loaded higher up via composer --- CRM/Core/CodeGen/Util/Smarty.php | 5 ++++- xml/GenCode.php | 3 ++- xml/templates/civicrm_msg_template.tpl | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CRM/Core/CodeGen/Util/Smarty.php b/CRM/Core/CodeGen/Util/Smarty.php index 68a7077ec7..d45989504d 100644 --- a/CRM/Core/CodeGen/Util/Smarty.php +++ b/CRM/Core/CodeGen/Util/Smarty.php @@ -46,11 +46,12 @@ class CRM_Core_CodeGen_Util_Smarty { */ public function createSmarty() { $base = dirname(dirname(dirname(dirname(__DIR__)))); + $pkgs = file_exists(dirname($base) . "/civicrm-packages") ? dirname($base) . "/civicrm-packages" : "$base/packages"; require_once 'Smarty/Smarty.class.php'; $smarty = new Smarty(); $smarty->template_dir = "$base/xml/templates"; - $smarty->plugins_dir = ["$base/packages/Smarty/plugins", "$base/CRM/Core/Smarty/plugins"]; + $smarty->plugins_dir = ["$pkgs/Smarty/plugins", "$base/CRM/Core/Smarty/plugins"]; $smarty->compile_dir = $this->getCompileDir(); $smarty->clear_all_cache(); @@ -59,6 +60,8 @@ class CRM_Core_CodeGen_Util_Smarty { require_once 'CRM/Core/Smarty/plugins/block.localize.php'; $smarty->register_block('localize', 'smarty_block_localize'); + $smarty->assign('gencodeXmlDir', dirname(dirname(dirname(dirname(__DIR__)))) . '/xml'); + return $smarty; } diff --git a/xml/GenCode.php b/xml/GenCode.php index 01b541c9bd..78661a9111 100644 --- a/xml/GenCode.php +++ b/xml/GenCode.php @@ -4,7 +4,8 @@ if (PHP_SAPI !== 'cli') { die("GenCode can only be run from command line."); } -ini_set('include_path', '.' . PATH_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'packages' . PATH_SEPARATOR . '..'); +$includes = ['.', '../packages', '../../civicrm-packages', '..']; +ini_set('include_path', implode(PATH_SEPARATOR, $includes)); // make sure the memory_limit is at least 512 MB $memLimitString = trim(ini_get('memory_limit')); $memLimitUnit = strtolower(substr($memLimitString, -1)); diff --git a/xml/templates/civicrm_msg_template.tpl b/xml/templates/civicrm_msg_template.tpl index 805a67cba4..b664df6674 100644 --- a/xml/templates/civicrm_msg_template.tpl +++ b/xml/templates/civicrm_msg_template.tpl @@ -106,16 +106,16 @@ INSERT INTO civicrm_msg_template (msg_title, msg_subject, msg_text, msg_html, workflow_id, is_default, is_reserved) VALUES {foreach from=$ovNames key=gName item=ovs name=for_groups} {foreach from=$ovs key=vName item=title name=for_values} - {fetch assign=subject file="`$smarty.const.SMARTY_DIR`/../../xml/templates/message_templates/`$vName`_subject.tpl"} - {fetch assign=text file="`$smarty.const.SMARTY_DIR`/../../xml/templates/message_templates/`$vName`_text.tpl"} - {fetch assign=html file="`$smarty.const.SMARTY_DIR`/../../xml/templates/message_templates/`$vName`_html.tpl"} + {fetch assign=subject file="`$gencodeXmlDir`/templates/message_templates/`$vName`_subject.tpl"} + {fetch assign=text file="`$gencodeXmlDir`/templates/message_templates/`$vName`_text.tpl"} + {fetch assign=html file="`$gencodeXmlDir`/templates/message_templates/`$vName`_html.tpl"} ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 1, 0), ('{$title}', '{$subject|escape:"quotes"}', '{$text|escape:"quotes"}', '{$html|escape:"quotes"}', @tpl_ovid_{$vName}, 0, 1) {if $smarty.foreach.for_groups.last and $smarty.foreach.for_values.last};{else},{/if} {/foreach} {/foreach} {php} - $dir = SMARTY_DIR . '/../../xml/templates/message_templates/sample'; + $dir = $this->_tpl_vars['gencodeXmlDir'] . '/templates/message_templates/sample'; $templates = array(); foreach (preg_grep('/\.tpl$/', scandir($dir)) as $filename) { $templates[] = array('name' => basename($filename, '.tpl'), 'filename' => "$dir/$filename"); -- 2.25.1