Merge pull request #4726 from atif-shaikh/CRM-5039
[civicrm-core.git] / tools / extensions / org.civicrm.multisite / multisite.civix.php
1 <?php
2
3 // AUTO-GENERATED FILE -- Civix may overwrite any changes made to this file
4
5 /**
6 * (Delegated) Implementation of hook_civicrm_config
7 */
8 function _multisite_civix_civicrm_config(&$config = NULL) {
9 static $configured = FALSE;
10 if ($configured) return;
11 $configured = TRUE;
12
13 $template =& CRM_Core_Smarty::singleton();
14
15 $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
16 $extDir = $extRoot . 'templates';
17
18 if ( is_array( $template->template_dir ) ) {
19 array_unshift( $template->template_dir, $extDir );
20 } else {
21 $template->template_dir = array( $extDir, $template->template_dir );
22 }
23
24 $include_path = $extRoot . PATH_SEPARATOR . get_include_path( );
25 set_include_path( $include_path );
26 }
27
28 /**
29 * (Delegated) Implementation of hook_civicrm_alterSettingsMetaData
30 */
31 function _multisite_civix_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
32 static $configured = FALSE;
33 if ($configured) return;
34 $configured = TRUE;
35
36 $extRoot = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
37 $extDir = $extRoot . 'settings';
38 if(!in_array($extDir, $metaDataFolders)){
39 $metaDataFolders[] = $extDir;
40 }
41 }
42
43 /**
44 * (Delegated) Implementation of hook_civicrm_xmlMenu
45 *
46 * @param $files array(string)
47 */
48 function _multisite_civix_civicrm_xmlMenu(&$files) {
49 foreach (glob(__DIR__ . '/xml/Menu/*.xml') as $file) {
50 $files[] = $file;
51 }
52 }
53
54 /**
55 * Implementation of hook_civicrm_install
56 */
57 function _multisite_civix_civicrm_install() {
58 _multisite_civix_civicrm_config();
59 civicrm_api('system', 'flush', array('version' => 3));
60 civicrm_api('settings', 'fill', array('version' => 3));
61 if ($upgrader = _multisite_civix_upgrader()) {
62 return $upgrader->onInstall();
63 }
64 }
65
66 /**
67 * Implementation of hook_civicrm_uninstall
68 */
69 function _multisite_civix_civicrm_uninstall() {
70 _multisite_civix_civicrm_config();
71 if ($upgrader = _multisite_civix_upgrader()) {
72 return $upgrader->onUninstall();
73 }
74 }
75
76 /**
77 * (Delegated) Implementation of hook_civicrm_enable
78 */
79 function _multisite_civix_civicrm_enable() {
80 _multisite_civix_civicrm_config();
81 if ($upgrader = _multisite_civix_upgrader()) {
82 if (is_callable(array($upgrader, 'onEnable'))) {
83 return $upgrader->onEnable();
84 }
85 }
86 }
87
88 /**
89 * (Delegated) Implementation of hook_civicrm_disable
90 */
91 function _multisite_civix_civicrm_disable() {
92 _multisite_civix_civicrm_config();
93 if ($upgrader = _multisite_civix_upgrader()) {
94 if (is_callable(array($upgrader, 'onDisable'))) {
95 return $upgrader->onDisable();
96 }
97 }
98 }
99
100 /**
101 * (Delegated) Implementation of hook_civicrm_upgrade
102 *
103 * @param $op string, the type of operation being performed; 'check' or 'enqueue'
104 * @param $queue CRM_Queue_Queue, (for 'enqueue') the modifiable list of pending up upgrade tasks
105 *
106 * @return mixed based on op. for 'check', returns array(boolean) (TRUE if upgrades are pending)
107 * for 'enqueue', returns void
108 */
109 function _multisite_civix_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
110 if ($upgrader = _multisite_civix_upgrader()) {
111 return $upgrader->onUpgrade($op, $queue);
112 }
113 }
114
115 /**
116 * @return null
117 */
118 function _multisite_civix_upgrader() {
119 if (!file_exists(__DIR__.'/CRM/Multisite/Upgrader.php')) {
120 return NULL;
121 } else {
122 return CRM_Multisite_Upgrader_Base::instance();
123 }
124 }
125
126 /**
127 * Search directory tree for files which match a glob pattern
128 *
129 * @param $dir string, base dir
130 * @param $pattern string, glob pattern, eg "*.txt"
131 * @return array(string)
132 */
133 function _multisite_civix_find_files($dir, $pattern) {
134 $todos = array($dir);
135 $result = array();
136 while (!empty($todos)) {
137 $subdir = array_shift($todos);
138 foreach (glob("$subdir/$pattern") as $match) {
139 if (!is_dir($match)) {
140 $result[] = $match;
141 }
142 }
143 if ($dh = opendir($subdir)) {
144 while (FALSE !== ($entry = readdir($dh))) {
145 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
146 if ($entry == '.' || $entry == '..') {
147 } elseif (is_dir($path)) {
148 $todos[] = $path;
149 }
150 }
151 closedir($dh);
152 }
153 }
154 return $result;
155 }
156 /**
157 * (Delegated) Implementation of hook_civicrm_managed
158 *
159 * Find any *.mgd.php files, merge their content, and return.
160 */
161 function _multisite_civix_civicrm_managed(&$entities) {
162 $mgdFiles = _multisite_civix_find_files(__DIR__, '*.mgd.php');
163 foreach ($mgdFiles as $file) {
164 $es = include $file;
165 foreach ($es as $e) {
166 if (empty($e['module'])) {
167 $e['module'] = 'nz.co.fuzion.multisite';
168 }
169 $entities[] = $e;
170 }
171 }
172 }