MediaWiki 1.41.2
checkComposerLockUpToDate.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/Maintenance.php';
4
5use Composer\Semver\Semver;
6
15 public function __construct() {
16 parent::__construct();
17 $this->addDescription(
18 'Checks whether your composer.lock file is up to date with the current composer.json' );
19 }
20
21 public function execute() {
22 global $IP;
23 $lockLocation = "$IP/composer.lock";
24 $jsonLocation = "$IP/composer.json";
25 if ( !file_exists( $lockLocation ) ) {
26 // Maybe they're using mediawiki/vendor?
27 $lockLocation = "$IP/vendor/composer.lock";
28 if ( !file_exists( $lockLocation ) ) {
29 $this->fatalError(
30 'Could not find composer.lock file. Have you run "composer install --no-dev"?'
31 );
32 }
33 }
34
35 $lock = new ComposerLock( $lockLocation );
36 $json = new ComposerJson( $jsonLocation );
37
38 $requiredButOld = [];
39 $requiredButMissing = [];
40
41 // Check all the dependencies to see if any are old
42 $installed = $lock->getInstalledDependencies();
43 foreach ( $json->getRequiredDependencies() as $name => $version ) {
44 // Not installed at all.
45 if ( !isset( $installed[$name] ) ) {
46 $requiredButMissing[] = [
47 'name' => $name,
48 'wantedVersion' => $version
49 ];
50 continue;
51 }
52
53 // Installed; need to check it's the right version
54 if ( !SemVer::satisfies( $installed[$name]['version'], $version ) ) {
55 $requiredButOld[] = [
56 'name' => $name,
57 'wantedVersion' => $version,
58 'suppliedVersion' => $installed[$name]['version']
59 ];
60 }
61
62 // We're happy; loop to the next dependency.
63 }
64
65 if ( count( $requiredButOld ) === 0 && count( $requiredButMissing ) === 0 ) {
66 // We couldn't find any out-of-date or missing dependencies, so assume everything is ok!
67 $this->output( "Your composer.lock file is up to date with current dependencies!\n" );
68 return;
69 }
70
71 foreach ( $requiredButOld as [
72 "name" => $name,
73 "suppliedVersion" => $suppliedVersion,
74 "wantedVersion" => $wantedVersion
75 ] ) {
76 $this->error( "$name: $suppliedVersion installed, $wantedVersion required.\n" );
77 }
78
79 foreach ( $requiredButMissing as [
80 "name" => $name,
81 "wantedVersion" => $wantedVersion
82 ] ) {
83 $this->error( "$name: not installed, $wantedVersion required.\n" );
84 }
85
86 $this->fatalError(
87 'Error: your composer.lock file is not up to date. ' .
88 'Run "composer update --no-dev" to install newer dependencies'
89 );
90 }
91}
92
93$maintClass = CheckComposerLockUpToDate::class;
94require_once RUN_MAINTENANCE_IF_MAIN;
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:96
Checks whether your composer-installed dependencies are up to date.
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Reads a composer.lock file and provides accessors to get its hash and what is installed.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.