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): 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 
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(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 }
static project()
Get the project root (where composer is installed) path with "/".
Definition: Paths.php:25
$plugin
static elgg()
Get the Elgg codebase path with "/".
Definition: Paths.php:44
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
if(!$item instanceof ElggEntity) $link
Definition: container.php:16
$target
Definition: create.php:17
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 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 execute(Event $event)
Copies files that Elgg expects to be in the root directory.
Definition: PostInstall.php:20
static symlinkPluginFromRootToElgg(string $plugin)
Make it possible for composer-managed Elgg site to recognize plugins version-controlled in Elgg core...
Definition: PostInstall.php:89