Update to Composer 2 (#12263)

* Update to Composer 2

No need to roll our own checks anymore since this is now built in.
Also limit the update check to once a week.

* update

* Make Composer wrapper report correct exit code

* Update composer_wrapper.php

* re-enable extension check

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
Jellyfrog 2020-11-09 07:28:07 +01:00 committed by GitHub
parent 591384f321
commit b7676e4cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 15 additions and 88 deletions

View File

@ -34,44 +34,6 @@ use Toastr;
class Checks
{
public static function preAutoload()
{
// Check PHP version otherwise it will just say server error
if (version_compare(PHP_VERSION, '7.3', '<')) {
self::printMessage(
'PHP version 7.3 or newer is required to run LibreNMS',
null,
true
);
}
}
/**
* Pre-boot dependency check
*/
public static function postAutoload()
{
if (! class_exists(\Illuminate\Foundation\Application::class)) {
self::printMessage(
'Error: Missing dependencies! Run the following command to fix:',
'./scripts/composer_wrapper.php install --no-dev',
true
);
}
}
public static function preBoot()
{
// check php extensions
if ($missing = self::missingPhpExtensions()) {
self::printMessage(
'Missing PHP extensions. Please install and enable them on your LibreNMS server.',
$missing,
true
);
}
}
/**
* Post boot Toast messages
*/
@ -156,18 +118,4 @@ class Checks
exit(1);
}
}
private static function missingPhpExtensions()
{
// allow mysqli, but prefer mysqlnd
if (! extension_loaded('mysqlnd') && ! extension_loaded('mysqli')) {
return ['mysqlnd'];
}
$required_modules = ['mbstring', 'pcre', 'curl', 'xml', 'gd'];
return array_filter($required_modules, function ($module) {
return ! extension_loaded($module);
});
}
}

View File

@ -2,7 +2,6 @@
namespace App\Http;
use App\Checks;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
@ -96,10 +95,4 @@ class Kernel extends HttpKernel
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Illuminate\Auth\Middleware\Authorize::class,
];
public function bootstrap()
{
Checks::preBoot();
parent::bootstrap();
}
}

View File

@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
@ -13,7 +15,7 @@
|
*/
require __DIR__.'/bootstrap/autoload.php';
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

View File

@ -1,22 +0,0 @@
<?php
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Composer Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so we do not have to manually load any of
| our application's PHP classes. It just feels great to relax.
|
*/
@require_once __DIR__ . '/../app/Checks.php';
\App\Checks::preAutoload();
@include __DIR__ . '/../vendor/autoload.php';
\App\Checks::postAutoload();

View File

@ -100,6 +100,7 @@
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true,
"platform-check": true,
"discard-changes": true
},
"scripts": {

View File

@ -22,7 +22,7 @@ you can do so by running the following commands:
```bash
cd /opt/librenms
git pull
composer install --no-dev
./scripts/composer_wrapper.php install --no-dev
php includes/sql-schema/update.php
./validate.php
```

View File

@ -18,7 +18,7 @@
|
*/
require __DIR__ . '/../bootstrap/autoload.php';
require __DIR__ . '/../vendor/autoload.php';
/*
|--------------------------------------------------------------------------

2
lnms
View File

@ -13,7 +13,7 @@
|
*/
require __DIR__.'/bootstrap/autoload.php';
require __DIR__.'/vendor/autoload.php';
// Check that we don't run this as the wrong user and break the install
\App\Checks::runningUser();

View File

@ -55,8 +55,12 @@ if (php_sapi_name() == 'cli' && isset($_SERVER['TERM'])) {
if (is_file($install_dir . '/composer.phar')) {
$exec = PHP_BINDIR . '/php ' . $install_dir . '/composer.phar';
// self-update
passthru("$exec self-update -q" . $extra_args);
// If older than 1 week, try update
if (time() - filemtime($install_dir . '/composer.phar') > 60 * 60 * 24 * 7) {
// self-update
passthru("$exec self-update --quiet --2" . $extra_args);
touch($install_dir . '/composer.phar');
}
} else {
$sig_url = ($use_https ? 'https' : 'http') . '://composer.github.io/installer.sig';
@ -93,7 +97,8 @@ if (! $exec) {
}
if ($exec) {
passthru("$exec " . implode(' ', array_splice($argv, 1)) . "$extra_args 2>&1");
passthru("$exec " . implode(' ', array_splice($argv, 1)) . "$extra_args 2>&1", $exit_code);
exit($exit_code);
} else {
echo "Composer not available, please manually install composer.\n";
}