-
Bug
-
Resolution: Cannot Reproduce
-
Minor
-
None
-
3.9.2
When creating a new wiki page using the web-service method mod_wiki_new_page with the following parameters:
{
|
"moodlewsrestformat": "json",
|
"wstoken": "mytoken",
|
"wikiid": 2,
|
"title": "Testpage",
|
"content": "Hello World!",
|
"wsfunction": "mod_wiki_new_page"
|
}
|
The corresponding API-Call: https://mymoodle/webservice/rest/server.php?moodlewsrestformat=json&wstoken=mytoken&wikiid=2&title=Testpage&content=Hello+World%21&wsfunction=mod_wiki_new_page
I get the error message dml_write_exception. The full exception with debug enabled looks like this:
{
|
"exception": "dml_write_exception",
|
"errorcode": "dmlwriteexception",
|
"message": "Fehler beim Schreiben der Datenbank",
|
"debuginfo": "Column 'groupid' cannot be null\nINSERT INTO mdl_wiki_subwikis (wikiid,groupid,userid) VALUES(?,?,?)\n[array (\n 0 => '2',\n 1 => NULL,\n 2 => 0,\n)]"
|
}
|
This bug therefore appears to be with the default value for groupid. According to the code and the generated documentation, null is the default value used for creating new wiki pages. However, this doesn't fit with the NOTNULL=true as defined in install.xml.
When taking a look at the database, previous wiki pages were created with the groupid 0. Therefore, I created the following fix:
diff --git a/mod/wiki/classes/external.php b/mod/wiki/classes/external.php
|
index 4a147559517..70ee6989ab1 100644
|
--- a/mod/wiki/classes/external.php
|
+++ b/mod/wiki/classes/external.php
|
@@ -938,7 +938,7 @@ class mod_wiki_external extends external_api {
|
'userid' => new external_value(PARAM_INT, 'Subwiki\'s user ID. Used if subwiki does not exists.', VALUE_DEFAULT,
|
null),
|
'groupid' => new external_value(PARAM_INT, 'Subwiki\'s group ID. Used if subwiki does not exists.', VALUE_DEFAULT,
|
- null)
|
+ 0)
|
)
|
);
|
}
|
@@ -957,7 +957,7 @@ class mod_wiki_external extends external_api {
|
* @since Moodle 3.1
|
*/
|
public static function new_page($title, $content, $contentformat = null, $subwikiid = null, $wikiid = null, $userid = null,
|
- $groupid = null) {
|
+ $groupid = 0) {
|
global $USER;
|
|
$params = self::validate_parameters(self::new_page_parameters(), |
This patch replaces the default value for the GrouID with 0 and fixed the issue on my installation.
My moodle installation is running on the following specs:
- MOODLE_39_STABLE (a45e6838efe43d6a4485e911a7e81a88edc0f53e)
- Debian Buster, 10.4
- 4.19.0-9-amd64
- MariaDB 10.3.22 database server