Installing and upgrading help

Ia there a command line version of the environment check?

 
Picture of Ken Task
Ia there a command line version of the environment check?
Particularly helpful Moodlers

Have entity that has an internal only moodle 3.4.highest and desire to upgrade to 3.5.highest.  The internal site cannot be seen from the outside world ... have to hop from one server to this internal only moodle site via ssh.   Can do most things that need to be done via command line scripts and moosh.  moosh, however, doesn't have a environment check.

Is there a way to run the environment check via command line?

Thanks, in advance, Ken



 
Average of ratings: -
Picture of Leon Stringer
Re: Ia there a command line version of the environment check?
Particularly helpful Moodlers

If you have SSH access back to your client (i.e. you're SSHing to one server then to another) and can thus scp a file back then this might work:

One Wget:

wget --save-cookies cookies.txt \
     --keep-session-cookies \
     --delete-after \
     https://site1.example.com/admin/environment.php

Then another Wget:

wget --load-cookies cookies.txt \
     --post-data 'username=admin&password=[ADMINPASSWORD]' \
     --output-document=environment.html \
     https://site1.example.com/login/index.php

This is based on a StackOverflow post and works in two steps because the first request for /admin/environment.php needs you to be a site admin and you're not logged in so it sets the session variable wantsurl to the requested page and redirects you to the login page. The second step sends credentials to the login page but includes the session cookie from the first response so the login page sees the wantsurl value and redirects you there. Wget responds to this redirect saving the resulting page to environment.html.

This depends on the server you run this on being able to resolve the site domain name and access itself on port 443 or 80.

Possibly a bit messier than you were hoping but it seems to work.

 
Average of ratings: Useful (2)
Picture of Ken Task
Re: Ia there a command line version of the environment check?
Particularly helpful Moodlers

Thanks, Leon!  A +20 ... and you are right ... 'a bit messier' is really an understatement. :\

Environment Check
pardon the rant but ...

BEGIN RANT

Is one of the few if not the only 'component' that gets updated manually.
It is crucial to those with little admin experience to know if their server
meets specs when it comes to versions of things like PHP/MySQL, php extensions, etc..   How many times in forums have we seen posters who didn't check environment and are somewhere in la-la-land in attempts
to upgrade.   That is never a fun time to fix ... especially via forum exchange of information.  Wonder if those persons feel a little 'trapped' and a little resentful they might have to hire someone to fix it?

The files, environment.php and environment.xml do get updated on git updates/upgrades on point releases and on upgrades for sure.   But once that's done, newbie admins don't think to check it when they notice in noitications page they are multiple versions behind.  Besides that, there is the 'nag' that 'encourages' admins to keep their site up to date.
"It is strongly recommended that you update your site to the latest version to obtain all recent security and bug fixes."

For years, I have been manually editing language files to include a link to the environment checks from the Notifications page.  Most of the time, that edit stays ... sometimes it's gets wiped out and I have to put it in again.

And to add more ... environment check should have a CLI version of updating environment
check (a tool?) and/or just running it.

Ok ... end rant.

Think I'll attempt 'cli'zing' a copy of environment.php in admin/cli/ with the appropriate 'requires' to see if I can't get a difficult to read table via CLI that I could 'live' with. :\

Thanks, again Leon ... when I have a few hours will attempt to wrap feeble brain around that and try it out. smile

Hmmmm ... that's why I make the 'big bucks' ... right? (I'd rather not!) :\

'spirit of sharing', Ken


 
Average of ratings: -
Picture of Howard Miller
Re: Ia there a command line version of the environment check?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

It sounds like such an obvious thing to have (we don't) that I'll go and have a look to see how hard it would be. 

It's done in the install CLI script... so, it should be pretty easy to incorporate into a script. These are the lines from install.php (CLI version)

$release is from the version.php file (e.g. $release  = '3.5.3+ (Build: 20181123)')


// Test environment first.
require_once($CFG->libdir . '/environmentlib.php');
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
    $errors = environment_get_errors($environment_results);
    cli_heading(get_string('environment', 'admin'));
    foreach ($errors as $error) {
        list($info, $report) = $error;
        echo "!! $info !!\n$report\n\n";
    }
    exit(1);
}
 
Average of ratings: Useful (2)
Picture of Ken Task
Re: Ia there a command line version of the environment check?
Particularly helpful Moodlers

Many thanks, Howard!

Will give it a go.

My 'experiments' have been failures so far ... at least I know what doesn't work and am also learning why. :|

Hopefully, your contribution here will encourage the creation/addition of such a check via cli in official releases of the future.

'spirit of sharing', Ken


 
Average of ratings: -
Picture of Howard Miller
Re: Ia there a command line version of the environment check?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Ultra rough... but here you go!

<?php
define('CLI_SCRIPT', true);
define('CACHE_DISABLE_ALL', true);
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php');       // various admin-only functions
require_once($CFG->libdir.'/upgradelib.php');     // general upgrade/install related functions
require_once($CFG->libdir.'/clilib.php');         // cli only functions
require_once($CFG->libdir.'/environmentlib.php');
$release = "3.6";
// Test environment first.
require_once($CFG->libdir . '/environmentlib.php');
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
//echo "<pre>"; var_dump($environment_results); die;
foreach ($environment_results as $env) {
    echo "$env->part $env->info ($env->level)";
    if ($env->current_version) {
        echo "    Current $env->current_version,  Needed $env->needed_version";
    }
    if ($env->status) {
        echo " PASS ";
    } else {
        echo " FAIL ";
    }
    echo "\n";
}
if (!$envstatus) {
    echo "\nErrors found...\n\n";
    $errors = environment_get_errors($environment_results);
    cli_heading(get_string('environment', 'admin'));
    foreach ($errors as $error) {
        list($info, $report) = $error;
        echo "!! $info !!\n$report\n\n";
    }
    exit(1);
}
 
Average of ratings: Useful (3)
Picture of Howard Miller
Re: Ia there a command line version of the environment check?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

I'll tidy it up tomorrow and submit something to the plugins database

 
Average of ratings: Useful (1)
Picture of Ken Task
Re: Ia there a command line version of the environment check?
Particularly helpful Moodlers

Many thanks, Howard!  Rough or not ... it works! smile  Thank you!  Thank you!  Thank you!

Using on a 3.5.3+ (Build: 20181204)

'spirit of sharing', Ken


 
Average of ratings: Useful (1)
Picture of Howard Miller
Re: Ia there a command line version of the environment check?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

As promised, I've tidied this up a bit and packaged it as an admin tool plugin


https://moodle.org/plugins/tool_environment

https://github.com/thepurpleblob/moodle-tool_environment

I've submitted it to the plugins database but it hasn't been approved yet.

 
Average of ratings: Useful (3)
Picture of AL Rachels
Re: Ia there a command line version of the environment check?
Core developersParticularly helpful MoodlersPlugin developersTesters

The original was very usable, but this looks very nice and easier to read. Thanks Howard!

 
Average of ratings: Useful (1)