MediaWiki  1.34.0
checkComposerLockUpToDate.php
Go to the documentation of this file.
1 <?php
2 
3 require_once __DIR__ . '/Maintenance.php';
4 
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' );
17  }
18 
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->fatalError(
28  'Could not find composer.lock file. Have you run "composer install --no-dev"?'
29  );
30  }
31  }
32 
33  $lock = new ComposerLock( $lockLocation );
34  $json = new ComposerJson( $jsonLocation );
35 
36  // Check all the dependencies to see if any are old
37  $found = false;
38  $installed = $lock->getInstalledDependencies();
39  foreach ( $json->getRequiredDependencies() as $name => $version ) {
40  if ( isset( $installed[$name] ) ) {
41  if ( $installed[$name]['version'] !== $version ) {
42  $this->output(
43  "$name: {$installed[$name]['version']} installed, $version required.\n"
44  );
45  $found = true;
46  }
47  } else {
48  $this->output( "$name: not installed, $version required.\n" );
49  $found = true;
50  }
51  }
52  if ( $found ) {
53  $this->fatalError(
54  'Error: your composer.lock file is not up to date. ' .
55  'Run "composer update --no-dev" to install newer dependencies'
56  );
57  } else {
58  // We couldn't find any out-of-date dependencies, so assume everything is ok!
59  $this->output( "Your composer.lock file is up to date with current dependencies!\n" );
60  }
61  }
62 }
63 
64 $maintClass = CheckComposerLockUpToDate::class;
65 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
ComposerJson
Reads a composer.json file and provides accessors to get its hash and the required dependencies.
Definition: ComposerJson.php:9
CheckComposerLockUpToDate\execute
execute()
Do the actual work.
Definition: checkComposerLockUpToDate.php:19
Maintenance\fatalError
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Definition: Maintenance.php:504
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
CheckComposerLockUpToDate
Checks whether your composer-installed dependencies are up to date.
Definition: checkComposerLockUpToDate.php:12
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
ComposerLock
Reads a composer.lock file and provides accessors to get its hash and what is installed.
Definition: ComposerLock.php:9
$IP
$IP
Definition: update.php:3
CheckComposerLockUpToDate\__construct
__construct()
Default constructor.
Definition: checkComposerLockUpToDate.php:13
$maintClass
$maintClass
Definition: checkComposerLockUpToDate.php:64
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453