X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/checkComposerLockUpToDate.php diff --git a/maintenance/checkComposerLockUpToDate.php b/maintenance/checkComposerLockUpToDate.php new file mode 100644 index 00000000..e5b4c13e --- /dev/null +++ b/maintenance/checkComposerLockUpToDate.php @@ -0,0 +1,67 @@ +addDescription( + 'Checks whether your composer.lock file is up to date with the current composer.json' ); + } + + public function execute() { + global $IP; + $lockLocation = "$IP/composer.lock"; + $jsonLocation = "$IP/composer.json"; + if ( !file_exists( $lockLocation ) ) { + // Maybe they're using mediawiki/vendor? + $lockLocation = "$IP/vendor/composer.lock"; + if ( !file_exists( $lockLocation ) ) { + $this->error( + 'Could not find composer.lock file. Have you run "composer install --no-dev"?', + 1 + ); + } + } + + $lock = new ComposerLock( $lockLocation ); + $json = new ComposerJson( $jsonLocation ); + + // Check all the dependencies to see if any are old + $found = false; + $installed = $lock->getInstalledDependencies(); + foreach ( $json->getRequiredDependencies() as $name => $version ) { + if ( isset( $installed[$name] ) ) { + if ( $installed[$name]['version'] !== $version ) { + $this->output( + "$name: {$installed[$name]['version']} installed, $version required.\n" + ); + $found = true; + } + } else { + $this->output( "$name: not installed, $version required.\n" ); + $found = true; + } + } + if ( $found ) { + $this->error( + 'Error: your composer.lock file is not up to date. ' . + 'Run "composer update --no-dev" to install newer dependencies', + 1 + ); + } else { + // We couldn't find any out-of-date dependencies, so assume everything is ok! + $this->output( "Your composer.lock file is up to date with current dependencies!\n" ); + } + } +} + +$maintClass = 'CheckComposerLockUpToDate'; +require_once RUN_MAINTENANCE_IF_MAIN;