Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

engine/classes/Elgg/Composer/PostInstall.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
namespace Elgg\Composer;
3
4
use Composer\Script\Event;
5
use Elgg;
6
use Elgg\Filesystem\Directory;
7
8
/**
9
 * A composer command handler to run after composer install
10
 */
11
class PostInstall {
12
	/**
13
	 * Copies files that Elgg expects to be in the root directory.
14
	 *
15
	 * @param Event $event The Composer event (install/upgrade)
16
	 *
17
	 * @return void
18
	 */
19
	public static function execute(Event $event) {
0 ignored issues
show
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
20
		self::copyFromElggToRoot("install/config/htaccess.dist", ".htaccess");
21
		self::copyFromElggToRoot("index.php", "index.php");
22
		self::copyFromElggToRoot("install.php", "install.php");
23
		self::copyFromElggToRoot("upgrade.php", "upgrade.php");
24
25
		$managed_plugins = [
26
			'activity',
27
			'blog',
28
			'bookmarks',
29
			'ckeditor',
30
			'custom_index',
31
			'dashboard',
32
			'developers',
33
			'diagnostics',
34
			'discussions',
35
			'embed',
36
			'externalpages',
37
			'file',
38
			'friends',
39
			'friends_collections',
40
			'garbagecollector',
41
			'groups',
42
			'invitefriends',
43
			'legacy_urls',
44
			'likes',
45
			'logbrowser',
46
			'logrotate',
47
			'members',
48
			'messageboard',
49
			'messages',
50
			'notifications',
51
			'pages',
52
			'profile',
53
			'reportedcontent',
54
			'search',
55
			'site_notifications',
56
			'tagcloud',
57
			'thewire',
58
			'uservalidationbyemail',
59
			'web_services',
60
		];
61
62
		foreach ($managed_plugins as $plugin) {
63
			self::symlinkPluginFromRootToElgg($plugin);
64
		}
65
	}
66
67
	/**
68
	 * Copies a file from the given location in Elgg to the given location in root.
69
	 *
70
	 * @param string $elggPath  Path relative to elgg dir.
71
	 * @param string $rootPath  Path relative to app root dir.
72
	 * @param bool   $overwrite Overwrite file if it exists in root path, defaults to false.
73
	 *
74
	 * @return boolean Whether the copy succeeded.
75
	 */
76
	private static function copyFromElggToRoot($elggPath, $rootPath, $overwrite = false) {
77
		$from = Elgg\Application::elggDir()->getPath($elggPath);
78
		$to = Directory\Local::projectRoot()->getPath($rootPath);
79
80
		if (!$overwrite && file_exists($to)) {
81
			return false;
82
		}
83
84
		return copy($from, $to);
85
	}
86
87
	/**
88
	 * Make it possible for composer-managed Elgg site to recognize plugins
89
	 * version-controlled in Elgg core.
90
	 *
91
	 * @param string $plugin The name of the plugin to symlink
92
	 *
93
	 * @return bool Whether the symlink succeeded.
94
	 */
95
	private static function symlinkPluginFromRootToElgg($plugin) {
96
		$from = Directory\Local::projectRoot()->getPath("mod/$plugin");
97
		$to = Elgg\Application::elggDir()->getPath("mod/$plugin");
98
99
		return !file_exists($from) && symlink($to, $from);
100
	}
101
}
102