2020-09-02 14:48:08 +08:00
< ? php namespace System\Console ;
use App ;
use System\Classes\UpdateManager ;
2021-04-02 10:27:48 +08:00
/**
* Detects the version of Winter CMS installed .
*
* This checks against a central manifest on Winter CMS ' s GitHub account to determine the version . If any files have
* been modified , this will be indicated when detecting the version .
*
* To get a list of modified files , simply add the " --changes " parameter .
*
* @ package winter\wn - system - module
* @ author Ben Thomson
* @ author Winter CMS
*/
2021-03-10 15:02:53 -06:00
class WinterVersion extends \Illuminate\Console\Command
2020-09-02 14:48:08 +08:00
{
/**
* @ var string The console command description .
*/
2021-03-10 15:02:53 -06:00
protected $description = 'Detects the build number (version) of this Winter CMS instance.' ;
2020-09-02 14:48:08 +08:00
/**
* @ var string The name and signature of the console command .
*/
2021-03-10 15:02:53 -06:00
protected $signature = ' winter : version
2020-09-03 11:48:35 +08:00
{ -- changes : Include the list of changes between this install and the expected files for the detected build . } ' ;
2020-09-02 14:48:08 +08:00
/**
* Execute the console command .
*
* @ return mixed
*/
public function handle ()
{
2021-03-10 15:02:53 -06:00
$this -> comment ( '*** Detecting Winter CMS build...' );
2020-09-02 14:48:08 +08:00
if ( ! App :: hasDatabase ()) {
2020-09-03 11:48:35 +08:00
$build = UpdateManager :: instance () -> getBuildNumberManually ( $this -> option ( 'changes' ));
2020-09-02 14:48:08 +08:00
// Skip setting the build number if no database is detected to set it within
$this -> comment ( '*** No database detected - skipping setting the build number.' );
} else {
2020-09-03 11:48:35 +08:00
$build = UpdateManager :: instance () -> setBuildNumberManually ( $this -> option ( 'changes' ));
2020-09-02 14:48:08 +08:00
}
2020-09-03 11:48:35 +08:00
if ( ! $build [ 'confident' ]) {
2021-03-10 15:02:53 -06:00
$this -> warn ( '*** We could not accurately determine your Winter CMS build due to the number of modifications. The closest detected build is Winter CMS build ' . $build [ 'build' ] . '.' );
2020-09-03 11:48:35 +08:00
} else if ( $build [ 'modified' ]) {
2021-03-10 15:02:53 -06:00
$this -> info ( '*** Detected a modified version of Winter CMS build ' . $build [ 'build' ] . '.' );
2020-09-02 14:48:08 +08:00
} else {
2021-03-10 15:02:53 -06:00
$this -> info ( '*** Detected Winter CMS build ' . $build [ 'build' ] . '.' );
2020-09-02 14:48:08 +08:00
}
2020-09-03 11:48:35 +08:00
if ( $this -> option ( 'changes' )) {
$this -> line ( '' );
$this -> comment ( 'We have detected the following modifications:' );
if ( count ( $build [ 'changes' ][ 'added' ] ? ? [])) {
$this -> line ( '' );
$this -> info ( 'Files added:' );
foreach ( array_keys ( $build [ 'changes' ][ 'added' ]) as $file ) {
$this -> line ( ' - ' . $file );
}
}
if ( count ( $build [ 'changes' ][ 'modified' ] ? ? [])) {
$this -> line ( '' );
$this -> info ( 'Files modified:' );
foreach ( array_keys ( $build [ 'changes' ][ 'modified' ]) as $file ) {
$this -> line ( ' - ' . $file );
}
}
if ( count ( $build [ 'changes' ][ 'removed' ] ? ? [])) {
$this -> line ( '' );
$this -> info ( 'Files removed:' );
foreach ( array_keys ( $build [ 'changes' ][ 'removed' ]) as $file ) {
$this -> line ( ' - ' . $file );
}
}
}
2020-09-02 14:48:08 +08:00
}
}