MediaWiki 1.42.1
checkComposerLockUpToDate.php
Go to the documentation of this file.
1<?php
2
3require_once __DIR__ . '/Maintenance.php';
4
8
17 public function __construct() {
18 parent::__construct();
19 $this->addDescription(
20 'Checks whether your composer.lock file is up to date with the current composer.json' );
21 }
22
23 public function execute() {
24 global $IP;
25 $lockLocation = "$IP/composer.lock";
26 $jsonLocation = "$IP/composer.json";
27 if ( !file_exists( $lockLocation ) ) {
28 // Maybe they're using mediawiki/vendor?
29 $lockLocation = "$IP/vendor/composer.lock";
30 if ( !file_exists( $lockLocation ) ) {
31 $this->fatalError(
32 'Could not find composer.lock file. Have you run "composer install --no-dev"?'
33 );
34 }
35 }
36
37 $lock = new ComposerLock( $lockLocation );
38 $json = new ComposerJson( $jsonLocation );
39
40 // Check all the dependencies to see if any are old
41 $checker = new LockFileChecker( $json, $lock );
42 $result = $checker->check();
43 if ( $result->isGood() ) {
44 // We couldn't find any out-of-date dependencies, so assume everything is ok!
45 $this->output( "Your composer.lock file is up to date with current dependencies!\n" );
46 } else {
47 // NOTE: wfMessage will fail if MediaWikiServices is not yet initialized.
48 // This can happen when this class is called directly from bootstrap code,
49 // e.g. by TestSetup. We get around this by having testSetup use quiet mode.
50 if ( !$this->isQuiet() ) {
51 foreach ( $result->getErrors() as $error ) {
52 $this->error(
53 wfMessage( $error['message'], ...$error['params'] )->inLanguage( 'en' )->plain() . "\n"
54 );
55 }
56 }
57 $this->fatalError(
58 'Error: your composer.lock file is not up to date. ' .
59 'Run "composer update --no-dev" to install newer dependencies'
60 );
61 }
62 }
63}
64
65$maintClass = CheckComposerLockUpToDate::class;
66require_once RUN_MAINTENANCE_IF_MAIN;
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MEDIAWIKI')) if(ini_get('mbstring.func_overload')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
Definition Setup.php:98
Checks whether your composer-installed dependencies are up to date.
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.
Used to check whether composer-installed dependencies (no-dev) 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.