Elgg  Version 6.3
PostInstall.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Composer;
4 
5 use Composer\Script\Event;
7 
11 class PostInstall {
12 
20  public static function execute(Event $event): void {
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 
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) {
33  }
34  }
35  }
36 
46  protected static function copyFromElggToRoot(string $elggPath, string $rootPath, bool $overwrite = false): bool {
47  $from = Paths::elgg() . $elggPath;
48  $to = Paths::project() . $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 = Paths::project() . 'mod';
66  $elgg_mod = Paths::elgg() . '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(string $plugin): bool {
90  $link = Paths::project() . "mod/{$plugin}";
91  $target = Paths::elgg() . "mod/{$plugin}";
92 
93  return is_dir($target) && !file_exists($link) && symlink($target, $link);
94  }
95 }
A composer command handler to run after composer install.
Definition: PostInstall.php:11
static copyFromElggToRoot(string $elggPath, string $rootPath, bool $overwrite=false)
Copies a file from the given location in Elgg to the given location in root.
Definition: PostInstall.php:46
static createProjectModFolder()
Make sure the /mod folder exists in when Elgg is installed through a Composer project eg.
Definition: PostInstall.php:64
static symlinkPluginFromRootToElgg(string $plugin)
Make it possible for composer-managed Elgg site to recognize plugins version-controlled in Elgg core.
Definition: PostInstall.php:89
static execute(Event $event)
Copies files that Elgg expects to be in the root directory.
Definition: PostInstall.php:20
Find Elgg and project paths.
Definition: Paths.php:8
static project()
Get the project root (where composer is installed) path with "/".
Definition: Paths.php:25
if(! $item instanceof ElggEntity) $link
Definition: container.php:16
elgg()
Bootstrapping and helper procedural code available for use in Elgg core and plugins.
Definition: elgglib.php:12
string project
Definition: conf.py:52
$target
Definition: create.php:17
$plugin