TheDJ has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/371965 )
Change subject: update.php: Check for outdated composer deps of extensions ...................................................................... update.php: Check for outdated composer deps of extensions Bug: T119711 Change-Id: I6d4f427eb255b6638ac51ae5537d62d2fe54d37d --- M maintenance/checkComposerLockUpToDate.php 1 file changed, 46 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/65/371965/1 diff --git a/maintenance/checkComposerLockUpToDate.php b/maintenance/checkComposerLockUpToDate.php index b504bde..afbcc15 100644 --- a/maintenance/checkComposerLockUpToDate.php +++ b/maintenance/checkComposerLockUpToDate.php @@ -10,24 +10,51 @@ * the composer.json file to see if dependencies are up to date. */ class CheckComposerLockUpToDate extends Maintenance { + public function __construct() { parent::__construct(); $this->addDescription( 'Checks whether your composer.lock file is up to date with the current composer.json' ); + $this->addOption( 'without-extensions', 'Also recurse the extensions folder' ); } public function execute() { global $IP; - $lockLocation = "$IP/composer.lock"; - $jsonLocation = "$IP/composer.json"; + + $this->updateComposerDirectory( "$IP", true ); + + if ( $this->hasOption( 'without-extensions' ) ) { + return; + } + + $installedExtensions = ExtensionRegistry::getInstance()->getAllThings(); + + foreach ( $installedExtensions as $extensionName => $extensionInfo ) { + $directory = dirname( $extensionInfo[ 'path' ] ); + if ( !$this->isSuitablePath( $directory ) ) { + continue; + } + $this->output( "Checking composer dependencies for: $extensionName\n" ); + $this->updateComposerDirectory( dirname( $extensionInfo[ 'path' ] ) ); + } + } + + public function updateComposerDirectory( $directory, $root = false ) { + global $IP; + $lockLocation = "$directory/composer.lock"; + $jsonLocation = "$directory/composer.json"; + $workingDir = $root ? '' : " -d \"{$directory}\""; + 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"?', - 1 + "Could not find composer.lock file.\n" . + "Have you run 'composer install{$workingDir}' ?\n", + $root ? true : false ); + return; } } @@ -53,7 +80,7 @@ if ( $found ) { $this->error( 'Error: your composer.lock file is not up to date. ' . - 'Run "composer update" to install newer dependencies', + "Run 'composer update{$workingDir}' to install newer dependencies", 1 ); } else { @@ -61,6 +88,20 @@ $this->output( "Your composer.lock file is up to date with current dependencies!\n" ); } } + + /** + * Returns true if $directory is of a type we can check + * @param string $directory + * @return bool + */ + private function isSuitablePath( $directory ) { + $directory = str_replace( '\\', '/', $directory ); + if ( file_exists( "$directory/composer.json" ) ) { + return true; + } + + return false; + } } $maintClass = 'CheckComposerLockUpToDate'; -- To view, visit https://gerrit.wikimedia.org/r/371965 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6d4f427eb255b6638ac51ae5537d62d2fe54d37d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: TheDJ <hartman.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits