Skip to content

Commit

Permalink
Fix to issue #1379: removal of support for direct 'win' connection to…
Browse files Browse the repository at this point in the history
… Maxima.
  • Loading branch information
sangwinc committed Feb 5, 2025
1 parent 754658f commit 6be6a44
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 184 deletions.
7 changes: 2 additions & 5 deletions adminui/healthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,9 @@
stack_string('clearthecache'));
}

// Option to auto-create the Maxima image and store the results.
if ($config->platform != 'win') {
echo $OUTPUT->single_button(
new moodle_url($PAGE->url, ['createmaximaimage' => 1, 'sesskey' => sesskey()]),
echo $OUTPUT->single_button(
new moodle_url($PAGE->url, ['createmaximaimage' => 1, 'sesskey' => sesskey()]),
stack_string('healthcheckcreateimage'));
}

echo '<hr />';
// LaTeX. This is an install requirement, rather than a CAS healtcheck.
Expand Down
6 changes: 4 additions & 2 deletions db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ function xmldb_qtype_stack_install() {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
// See http://stackoverflow.com/questions/1482260/how-to-get-the-os-on-which-php-is-running
// and http://stackoverflow.com/questions/738823/possible-values-for-php-os.
$platform = 'win';

// We don't support the direct 'win' setting, so try to use the server setting for goemaxima instead.
$platform = 'server';
}
set_config('platform', $platform, 'qtype_stack');

// If this is a PHP unit test site, automatically create maxima_opt_auto.
// Should probably consider doing this for real in the future.
if ($platform != 'win' && (PHPUNIT_TEST || defined('BEHAT_UTIL'))) {
if (PHPUNIT_TEST || defined('BEHAT_UTIL')) {
// Set to the same defaults as in settings.php - however, that has not been done
// yet in the Moodle install code flow, so we have to duplicate here.
set_config('maximaversion', 'default', 'qtype_stack');
Expand Down
3 changes: 2 additions & 1 deletion doc/en/Developer/Development_track.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ We use the [github issue tracker](https://github.com/maths/moodle-qtype_stack/is

Done.
1. Introduce `ta` as the default teacher's answer in the question variables, and use this in the input and default prt.
2. Support `allowrmpty` for dropdown, radio and checkbox inputs.
2. Support `allowempty` for dropdown, radio and checkbox inputs.
3. Remove support for the `win` platform (which hasn't been tested for many years). See [issue #1379](https://github.com/maths/moodle-qtype_stack/issues/1379).

Issues with [github milestone 4.9.0](https://github.com/maths/moodle-qtype_stack/issues?q=is%3Aissue+milestone%3A4.9.0) include

Expand Down
1 change: 0 additions & 1 deletion lang/de/qtype_stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@
$string['settingplatformtypelinux'] = 'Linux';
$string['settingplatformtypelinuxoptimised'] = 'Linux (optimiert)';
$string['settingplatformtypeserver'] = 'Server';
$string['settingplatformtypewin'] = 'Windows';
$string['settingreplacedollars'] = '<code>$</code> und <code>$$</code> ersetzen';
$string['settingreplacedollars_desc'] = 'Ersetze <code>$...$</code> und <code>$$...$$</code> Trennzeichen in Fragetexten, zusätzlich zu <code>\\\\[...\\\\]</code> und <code>\\\\(...\\\\)</code>. Eine bessere Option ist die Verwendung des Skripts \'Maths-Trennzeichen korrigieren\', auf das im Folgenden Bezug genommen wird.';
$string['settingserveruserpass'] = 'Server username:password';
Expand Down
1 change: 0 additions & 1 deletion lang/en/qtype_stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@
$string['settingplatformtype_desc'] = 'STACK needs to know what sort of operating system it is running on. The "Server" option gives better performance at the cost of having to set up an additional server. The option "Linux (optimised)" is explained on the Optimising Maxima page in the documentation.';
$string['settingplatformtypelinux'] = 'Linux';
$string['settingplatformtypelinuxoptimised'] = 'Linux (optimised)';
$string['settingplatformtypewin'] = 'Windows';
$string['settingplatformtypeserver'] = 'Server';
$string['settingplatformtypeserverproxy'] = 'Server (via proxy)';
$string['settingplatformmaximacommand'] = 'Maxima command';
Expand Down
2 changes: 0 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,9 @@

$settings->add(new admin_setting_configselect('qtype_stack/platform',
get_string('settingplatformtype', 'qtype_stack'),
// Note, install.php tries to auto-detect Windows installs, and set the default appropriately.
get_string('settingplatformtype_desc', 'qtype_stack'), null, [
'linux' => get_string('settingplatformtypelinux', 'qtype_stack'),
'linux-optimised' => get_string('settingplatformtypelinuxoptimised', 'qtype_stack'),
'win' => get_string('settingplatformtypewin', 'qtype_stack'),
'server' => get_string('settingplatformtypeserver', 'qtype_stack'),
'server-proxy' => get_string('settingplatformtypeserverproxy', 'qtype_stack'),
]));
Expand Down
33 changes: 2 additions & 31 deletions stack/cas/connector.healthcheck.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,9 @@ public function __construct($config) {
stack_cas_configuration::create_maximalocal();

// Make sure we are in a position to call maxima.
// Support for Windows was removed on 5th Feb 2025.
// See commit 59e255ccf13b1baf2c2c52b5bd2d8372bbde1317 for last commit containing 'win' code.
switch ($config->platform) {
case 'win':
$maximalocation = stack_cas_configuration::confirm_maxima_win_location();
if ('' != $maximalocation) {
$test = [];
$test['tag'] = 'stackmaximalibraries';
$test['result'] = null;
$test['summary'] = null;
$test['details'] = html_writer::tag('p', stack_string('healthcheckconfigintro1').' '.
html_writer::tag('tt', $maximalocation));
$this->tests[] = $test;
} else {
$this->ishealthy = false;
$test = [];
$test['result'] = false;
$test['summary'] = "Could not confirm the location of Maxima";
$this->tests[] = $test;
}

stack_cas_configuration::copy_maxima_bat();

if (!is_readable($CFG->dataroot . '/stack/maxima.bat')) {
$this->ishealthy = false;
$test = [];
$test['tag'] = 'healthcheckmaximabat';
$test['result'] = false;
$test['summary'] = stack_string('healthcheckmaximabatinfo', $CFG->dataroot);
$test['details'] = html_writer::tag('p', stack_string('healthcheckmaximabatinfo', $CFG->dataroot));
$this->tests[] = $test;
}

break;
case 'linux':
// On a raw linux server list the versions of Maxima available.
$connection = stack_connection_helper::make();
Expand Down
4 changes: 0 additions & 4 deletions stack/cas/connectorhelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ public static function make() {
$debuglog = stack_utils::make_debug_log(self::$config->casdebugging);

switch (self::$config->platform) {
case 'win':
require_once(__DIR__ . '/connector.windows.class.php');
$connection = new stack_cas_connection_windows(self::$config, $debuglog);
break;
case 'linux':
case 'linux-optimised':
require_once(__DIR__ . '/connector.linux.class.php');
Expand Down
144 changes: 7 additions & 137 deletions stack/cas/installhelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,135 +97,16 @@ public function __construct() {
// Note, the quotes need to be protected below.
$this->blocksettings['PLOT_TERM_OPT'] = 'dynamic font \",11\" linewidth 1.2';

if ($this->settings->platform === 'win') {
$this->blocksettings['DEL_CMD'] = 'del';
$this->blocksettings['GNUPLOT_CMD'] = $this->get_plotcommand_win();
$this->blocksettings['DEL_CMD'] = 'rm';
if ((trim($this->settings->plotcommand)) != '') {
$this->blocksettings['GNUPLOT_CMD'] = $this->settings->plotcommand;
} else if (is_readable('/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot')) {
$this->blocksettings['GNUPLOT_CMD'] = '/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot';
} else {
$this->blocksettings['DEL_CMD'] = 'rm';
if ((trim($this->settings->plotcommand)) != '') {
$this->blocksettings['GNUPLOT_CMD'] = $this->settings->plotcommand;
} else if (is_readable('/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot')) {
$this->blocksettings['GNUPLOT_CMD'] = '/Applications/Gnuplot.app/Contents/Resources/bin/gnuplot';
} else {
$this->blocksettings['GNUPLOT_CMD'] = 'gnuplot';
}
}
// Loop over this array to format them correctly...
if ($this->settings->platform === 'win') {
foreach ($this->blocksettings as $var => $val) {
if ($var != 'PLOT_TERM_OPT') {
$this->blocksettings[$var] = addslashes(str_replace( '/', '\\', $val));
}
}
$this->blocksettings['GNUPLOT_CMD'] = 'gnuplot';
}

$this->blocksettings['MAXIMA_VERSION_EXPECTED'] = $this->settings->maximaversion;
$this->blocksettings['URL_BASE'] = '!ploturl!';
if ($this->settings->platform === 'win') {
$this->blocksettings['URL_BASE'] = '!ploturl!/';
}
}

/**
* Try to guess the gnuplot command on Windows.
* @return string the command.
*/
public function get_plotcommand_win() {
global $CFG;
if ($this->settings->plotcommand && $this->settings->plotcommand != 'gnuplot') {
return $this->settings->plotcommand;
}

// This does its best to find your version of Gnuplot...
$maximalocation = $this->maxima_win_location();

$plotcommands = [];
$plotcommands[] = $maximalocation. 'gnuplot/wgnuplot.exe';
$plotcommands[] = $maximalocation. 'bin/wgnuplot.exe';
$plotcommands[] = $maximalocation. 'gnuplot/bin/wgnuplot.exe';

// I'm really now totally and finally fed up with dealing with spaces in MS filenames.
$newplotlocation = stack_utils::convert_slash_paths($CFG->dataroot . '/stack/wgnuplot.exe');
foreach ($plotcommands as $plotcommand) {
if (file_exists($plotcommand)) {
if (substr_count($plotcommand, ' ') === 0) {
$newplotlocation = stack_utils::convert_slash_paths($CFG->dataroot . '/stack/wgnuplot.bat');
if (!file_put_contents($newplotlocation, $this->maxima_win_location() .
"gnuplot/bin/wgnuplot.exe %1 %2 %3 %3 %5 %6 %7 \n\n")) {
throw new stack_exception('Failed to write wgnuplot batch file to:'. $newplotlocation);
}
} else {
copy($plotcommand, $newplotlocation);
}
return $newplotlocation;
}
}
throw new stack_exception('Could not locate GNUPlot.');
}

// phpcs:ignore moodle.Commenting.MissingDocblock.Function
public function maxima_win_location() {
if ($this->settings->platform != 'win') {
return '';
}

$locations = [];
$locations[] = 'C:/maxima-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/maxima-' . $this->settings->maximaversion . 'a/';
$locations[] = 'C:/Maxima-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/bin/Maxima-gcl-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/bin/Maxima-sbcl-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files/Maxima-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files (x86)/Maxima-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files/Maxima-sbcl-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files (x86)/Maxima-sbcl-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files/Maxima-gcl-' . $this->settings->maximaversion . '/';
$locations[] = 'C:/Program Files (x86)/Maxima-gcl-' . $this->settings->maximaversion . '/';
if ('5.25.1' == $this->settings->maximaversion) {
$locations[] = 'C:/Program Files/Maxima-5.25.1-gcl/';
$locations[] = 'C:/Program Files (x86)/Maxima-5.25.1-gcl/';
}
if ('5.28.0' == $this->settings->maximaversion) {
$locations[] = 'C:/Program Files/Maxima-5.28.0-2/';
$locations[] = 'C:/Program Files (x86)/Maxima-5.28.0-2/';
}
if ('5.31.1' == $this->settings->maximaversion) {
$locations[] = 'C:/Program Files/Maxima-5.31.1-1/';
$locations[] = 'C:/Program Files (x86)/Maxima-5.31.1-1/';
}
$locations[] = 'C:/Program Files/Maxima/';
$locations[] = 'C:/Program Files (x86)/Maxima/';

foreach ($locations as $location) {
if (file_exists($location.'bin/maxima.bat')) {
return $location;
}
}

throw new stack_exception('Could not locate the directory into which Maxima is installed. Tried the following:' .
implode(', ', $locations));
}

// phpcs:ignore moodle.Commenting.MissingDocblock.Function
public function copy_maxima_bat() {
global $CFG;

$batchfilename = $this->maxima_win_location() . 'bin/maxima.bat';
if (substr_count($batchfilename, ' ') === 0) {
$batchfilecontents = "rem Auto-generated Maxima batch file. \n\n";
$batchfilecontents .= $batchfilename."\n\n";
if (!file_put_contents($CFG->dataroot . '/stack/maxima.bat', $batchfilecontents)) {
throw new stack_exception('Failed to write Maxima batch file.');
}
return true;
}

// If there are spaces within the pathname to the windows batch file we need to copy the batch file.
if (!copy($batchfilename, $CFG->dataroot . '/stack/maxima.bat')) {
throw new stack_exception('Could not copy the Maxima batch file ' . $batchfilename .
' to location ' . $CFG->dataroot . '/stack/maxima.bat');
}
return true;
}

// phpcs:ignore moodle.Commenting.MissingDocblock.Function
Expand Down Expand Up @@ -352,14 +233,6 @@ public static function generate_maximalocal_contents() {
return self::get_instance()->get_maximalocal_contents();
}

/**
* Generate the directoryname
* @return string the contents that the maximalocal.mac file should have.
*/
public static function confirm_maxima_win_location() {
return self::get_instance()->maxima_win_location();
}

/**
* This function checks the current setting match to the supported packages.
*/
Expand Down Expand Up @@ -403,10 +276,7 @@ public static function validate_maximalibraries() {
public static function create_auto_maxima_image() {
$config = get_config('qtype_stack');
// Do not try to generate the optimised image on MS platforms.
if ($config->platform == 'win') {
$errmsg = "Microsoft Windows version cannot be automatically optimised";
return [false, $errmsg];
} else if ($config->platform != 'linux' && $config->platform != 'linux-optimised') {
if ($config->platform != 'linux' && $config->platform != 'linux-optimised') {
$errmsg = "$config->platform version cannot be automatically optimised";
return [false, $errmsg];
}
Expand Down

0 comments on commit 6be6a44

Please sign in to comment.