Passed
Push — collab-docker-install ( 36b3a0 )
by Ilia
14:23
created

docker_installer.php ➔ init_mods()   B

Complexity

Conditions 7
Paths 16

Size

Total Lines 287

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 16
nop 1
dl 0
loc 287
rs 7.0666
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Docker CLI installer script.
4
 *
5
 * @access private
6
 */
7
8
$enabled = getenv('DOCKER') != ''; //are we in a Docker container?
9
if (!$enabled) {
10
	echo "This script should be run only in a properly configured Docker container environment.\n";
11
	exit(1);
12
}
13
14
if (PHP_SAPI !== 'cli') {
15
	echo "You must use the command line to run this script.\n";
16
	exit(2);
17
}
18
19
$init_type = getenv('INIT');
20
switch ($init_type) {
21
	case 'gcconnex':
22
		$type = "connex";
23
		break;
24
	case 'gccollab':
25
		$type = "collab";
26
		break;
27
	
28
	default:
29
		echo "Install script not running as per configuration ( INIT environment variable not one of gcconnex or gccollab).\n";
30
		exit(0);
31
		break;
32
}
33
34
$elggRoot = dirname(dirname(__DIR__));
35
36
require_once "$elggRoot/vendor/autoload.php";
37
38
$installer = new ElggInstaller();
39
40
if (getenv('DBHOST') != '')
41
	$dbhost = getenv('DBHOST');
42
else
43
	$dbhost = 'gcconnex-db';
44
45
if (getenv('DBUSER') != '')
46
	$dbuser = getenv('DBUSER');
47
else
48
	$dbuser = 'elgg';
49
50
if (getenv('DBPASS') != '')
51
	$dbpass = getenv('DBPASS');
52
else
53
	$dbpass = 'gcconnex';
54
55
if (getenv('DBNAME') != '')
56
	$dbname = getenv('DBNAME');
57
else
58
	$dbname = 'elgg';
59
60
61
if (getenv('WWWROOT') != '')
62
	$wwwroot = getenv('WWWROOT');
63
else
64
	$wwwroot = 'http://localhost:8080/';
65
66
// none of the following may be empty
67
$params = array(
68
	// database parameters
69
	'dbuser' => $dbuser,
70
	'dbpassword' => $dbpass,
71
	'dbname' => $dbname,
72
	
73
	// We use a wonky dbprefix to catch any cases where folks hardcode "elgg_"
74
	// instead of using config->dbprefix
75
	'dbprefix' => 'd_elgg_',
76
	'dbhost' => $dbhost,
77
78
	// site settings
79
	'sitename' => 'Docker GC' . $type,
80
	'siteemail' => '[email protected]',
81
	'wwwroot' => $wwwroot,
82
	'dataroot' => getenv('HOME') . '/data/',
83
84
	// admin account
85
	'displayname' => 'Administrator',
86
	'email' => '[email protected]',
87
	'username' => 'admin',
88
	'password' => 'adminpassword',
89
);
90
91
// wait for db to be ready
92
echo "Connecting to database..";
93
$etmp = error_reporting(E_ERROR);     // don't need all the connection errors...
94
95
do{
96
  echo ".";
97
  sleep(1); // wait for the db container
98
  $dbconnect = mysqli_connect($dbhost, $params['dbuser'], $params['dbpassword']);
99
}while(!$dbconnect);
100
101
echo "Connected!";
102
mysqli_close($dbconnect);
103
error_reporting($etmp);     // revert error reporting to default
104
105
// install and create the .htaccess file
106
$installer->batchInstall($params, TRUE);
107
108
// at this point installation has completed (otherwise an exception halted execution).
109
echo "Elgg CLI install successful. wwwroot: " . elgg_get_config('wwwroot') . "\n";
110
111
// arrange and activate mods
112
init_mods( $type );
113
114
echo "Elgg CLI plugin install successful. \n";
115
116
117
function init_mods( $type ){
118
	
119
// GCcollab
120
$plugins_connex = array(
121
	'garbagecollector',
122
	'groups',
123
	'logrotate',
124
	'group_tools',
125
	'blog',
126
	'bookmarks',
127
	'dashboard',
128
	'diagnostics',
129
	'friend_request',
130
	'externalpages',
131
	'file',
132
	'embed',
133
	'group_operators',
134
	'htmlawed',
135
	'invitefriends',
136
	'likes',
137
	'logbrowser',
138
	'gcforums',
139
	'messageboard',
140
	'messages',
141
	'polls',
142
	'profile',
143
	'rename_friends',
144
	'members',
145
	'thewire',
146
	'uservalidationbyemail',
147
	'unvalidatedemailchange',
148
	'widget_manager',
149
	'zaudio',
150
	'custom_index_widgets',
151
	'file_tools',
152
	'event_calendar',
153
	'ideas',
154
	'pages',
155
	'analytics',
156
	'tidypics',
157
	'translation_editor',
158
	'gcProfilePictureBadges',
159
	'upload_users',
160
	'c_email_extensions',
161
	'gcRegistration',
162
	'c_module_dump',
163
	'au_subgroups',
164
	'widget_manager_accessibility',
165
	'b_extended_profile',
166
	'c_members_byDepartment',
167
	'blog_tools',
168
	'ckeditor',
169
	'contactform',
170
	'site_notifications',
171
	'web_services',
172
	'missions_organization',
173
	'missions',
174
	'data_views',
175
	'mt_activity_tabs',
176
	'geds_sync',
177
	'gc_api',
178
	'achievement_badges',
179
	'embed_extender',
180
	'toggle_language',
181
	'cp_notifications',
182
	'login_as',
183
	'thewire_tools',
184
	'mentions',
185
	'GoC_dev_banner',
186
	'questions',
187
	'wet4',
188
	'GC_profileStrength',
189
	'saml_link',
190
	'simplesaml',
191
	'elgg-jsonp',
192
	'machine_translation',
193
	'phpmailer',
194
	'gc_newsfeed',
195
	'gc_onboard',
196
	'gc_splash_page',
197
	'gc_group_layout',
198
	'gcconnex_theme',
199
	'gc_streaming_content',
200
	'multi_file_upload',
201
	'gccollab_stats',
202
	'gc_communities',
203
	'gc_tags',
204
	'gc_elgg_sitemap',
205
	);
206
	$plugins_off_connex = array(
207
	'developers',
208
	'oauth_api',
209
	'reportedcontent',
210
	'search',
211
	'tagcloud',
212
	'tasks',
213
	'twitter',
214
	'unvalidated_user_cleanup',
215
	'twitter_api',
216
	'sphinx',
217
	'gc_group_deletion',
218
	'custom_error_page',
219
	'maintenance',
220
	'gc_fedsearch_gsa',
221
	'gc_official_groups',
222
	'apiadmin',
223
	'gc_profile_nudge',
224
	'enhanced_user_search',
225
	'GC_profileStrength_collab',
226
	'b_extended_profile_collab',
227
	'gcRegistration_collab',
228
	'gc_onboard_collab',
229
	'gc_splash_page_collab',
230
	'gccollab_theme',
231
	);
232
	
233
	
234
	// GCcollab	
235
	$plugins_collab = array(
236
	'garbagecollector',
237
	'groups',
238
	'logrotate',
239
	'group_tools',
240
	'blog',
241
	'bookmarks',
242
	'dashboard',
243
	'diagnostics',
244
	'friend_request',
245
	'externalpages',
246
	'file',
247
	'embed',
248
	'group_operators',
249
	'htmlawed',
250
	'invitefriends',
251
	'likes',
252
	'logbrowser',
253
	'messageboard',
254
	'messages',
255
	'polls',
256
	'profile',
257
	'rename_friends',
258
	'search',
259
	'members',
260
	'thewire',
261
	'uservalidationbyemail',
262
	'unvalidatedemailchange',
263
	'widget_manager',
264
	'zaudio',
265
	'custom_index_widgets',
266
	'file_tools',
267
	'event_calendar',
268
	'ideas',
269
	'unvalidated_user_cleanup',
270
	'pages',
271
	'analytics',
272
	'tidypics',
273
	'translation_editor',
274
	'gcProfilePictureBadges',
275
	'upload_users',
276
	'c_email_extensions',
277
	'gcRegistration_collab',
278
	'c_module_dump',
279
	'au_subgroups',
280
	'widget_manager_accessibility',
281
	'b_extended_profile',
282
	'b_extended_profile_collab',
283
	'blog_tools',
284
	'ckeditor',
285
	'contactform',
286
	'site_notifications',
287
	'web_services',
288
	'missions_organization',
289
	'missions',
290
	'missions_collab',
291
	'data_views',
292
	'mt_activity_tabs',
293
	'gc_api',
294
	'achievement_badges',
295
	'embed_extender',
296
	'toggle_language',
297
	'cp_notifications',
298
	'login_as',
299
	'thewire_tools',
300
	'mentions',
301
	'GoC_dev_banner',
302
	'etherpad',
303
	'wet4',
304
	'wet4_collab',
305
	'GC_profileStrength',
306
	'GC_profileStrength_collab',
307
	'elgg-jsonp',
308
	'phpmailer',
309
	'gc_onboard',
310
	'gc_onboard_collab',
311
	'gc_newsfeed',
312
	'gc_splash_page',
313
	'gc_splash_page_collab',
314
	'gc_group_layout',
315
	'freshdesk_help',
316
	'gccollab_stats',
317
	'gccollab_theme',
318
	'gc_streaming_content',
319
	'multi_file_upload',
320
	'vroom',
321
	'elgg_solr',
322
	'elgg_recaptcha',
323
	'loginrequired',
324
	'gcRegistration_invitation',
325
	'gc_autosubscribegroup',
326
	'linkedin_profile_importer',
327
	'apiadmin',
328
	'gc_mobile_api',
329
	'gc_communities',
330
	'gc_tags',
331
	'gc_elgg_sitemap',
332
	'thewire_images',
333
	'pleio',
334
	);
335
	$plugins_off_collab = array(
336
	'developers',
337
	'gcforums',
338
	'oauth_api',
339
	'reportedcontent',
340
	'tagcloud',
341
	'tasks',
342
	'twitter',
343
	'twitter_api',
344
	'sphinx',
345
	'gcRegistration',
346
	'c_members_byDepartment',
347
	'gc_group_deletion',
348
	'custom_error_page',
349
	'geds_sync',
350
	'questions',
351
	'saml_link',
352
	'simplesaml',
353
	'maintenance',
354
	'machine_translation',
355
	'gcconnex_theme',
356
	'gc_fedsearch_gsa',
357
	'gc_official_groups',
358
	'apiadmin',
359
	'gc_profile_nudge',
360
	'enhanced_user_search',
361
	);
362
	
363
364
	// deactivate plugins that are not active in prod, order doesn't matter.
365
	// This happens first to ensure we don't run into conflicts when activating mods in the next step
366
	$plugins_off = ${"plugins_off_$type"};
367
	foreach ($plugins_off as $key => $id) {
368
		$plugin = elgg_get_plugin_from_id($id);
369
370
		if (!$plugin) {
371
			unset($plugins_off[$key]);
372
			continue;
373
		}
374
375
		if (!$plugin->isActive()){
376
			unset($plugins_off[$key]);
377
			continue;
378
		}
379
380
		$plugin->deactivate();
381
	}
382
383
384
	// activate plugins that are not activated on install, arrange those that are
385
	$plugins = ${"plugins_$type"};
386
	foreach ($plugins as $key => $id) {
387
		$plugin = elgg_get_plugin_from_id($id);
388
389
		if (!$plugin) {
390
			unset($plugins[$key]);
391
			continue;
392
		}
393
394
		$plugin->setPriority('last');	// move to the end of the list
395
396
		if ($plugin->isActive()){
397
			unset($plugins[$key]);
398
			continue;
399
		}
400
401
		$plugin->activate();
402
	}
403
}
404