Completed
Push — 3.1 ( d59679...4b8741 )
by Jeroen
62:38 queued 13s
created

engine/classes/Elgg/Composer/PostInstall.php (2 issues)

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) {
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
			'likes',
44
			'members',
45
			'messageboard',
46
			'messages',
47
			'notifications',
48
			'pages',
49
			'profile',
50
			'reportedcontent',
51
			'search',
52
			'site_notifications',
53
			'system_log',
54
			'tagcloud',
55
			'thewire',
56
			'uservalidationbyemail',
57
			'web_services',
58
		];
59
60
		foreach ($managed_plugins as $plugin) {
61
			self::symlinkPluginFromRootToElgg($plugin);
62
		}
63
	}
64
65
	/**
66
	 * Copies a file from the given location in Elgg to the given location in root.
67
	 *
68
	 * @param string $elggPath  Path relative to elgg dir.
69
	 * @param string $rootPath  Path relative to app root dir.
70
	 * @param bool   $overwrite Overwrite file if it exists in root path, defaults to false.
71
	 *
72
	 * @return boolean Whether the copy succeeded.
73
	 */
74
	private static function copyFromElggToRoot($elggPath, $rootPath, $overwrite = false) {
0 ignored issues
show
Private method name "PostInstall::copyFromElggToRoot" must be prefixed with an underscore
Loading history...
75
		$from = Elgg\Application::elggDir()->getPath($elggPath);
76
		$to = Directory\Local::projectRoot()->getPath($rootPath);
77
78
		if (!$overwrite && file_exists($to)) {
79
			return false;
80
		}
81
82
		return copy($from, $to);
83
	}
84
85
	/**
86
	 * Make it possible for composer-managed Elgg site to recognize plugins
87
	 * version-controlled in Elgg core.
88
	 *
89
	 * @param string $plugin The name of the plugin to symlink
90
	 *
91
	 * @return bool Whether the symlink succeeded.
92
	 */
93
	private static function symlinkPluginFromRootToElgg($plugin) {
0 ignored issues
show
Private method name "PostInstall::symlinkPluginFromRootToElgg" must be prefixed with an underscore
Loading history...
94
		$from = Directory\Local::projectRoot()->getPath("mod/$plugin");
95
		$to = Elgg\Application::elggDir()->getPath("mod/$plugin");
96
97
		return !file_exists($from) && symlink($to, $from);
98
	}
99
}
100