Update git submodules
[mediawiki.git] / maintenance / checkComposerLockUpToDate.php
blob196c32505f3a47368d6b91666abf521a6d38018b
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 use Composer\Semver\Semver;
7 /**
8 * Checks whether your composer-installed dependencies are up to date
10 * Composer creates a "composer.lock" file which specifies which versions are installed
11 * (via `composer install`). It has a hash, which can be compared to the value of
12 * the composer.json file to see if dependencies are up to date.
14 class CheckComposerLockUpToDate extends Maintenance {
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' );
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"?'
35 $lock = new ComposerLock( $lockLocation );
36 $json = new ComposerJson( $jsonLocation );
38 $requiredButOld = [];
39 $requiredButMissing = [];
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
50 continue;
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']
62 // We're happy; loop to the next dependency.
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;
71 foreach ( $requiredButOld as [
72 "name" => $name,
73 "suppliedVersion" => $suppliedVersion,
74 "wantedVersion" => $wantedVersion
75 ] ) {
76 $this->error( "$name: $suppliedVersion installed, $wantedVersion required.\n" );
79 foreach ( $requiredButMissing as [
80 "name" => $name,
81 "wantedVersion" => $wantedVersion
82 ] ) {
83 $this->error( "$name: not installed, $wantedVersion required.\n" );
86 $this->fatalError(
87 'Error: your composer.lock file is not up to date. ' .
88 'Run "composer update --no-dev" to install newer dependencies'
93 $maintClass = CheckComposerLockUpToDate::class;
94 require_once RUN_MAINTENANCE_IF_MAIN;