42 parent::__construct();
44 $this->
addOption(
'extensions',
'Comma separated list of extensions to check',
false,
true );
45 $this->
addOption(
'skins',
'Comma separated list of skins to check',
false,
true );
46 $this->
addOption(
'json',
'Output in JSON' );
47 $this->
addOption(
'dev',
'Check development dependencies too' );
51 $this->checkDev = $this->
hasOption(
'dev' );
52 $extensions = $this->
hasOption(
'extensions' )
53 ? explode(
',', $this->
getOption(
'extensions' ) )
56 ? explode(
',', $this->
getOption(
'skins' ) )
62 $registry = ExtensionRegistry::getInstance();
63 foreach ( $extensions as $extension ) {
64 if ( !$this->checkDev && $registry->isLoaded( $extension ) ) {
66 $this->addToDependencies( $dependencies, [ $extension ], [] );
69 $this->loadThing( $dependencies, $extension, [ $extension ], [] );
72 foreach ( $skins as $skin ) {
73 if ( !$this->checkDev && $registry->isLoaded( $skin ) ) {
75 $this->addToDependencies( $dependencies, [], [ $skin ] );
78 $this->loadThing( $dependencies, $skin, [], [ $skin ] );
82 $this->
output( json_encode( $dependencies ) .
"\n" );
84 $this->
output( $this->formatForHumans( $dependencies ) .
"\n" );
88 private function loadThing( &$dependencies, $name, $extensions, $skins ) {
89 $extDir = $this->
getConfig()->get( MainConfigNames::ExtensionDirectory );
90 $styleDir = $this->
getConfig()->get( MainConfigNames::StyleDirectory );
93 foreach ( $extensions as $extension ) {
94 $path =
"$extDir/$extension/extension.json";
95 if ( file_exists(
$path ) ) {
98 $this->addToDependencies( $dependencies, [ $extension ], [], $name );
101 $this->addToDependencies( $dependencies, [ $extension ], [], $name,
'missing' );
105 foreach ( $skins as $skin ) {
106 $path =
"$styleDir/$skin/skin.json";
107 if ( file_exists(
$path ) ) {
109 $this->addToDependencies( $dependencies, [], [ $skin ], $name );
112 $this->addToDependencies( $dependencies, [], [ $skin ], $name,
'missing' );
122 $registry->setCheckDevRequires( $this->checkDev );
124 $registry->readFromQueue( $queue );
127 if ( $e->incompatibleCore ) {
128 $reason =
'incompatible-core';
129 } elseif ( $e->incompatibleSkins ) {
130 $reason =
'incompatible-skins';
131 } elseif ( $e->incompatibleExtensions ) {
132 $reason =
'incompatible-extensions';
133 } elseif ( $e->missingExtensions || $e->missingSkins ) {
139 array_merge( $extensions, $e->missingExtensions ),
140 array_merge( $skins, $e->missingSkins )
150 $this->addToDependencies( $dependencies, $extensions, $skins, $name, $reason, $e->getMessage() );
153 $this->addToDependencies( $dependencies, $extensions, $skins, $name );
156 private function addToDependencies( &$dependencies, $extensions, $skins,
157 $why =
null, $status =
null, $message =
null
159 $mainRegistry = ExtensionRegistry::getInstance();
160 $iter = [
'extensions' => $extensions,
'skins' => $skins ];
161 foreach ( $iter as $type => $things ) {
162 foreach ( $things as $thing ) {
163 $preStatus = $dependencies[$type][$thing][
'status'] ??
false;
164 if ( $preStatus !==
'loaded' ) {
169 $tStatus = $mainRegistry->isLoaded( $thing ) ?
'loaded' :
'present';
171 $dependencies[$type][$thing][
'status'] = $tStatus;
173 if ( $why !==
null ) {
174 $dependencies[$type][$thing][
'why'][] = $why;
176 $dependencies[$type][$thing][
'why'] = array_unique(
177 $dependencies[$type][$thing][
'why'] );
180 if ( $message !==
null ) {
181 $dependencies[$type][$thing][
'message'] = trim( $message );
188 private function formatForHumans( $dependencies ) {
190 foreach ( $dependencies as $type => $things ) {
191 $text .= ucfirst( $type ) .
"\n" . str_repeat(
'=', strlen( $type ) ) .
"\n";
192 foreach ( $things as $thing => $info ) {
193 $why = $info[
'why'] ?? [];
195 $whyText =
'(because: ' . implode(
',', $why ) .
') ';
199 $msg = isset( $info[
'message'] ) ?
", {$info['message']}" :
'';
201 $text .=
"$thing: {$info['status']}{$msg} $whyText\n";
206 return trim( $text );
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.