Elgg  Version master
PostInstall.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Composer;
4 
7 
11 class PostInstall {
12 
20  public static function execute(Event $event) {
21  self::copyFromElggToRoot('install/config/htaccess.dist', '.htaccess');
22  self::copyFromElggToRoot('index.php', 'index.php');
23  self::copyFromElggToRoot('install.php', 'install.php');
24  self::copyFromElggToRoot('upgrade.php', 'upgrade.php');
25 
26  self::createProjectModFolder();
27 
28  if (stripos(PHP_OS, 'win') !== 0) {
29  // symlink the mods from Elgg /mod to the project /mod
30  $managed_plugins = \Elgg\Database\Plugins::BUNDLED_PLUGINS;
31  foreach ($managed_plugins as $plugin) {
32  self::symlinkPluginFromRootToElgg($plugin);
33  }
34  }
35  }
36 
46  protected static function copyFromElggToRoot($elggPath, $rootPath, $overwrite = false) {
47  $from = Local::elggRoot()->getPath($elggPath);
48  $to = Local::projectRoot()->getPath($rootPath);
49 
50  if (!$overwrite && file_exists($to)) {
51  return false;
52  }
53 
54  return copy($from, $to);
55  }
56 
64  protected static function createProjectModFolder(): bool {
65  $project_mod = Local::projectRoot()->getPath('mod');
66  $elgg_mod = Local::elggRoot()->getPath('mod');
67 
68  if ($project_mod === $elgg_mod) {
69  // Elgg is the main project, no need to create the /mod folder
70  return false;
71  }
72 
73  if (is_dir($project_mod)) {
74  // /mod folder already exists
75  return false;
76  }
77 
78  return mkdir($project_mod, 0755);
79  }
80 
89  protected static function symlinkPluginFromRootToElgg($plugin) {
90  $link = Local::projectRoot()->getPath("mod/{$plugin}");
91  $target = Local::elggRoot()->getPath("mod/{$plugin}");
92 
93  return is_dir($target) && !file_exists($link) && symlink($target, $link);
94  }
95 }
$plugin
static projectRoot()
Get the root composer install directory.
Definition: Local.php:36
if(!$item instanceof ElggEntity) $link
Definition: container.php:16
$target
Definition: create.php:17
static elggRoot()
Get the Elgg root directory.
Definition: Local.php:53
static symlinkPluginFromRootToElgg($plugin)
Make it possible for composer-managed Elgg site to recognize plugins version-controlled in Elgg core...
Definition: PostInstall.php:89
A composer command handler to run after composer install.
Definition: PostInstall.php:11
and give any other recipients of the Program a copy of this License along with the Program You may charge a fee for the physical act of transferring a copy
Definition: LICENSE.txt:140
static createProjectModFolder()
Make sure the /mod folder exists in when Elgg is installed through a Composer project eg...
Definition: PostInstall.php:64
static execute(Event $event)
Copies files that Elgg expects to be in the root directory.
Definition: PostInstall.php:20
static copyFromElggToRoot($elggPath, $rootPath, $overwrite=false)
Copies a file from the given location in Elgg to the given location in root.
Definition: PostInstall.php:46