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