/** * Run a CustomData file * * @param string $xml_file the CustomData XML file path (absolute path) * @return bool */ protected static function executeCustomDataFileByAbsPath($xml_file) { require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $import->run($xml_file); return TRUE; }
/** * Run a CustomData file * * @param string $relativePath the CustomData XML file path (relative to this extension's dir) * @return bool */ public function executeCustomDataFile($relativePath) { $xml_file = $this->extensionDir . '/' . $relativePath; require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $import->run($xml_file); return TRUE; }
/** * Implementation of hook_civicrm_install */ function booking_civicrm_install() { require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; $op = $extRoot . 'xml' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'OptionGroups.xml'; $import->run($op); return _booking_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function gotowebinar_civicrm_install() { #create custom group from xml file $extensionDir = dirname(__FILE__) . DIRECTORY_SEPARATOR; $customDataXMLFile = $extensionDir . 'auto_install.xml'; require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $import->run($customDataXMLFile); return _gotowebinar_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function pcpteams_civicrm_install() { //create custom group from xml file // Create OptionGroup, OptionValues, RelationshipType, CustomGroup and CustomFields $extensionDir = dirname(__FILE__) . DIRECTORY_SEPARATOR; $customDataXMLFile = $extensionDir . '/xml/CustomGroupData.xml'; $import = new CRM_Utils_Migrate_Import(); $import->run($customDataXMLFile); //Create Contact Subtype $params = array('parent_id' => 3, 'is_active' => 1, 'is_reserved' => 0); foreach (array(CRM_Pcpteams_Constant::C_CONTACT_SUB_TYPE_TEAM, CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_MEM, CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_CELEB, CRM_Pcpteams_Constant::C_CONTACTTYPE_BRANCH, CRM_Pcpteams_Constant::C_CONTACTTYPE_PARTNER) as $subTypes) { if (!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $subTypes, 'id', 'name')) { $params['name'] = $subTypes; $params['label'] = str_replace('_', ' ', $subTypes); CRM_Contact_BAO_ContactType::add($params); } } //set foreignkey $sql = "ALTER TABLE `civicrm_value_pcp_custom_set`\n MODIFY `team_pcp_id` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_custom_set_team_pcp_id` FOREIGN KEY (`team_pcp_id`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL"; CRM_Core_DAO::executeQuery($sql); //set foreignkey for pcp_a_b and pcp_b_a on delete make null $alterSql = "ALTER TABLE `civicrm_value_pcp_relationship_set`\n MODIFY `pcp_a_b` int(10) unsigned DEFAULT NULL, MODIFY `pcp_b_a` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_a_b` FOREIGN KEY (`pcp_a_b`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_b_a` FOREIGN KEY (`pcp_b_a`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL\n "; CRM_Core_DAO::executeQuery($alterSql); //invite team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_invite_members_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['invite_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_INVITE_TEAM, 'msg_subject' => (string) '{$inviteeFirstName} you have been invited to join {$teamName} and support Leukaemia and Lymphoma Research', 'is_default' => 1, 'msg_html' => $messageHtml); //join team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_join_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['join_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQUEST, 'msg_subject' => (string) '{$userFirstName} {$userlastName} has requested to join Team {$teamName} please authorise', 'is_default' => 1, 'msg_html' => $messageHtml); //leave team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_leave_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['leave_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_LEAVE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} has decided to leave Team {$teamName}', 'is_default' => 1, 'msg_html' => $messageHtml); //decline join request $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_decline_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['decline_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQ_DECLINE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} your request to join {$teamName} has been turned down', 'is_default' => 1, 'msg_html' => $messageHtml); //approve join request $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_approve_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['decline_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQ_APPROVE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} your request to join {$teamName} has been approved', 'is_default' => 1, 'msg_html' => $messageHtml); $ogId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', CRM_Pcpteams_Constant::C_OG_MSG_TPL_WORKFLOW, 'id', 'name'); foreach ($message_params as $key => $message_param) { $opValue = civicrm_api3('OptionValue', 'getsingle', array('version' => 3, 'option_group_id' => $ogId, 'name' => $message_param['msg_title'])); if ($opValue['id']) { $message_param['workflow_id'] = $opValue['id']; } $result = civicrm_api3('MessageTemplate', 'create', $message_param); } return _pcpteams_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install */ function civigiftaid_civicrm_install() { require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $extRoot = dirname(__FILE__) . DIRECTORY_SEPARATOR; $op = $extRoot . 'xml' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'CustomGroupData.xml'; $import->run($op); // rebuild the menu so our path is picked up require_once 'CRM/Core/Invoke.php'; CRM_Core_Invoke::rebuildMenuAndCaches(); return _civigiftaid_civix_civicrm_install(); }
/** * Example: Run a slow upgrade process by breaking it up into smaller chunk * * @return TRUE on success * @throws Exception */ public function upgrade_11() { $this->ctx->log->info('Applying update v1.1'); // PEAR Log interface require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); // Import custom data (flag to process DM sync) for contribution $file = 'xml' . DIRECTORY_SEPARATOR . 'Upgrade' . DIRECTORY_SEPARATOR . 'v1.1.xml'; $xmlFilepath = CRM_Core_Resources::singleton()->getPath('uk.co.vedaconsulting.module.dotmailer', $file); $import->run($xmlFilepath); return TRUE; }
/** * * @package CRM * @copyright CiviCRM LLC (c) 2004-2014 * $Id$ * */ function run() { session_start(); if (!array_key_exists('file', $_GET) || empty($_GET['file'])) { echo "Please send an input file to import<p>"; exit; } require_once '../../civicrm.config.php'; require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); // this does not return on failure CRM_Utils_System::authenticateScript(TRUE); require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $import->run($_GET['file']); echo "Import Done!"; }
/** * @param $customGroupParams * @param $fieldParams * @param $expectedXmlFilePath * @dataProvider basicXmlTestCases */ function testBasicXMLImports($expectCustomGroup, $expectCustomField, $inputXmlFilePath) { $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_custom_group WHERE title = %1', array(1 => array($expectCustomGroup['title'], 'String'))); $importer = new CRM_Utils_Migrate_Import(); $importer->run($inputXmlFilePath); $customGroups = $this->callAPISuccess('custom_group', 'get', array('title' => $expectCustomGroup['title'])); $this->assertEquals(1, $customGroups['count']); $customGroup = array_shift($customGroups['values']); foreach ($expectCustomGroup as $expectKey => $expectValue) { $this->assertEquals($expectValue, $customGroup[$expectKey]); } $customFields = $this->callAPISuccess('custom_field', 'get', array('label' => $expectCustomField['label'])); $this->assertEquals(1, $customFields['count']); $customField = array_shift($customFields['values']); foreach ($expectCustomField as $expectKey => $expectValue) { $this->assertEquals($expectValue, $customField[$expectKey]); } }
/** * Implementation of hook_civicrm_postInstall * * Note: This hook only runs in CiviCRM 4.4+. */ function hrcase_civicrm_postInstall() { //disable example case types hrcase_example_caseType(FALSE); // Import custom group require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $files = glob(__DIR__ . '/xml/*_customGroupCaseType.xml'); if (is_array($files)) { foreach ($files as $file) { $import->run($file); } } $scheduleActions = hrcase_getActionsSchedule(); foreach ($scheduleActions as $actionName => $scheduleAction) { $result = civicrm_api3('action_schedule', 'get', array('name' => $actionName)); if (empty($result['id'])) { $result = civicrm_api3('action_schedule', 'create', $scheduleAction); } } }
protected static function _populateDB($perClass = FALSE, &$object = NULL) { if (!parent::_populateDB($perClass, $object)) { return FALSE; } //populate vacancy_status of type Application $result = civicrm_api3('OptionGroup', 'create', array('name' => 'vacancy_status', 'title' => ts('Vacancy Status'), 'is_reserved' => 1, 'is_active' => 1)); $vacancyStatus = array('Draft' => ts('Draft'), 'Open' => ts('Open'), 'Closed' => ts('Closed'), 'Cancelled' => ts('Cancelled'), 'Rejected' => ts('Rejected')); $weight = 1; foreach ($vacancyStatus as $name => $label) { $statusParam = array('option_group_id' => $result['id'], 'label' => $label, 'name' => $name, 'value' => $weight++, 'is_active' => 1); if ($name == 'Draft') { $statusParam['is_default'] = 1; } elseif ($name == 'Open') { $statusParam['is_reserved'] = 1; } civicrm_api3('OptionValue', 'create', $statusParam); } $import = new CRM_Utils_Migrate_Import(); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrrecruitment') . '/xml/auto_install.xml'); return TRUE; }
/** * Helper function to load data into DB between iterations of the unit-test */ function _hrjob_phpunit_populateDB() { $import = new CRM_Utils_Migrate_Import(); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrjob') . '/xml/option_group_install.xml'); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrjob') . '/xml/job_summary_install.xml'); //create option value for option group region $result = civicrm_api3('OptionGroup', 'get', array('name' => "hrjob_region")); $regionVal = array('Asia' => ts('Asia'), 'Europe' => ts('Europe')); foreach ($regionVal as $name => $label) { $regionParam = array('option_group_id' => $result['id'], 'label' => $label, 'name' => $name, 'value' => $name, 'is_active' => 1); civicrm_api3('OptionValue', 'create', $regionParam); } }
public function executeCustomDataTemplateFile($relativePath) { $smarty = CRM_Core_Smarty::singleton(); $xmlCode = $smarty->fetch($relativePath); //x dpm($xmlCode); $xml = simplexml_load_string($xmlCode); require_once 'CRM/Utils/Migrate/Import.php'; $import = new CRM_Utils_Migrate_Import(); $import->runXmlElement($xml); return TRUE; }
/** * Helper function to load data into DB between iterations of the unit-test */ function _hrvisa_phpunit_populateDB() { $import = new CRM_Utils_Migrate_Import(); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrvisa') . '/xml/auto_install.xml'); // this had to be done as demographics consists of is_visa_required field (used in unit test) $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrdemog') . '/xml/auto_install.xml'); }
/** * Helper function to load data into DB between iterations of the unit-test */ function _hrrecruitment_phpunit_populateDB() { //populate vacancy_status and case_status of type Application $result = civicrm_api3('OptionGroup', 'create', array('name' => 'vacancy_status', 'title' => ts('Vacancy Status'), 'is_reserved' => 1, 'is_active' => 1)); $vacancyStatus = array('Draft' => ts('Draft'), 'Open' => ts('Open'), 'Closed' => ts('Closed'), 'Cancelled' => ts('Cancelled'), 'Rejected' => ts('Rejected')); $weight = 1; foreach ($vacancyStatus as $name => $label) { $statusParam = array('option_group_id' => $result['id'], 'label' => $label, 'name' => $name, 'value' => $weight++, 'is_active' => 1); if ($name == 'Draft') { $statusParam['is_default'] = 1; } elseif ($name == 'Open') { $statusParam['is_reserved'] = 1; } civicrm_api3('OptionValue', 'create', $statusParam); } $stages = array('Apply' => ts('Apply'), 'Ongoing_Vacancy' => ts('Ongoing'), 'Phone_Interview' => ts('Phone Interview'), 'Manager_Interview' => ts('Manager Interview'), 'Board_Interview' => ts('Board Interview'), 'Group_Interview' => ts('Group Interview'), 'Psych_Exam' => ts('Psych Exam'), 'Offer' => ts('Offer'), 'Hired' => ts('Hired')); $count = count(CRM_Core_OptionGroup::values('case_status')); foreach ($stages as $name => $label) { $count++; $caseStatusParam = array('option_group_id' => 'case_status', 'label' => $label, 'name' => $name, 'value' => $count, 'grouping' => 'Vacancy', 'filter' => 1); civicrm_api3('OptionValue', 'create', $caseStatusParam); } $import = new CRM_Utils_Migrate_Import(); $import->run(CRM_Extension_System::singleton()->getMapper()->keyToBasePath('org.civicrm.hrrecruitment') . '/xml/auto_install.xml'); }
/** * Run a CustomData file * * @param string $xml_file the CustomData XML file path (absolute path) * @return bool */ protected static function executeCustomDataFileByAbsPath($xml_file) { $import = new CRM_Utils_Migrate_Import(); $import->run($xml_file); return TRUE; }