It seems the library being used for commanline processing has problems dealing with booleans.
When trying to create a course that is not visible, -v 0 and -v '0' both generate the same exception:
PHP Fatal error: Uncaught exception 'GetOptionKit\Exception\RequireValueException' with message 'Option 'v' requires a value.' in /usr/local/moosh/vendor/c9s/GetOptionKit/src/GetOptionKit/ContinuousOptionParser.php:174
Stack trace:
#0 /usr/local/moosh/vendor/c9s/GetOptionKit/src/GetOptionKit/ContinuousOptionParser.php(124): GetOptionKit\ContinuousOptionParser->parse(Array)
#1 /usr/local/moosh/moosh.php(122): GetOptionKit\ContinuousOptionParser->continueParse()
#2 {main}
thrown in /usr/local/moosh/vendor/c9s/GetOptionKit/src/GetOptionKit/ContinuousOptionParser.php on line 174
I also tried -v 'false' and -v N but they also don't work, giving Dabatbase errors instead:
Default exception handler: Error writing to database Debug: Incorrect integer value: 'N' for column 'visible' at row 1
INSERT INTO mdl_course (fullname,shortname,format,idnumber,visible,category,timecreated,timemodified,sortorder,visibleold) VALUES(?,?,?,?,?,?,?,?,?,?)
[array (
0 => 'TEST - All Students [2014-2015]',
1 => 'TEST',
2 => 'weeks',
3 => 'test_2015_allstudents',
4 => 'N',
5 => '361',
6 => 1403023635,
7 => 1403023635,
8 => 0,
9 => 'N',
)]
Error code: dmlwriteexception
- line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown
- line 1080 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
- line 1122 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
- line 2524 of /course/lib.php: call to mysqli_native_moodle_database->insert_record()
- line 48 of /usr/local/moosh/Moosh/Command/Moodle23/Course/CourseCreate.php: call to create_course()
- line 213 of /usr/local/moosh/moosh.php: call to Moosh\Command\Moodle23\Course\CourseCreate->execute()
!!! Error writing to database !!!
I had a look at the docs for php-GetOptionKit, and tried with v|visible:=i in the hope that that would make it see sense, but alas not, it still doesn't think 0 is an integer!
I have two suggestions for possible fixes, and would be happy to submit either as a patch:
- replace the single -v flag that needs a value with two flags that do not, -v for a visible course, and -V for an invisible course
- alter the code so the -v flag expects 'yes' or 'no' rather than 1 or 0, and translates to 1 or before executing the moodle function to actually add the course
Obviously the real problem is that GetOptionKit is being dumb, but since that's not part of this codebase, I suggest we need to hack around it, so that probably means one of the above two approaches.