37 parent::__construct();
39 $this->
addOption(
'extensions',
'Comma separated list of extensions to check',
false,
true );
40 $this->
addOption(
'skins',
'Comma separated list of skins to check',
false,
true );
41 $this->
addOption(
'json',
'Output in JSON' );
42 $this->
addOption(
'dev',
'Check development dependencies too' );
46 $this->checkDev = $this->
hasOption(
'dev' );
47 $extensions = $this->
hasOption(
'extensions' )
48 ? explode(
',', $this->
getOption(
'extensions' ) )
51 ? explode(
',', $this->
getOption(
'skins' ) )
57 $registry = ExtensionRegistry::getInstance();
58 foreach ( $extensions as $extension ) {
59 if ( !$this->checkDev && $registry->isLoaded( $extension ) ) {
61 $this->addToDependencies( $dependencies, [ $extension ], [] );
64 $this->loadThing( $dependencies, $extension, [ $extension ], [] );
67 foreach ( $skins as $skin ) {
68 if ( !$this->checkDev && $registry->isLoaded( $skin ) ) {
70 $this->addToDependencies( $dependencies, [], [ $skin ] );
73 $this->loadThing( $dependencies, $skin, [], [ $skin ] );
77 $this->
output( json_encode( $dependencies ) .
"\n" );
79 $this->
output( $this->formatForHumans( $dependencies ) .
"\n" );
83 private function loadThing( &$dependencies, $name, $extensions, $skins ) {
84 $extDir = $this->
getConfig()->get( MainConfigNames::ExtensionDirectory );
85 $styleDir = $this->
getConfig()->get( MainConfigNames::StyleDirectory );
88 foreach ( $extensions as $extension ) {
89 $path =
"$extDir/$extension/extension.json";
90 if ( file_exists(
$path ) ) {
93 $this->addToDependencies( $dependencies, [ $extension ], [], $name );
96 $this->addToDependencies( $dependencies, [ $extension ], [], $name,
'missing' );
100 foreach ( $skins as $skin ) {
101 $path =
"$styleDir/$skin/skin.json";
102 if ( file_exists(
$path ) ) {
104 $this->addToDependencies( $dependencies, [], [ $skin ], $name );
107 $this->addToDependencies( $dependencies, [], [ $skin ], $name,
'missing' );
117 $registry->setCheckDevRequires( $this->checkDev );
119 $registry->readFromQueue(
$queue );
122 if ( $e->incompatibleCore ) {
123 $reason =
'incompatible-core';
124 } elseif ( $e->incompatibleSkins ) {
125 $reason =
'incompatible-skins';
126 } elseif ( $e->incompatibleExtensions ) {
127 $reason =
'incompatible-extensions';
128 } elseif ( $e->missingExtensions || $e->missingSkins ) {
131 return $this->loadThing(
134 array_merge( $extensions, $e->missingExtensions ),
135 array_merge( $skins, $e->missingSkins )
144 $this->addToDependencies( $dependencies, $extensions, $skins, $name, $reason, $e->getMessage() );
147 $this->addToDependencies( $dependencies, $extensions, $skins, $name );
150 private function addToDependencies( &$dependencies, $extensions, $skins,
151 $why =
null, $status =
null, $message =
null
154 $iter = [
'extensions' => $extensions,
'skins' => $skins ];
155 foreach ( $iter as
$type => $things ) {
156 foreach ( $things as $thing ) {
157 $preStatus = $dependencies[
$type][$thing][
'status'] ??
false;
158 if ( $preStatus !==
'loaded' ) {
163 $tStatus = $mainRegistry->isLoaded( $thing ) ?
'loaded' :
'present';
165 $dependencies[
$type][$thing][
'status'] = $tStatus;
167 if ( $why !==
null ) {
168 $dependencies[
$type][$thing][
'why'][] = $why;
170 $dependencies[
$type][$thing][
'why'] = array_unique(
171 $dependencies[
$type][$thing][
'why'] );
174 if ( $message !==
null ) {
175 $dependencies[
$type][$thing][
'message'] = trim( $message );
182 private function formatForHumans( $dependencies ) {
184 foreach ( $dependencies as
$type => $things ) {
185 $text .= ucfirst(
$type ) .
"\n" . str_repeat(
'=', strlen(
$type ) ) .
"\n";
186 foreach ( $things as $thing => $info ) {
187 $why = $info[
'why'] ?? [];
189 $whyText =
'(because: ' . implode(
',', $why ) .
') ';
193 $msg = isset( $info[
'message'] ) ?
", {$info['message']}" :
'';
195 $text .=
"$thing: {$info['status']}{$msg} $whyText\n";
200 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.