public static function setUpBeforeClass() { CRM_Core_Config::singleton(1, 1); CRM_Utils_System::loadBootStrap(array('name' => $GLOBALS['_CV']['ADMIN_USER'], 'pass' => $GLOBALS['_CV']['ADMIN_PASS'])); CRM_Utils_System::synchronizeUsers(); parent::setUpBeforeClass(); }
/** * Process the form submission. */ public function postProcess() { $result = CRM_Utils_System::synchronizeUsers(); $status = ts('Checked one user record.', array('count' => $result['contactCount'], 'plural' => 'Checked %count user records.')); if ($result['contactMatching']) { $status .= '<br />' . ts('Found one matching contact record.', array('count' => $result['contactMatching'], 'plural' => 'Found %count matching contact records.')); } $status .= '<br />' . ts('Created one new contact record.', array('count' => $result['contactCreated'], 'plural' => 'Created %count new contact records.')); CRM_Core_Session::setStatus($status, ts('Synchronize Complete'), 'success'); CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); }
<?php civicrm_initialize(); // ----------------------------- // Get a list of users to update if (!getenv('INSTALL_DASHBOARD_USERS')) { throw new RuntimeException('Missing environment variable: INSTALL_DASHBOARD_USERS'); } $users = explode(';', getenv('INSTALL_DASHBOARD_USERS')); CRM_Utils_System::synchronizeUsers(); // v4.7+ // ------------------------------ // Get list of available dashlets $dashletTypeResult = civicrm_api3('Dashboard', 'get', array('domain_id' => CRM_Core_Config::domainID())); $dashletTypes = CRM_Utils_Array::index(array('name'), $dashletTypeResult['values']); // --------------------------------------- // Build list of specific dashlets to add $dashlets = array(array('dashboard_id' => $dashletTypes['report/25']['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 1), array('dashboard_id' => $dashletTypes['report/13']['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 3), array('dashboard_id' => $dashletTypes['report/6']['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 4), array('dashboard_id' => $dashletTypes['activity']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 10), array('dashboard_id' => $dashletTypes['myCases']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 11), array('dashboard_id' => $dashletTypes['report/20']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 12)); // ------------------- // Insert the dashlets $tx = new CRM_Core_Transaction(); try { foreach ($users as $user) { foreach ($dashlets as $dashlet) { $dashlet['contact_id'] = "@user:{$user}"; $dashlet['is_active'] = 1; $dashlet['debug'] = 1; civicrm_api3('dashboard_contact', 'create', $dashlet); } } } catch (CiviCRM_API3_Exception $e) {