Import from SVN (r45945, r596)
[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 function _multisite_civix_upgrader() {
116 if (!file_exists(__DIR__.'/CRM/Multisite/Upgrader.php')) {
117 return NULL;
118 } else {
119 return CRM_Multisite_Upgrader_Base::instance();
120 }
121 }
122
123 /**
124 * Search directory tree for files which match a glob pattern
125 *
126 * @param $dir string, base dir
127 * @param $pattern string, glob pattern, eg "*.txt"
128 * @return array(string)
129 */
130 function _multisite_civix_find_files($dir, $pattern) {
131 $todos = array($dir);
132 $result = array();
133 while (!empty($todos)) {
134 $subdir = array_shift($todos);
135 foreach (glob("$subdir/$pattern") as $match) {
136 if (!is_dir($match)) {
137 $result[] = $match;
138 }
139 }
140 if ($dh = opendir($subdir)) {
141 while (FALSE !== ($entry = readdir($dh))) {
142 $path = $subdir . DIRECTORY_SEPARATOR . $entry;
143 if ($entry == '.' || $entry == '..') {
144 } elseif (is_dir($path)) {
145 $todos[] = $path;
146 }
147 }
148 closedir($dh);
149 }
150 }
151 return $result;
152 }
153 /**
154 * (Delegated) Implementation of hook_civicrm_managed
155 *
156 * Find any *.mgd.php files, merge their content, and return.
157 */
158 function _multisite_civix_civicrm_managed(&$entities) {
159 $mgdFiles = _multisite_civix_find_files(__DIR__, '*.mgd.php');
160 foreach ($mgdFiles as $file) {
161 $es = include $file;
162 foreach ($es as $e) {
163 if (empty($e['module'])) {
164 $e['module'] = 'nz.co.fuzion.multisite';
165 }
166 $entities[] = $e;
167 }
168 }
169 }