3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * The TasksTrait provides a library of tasks that are useful to run during an upgrade.
15 trait CRM_Extension_Upgrader_TasksTrait
{
20 abstract public function getExtensionDir();
23 * Run a CustomData file.
25 * @param string $relativePath
26 * the CustomData XML file path (relative to this extension's dir)
29 public function executeCustomDataFile($relativePath) {
30 $xml_file = $this->getExtensionDir() . '/' . $relativePath;
31 return $this->executeCustomDataFileByAbsPath($xml_file);
35 * Run a CustomData file
37 * @param string $xml_file
38 * the CustomData XML file path (absolute path)
42 protected function executeCustomDataFileByAbsPath($xml_file) {
43 $import = new CRM_Utils_Migrate_Import();
44 $import->run($xml_file);
51 * @param string $tplFile
52 * The SQL file path (relative to this extension's dir, or absolute)
56 public function executeSqlFile($tplFile) {
57 $tplFile = CRM_Utils_File
::isAbsolute($tplFile) ?
$tplFile : $this->getExtensionDir() . DIRECTORY_SEPARATOR
. $tplFile;
58 CRM_Utils_File
::sourceSQLFile(CIVICRM_DSN
, $tplFile);
63 * Run the sql commands in the specified file.
65 * @param string $tplFile
66 * The SQL file path (relative to this extension's dir, or absolute).
67 * Ex: "sql/mydata.mysql.tpl".
70 * @throws \CRM_Core_Exception
72 public function executeSqlTemplate($tplFile) {
73 // Assign multilingual variable to Smarty.
74 $upgrade = new CRM_Upgrade_Form();
76 $tplFile = CRM_Utils_File
::isAbsolute($tplFile) ?
$tplFile : $this->getExtensionDir() . DIRECTORY_SEPARATOR
. $tplFile;
77 $smarty = CRM_Core_Smarty
::singleton();
78 $smarty->assign('domainID', CRM_Core_Config
::domainID());
79 CRM_Utils_File
::sourceSQLFile(
80 CIVICRM_DSN
, $smarty->fetch($tplFile), NULL, TRUE
88 * This is just a wrapper for CRM_Core_DAO::executeSql, but it
89 * provides syntactic sugar for queueing several tasks that
90 * run different queries
94 public function executeSql($query, $params = []) {
95 // FIXME verify that we raise an exception on error
96 CRM_Core_DAO
::executeQuery($query, $params);