Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / maintenance / checkComposerLockUpToDate.php
blobb504bded778f90ec72419e93846226b97900b56f
1 <?php
3 require_once __DIR__ . '/Maintenance.php';
5 /**
6 * Checks whether your composer-installed dependencies are up to date
8 * Composer creates a "composer.lock" file which specifies which versions are installed
9 * (via `composer install`). It has a hash, which can be compared to the value of
10 * the composer.json file to see if dependencies are up to date.
12 class CheckComposerLockUpToDate extends Maintenance {
13 public function __construct() {
14 parent::__construct();
15 $this->addDescription(
16 'Checks whether your composer.lock file is up to date with the current composer.json' );
19 public function execute() {
20 global $IP;
21 $lockLocation = "$IP/composer.lock";
22 $jsonLocation = "$IP/composer.json";
23 if ( !file_exists( $lockLocation ) ) {
24 // Maybe they're using mediawiki/vendor?
25 $lockLocation = "$IP/vendor/composer.lock";
26 if ( !file_exists( $lockLocation ) ) {
27 $this->error(
28 'Could not find composer.lock file. Have you run "composer install"?',
34 $lock = new ComposerLock( $lockLocation );
35 $json = new ComposerJson( $jsonLocation );
37 // Check all the dependencies to see if any are old
38 $found = false;
39 $installed = $lock->getInstalledDependencies();
40 foreach ( $json->getRequiredDependencies() as $name => $version ) {
41 if ( isset( $installed[$name] ) ) {
42 if ( $installed[$name]['version'] !== $version ) {
43 $this->output(
44 "$name: {$installed[$name]['version']} installed, $version required.\n"
46 $found = true;
48 } else {
49 $this->output( "$name: not installed, $version required.\n" );
50 $found = true;
53 if ( $found ) {
54 $this->error(
55 'Error: your composer.lock file is not up to date. ' .
56 'Run "composer update" to install newer dependencies',
59 } else {
60 // We couldn't find any out-of-date dependencies, so assume everything is ok!
61 $this->output( "Your composer.lock file is up to date with current dependencies!\n" );
66 $maintClass = 'CheckComposerLockUpToDate';
67 require_once RUN_MAINTENANCE_IF_MAIN;