forked from Elgg/Elgg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
elgg-cli
65 lines (53 loc) · 1.62 KB
/
elgg-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env php
<?php
if (PHP_SAPI !== 'cli') {
echo "You must use the command line to run this script." . PHP_EOL;
die(1);
}
// Load dependencies
// Check various installation paths, which may vary depending on how Elgg was installed
$files = [
__DIR__ . '/../../autoload.php', // Elgg in Composer project
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/vendor/autoload.php', // Elgg as base path
__DIR__ . '/../autoload.php', // from Composer bin directory
];
foreach ($files as $file) {
if (file_exists($file)) {
require_once $file;
}
}
if (!class_exists('\Elgg\Application')) {
fwrite(STDERR, "Composer dependencies are not installed "
. "or you are trying to run the script outside of an Elgg installation's root directory." . PHP_EOL);
die(2);
}
$settings_file = \Elgg\Project\Paths::settingsFile();
$installed = is_file($settings_file);
if (!$installed) {
$cli = new Symfony\Component\Console\Application();
$cli->add(new \Elgg\Cli\InstallCommand());
$cli->run();
return;
}
$app = \Elgg\Application::getInstance();
$services = $app->_services;
$logger = $services->logger;
$cli = $services->cli;
$cli->setLogger($logger);
$argv = $services->request->server->get('argv');
if ($argv[1] === 'upgrade') {
// To run an upgrade successfully, we must first migrate
// the application before booting it
$cli->add(\Elgg\Cli\UpgradeCommand::class);
$cli->run(false);
return;
}
// For other commands, we just boot an application
try {
$app->start();
$cli->run();
} catch (\Throwable $throw) {
fwrite(STDERR, "An error occured during the execution of the command '{$argv[0]}': {$throw->getMessage()}" . PHP_EOL);
die(3);
}