From: moodler Date: Sun, 2 Mar 2008 01:22:51 +0000 (+0000) Subject: Merged MDL-13717 Applied hack from Nicklas to fix sitemp etc. It worked for me in... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=f76fa797eb9a64d3bccc518dce879dd86134779b;p=moodle.git Merged MDL-13717 Applied hack from Nicklas to fix sitemp etc. It worked for me in a quick test. --- diff --git a/mod/wiki/ewikimoodlelib.php b/mod/wiki/ewikimoodlelib.php index 30edf91210..37758e0708 100644 --- a/mod/wiki/ewikimoodlelib.php +++ b/mod/wiki/ewikimoodlelib.php @@ -176,50 +176,52 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) { } break; - /* Returns an array of __all__ pages, where each entry is made up - of the fields from the database requested with the $args array, - e.g. array("flags","meta","lastmodified"); + /* Returns an array of the lastest versions of __all__ pages, + where each entry is made up of the fields from the database + requested with the $args array, e.g. + array("flags","meta","lastmodified"); */ case "GETALL": switch ($CFG->dbfamily) { case 'postgres': - $sql= "SELECT pagename AS id, ". + // All but the latest version eliminated by DISTINCT + // ON (pagename) + $sql= "SELECT DISTINCT ON (pagename) pagename AS id, ". implode(", ", $args) . " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME . " WHERE wiki = ".$wiki_entry->id. - " GROUP BY pagename, ".implode(", ", $args); + " ORDER BY pagename, version DESC"; break; + case 'mysql': + // All but the latest version eliminated by + // mysql-specific GROUP BY-semantics + $sql= "SELECT pagename AS id, ". + implode(", ", $args) . + " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME . + " WHERE wiki = ".$wiki_entry->id. + " GROUP BY id, version DESC " ; default: + // All but the latest version are here eliminated in + // get_records_sql, since it will return an array + // with only one result per id-field value. Note, + // that for this to work the query needs to order the + // records ascending by version, so later versions + // will overwrite previous ones in + // recordset_to_array. This is not pretty. $sql= "SELECT pagename AS id, ". implode(", ", $args) . " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME . " WHERE wiki = ".$wiki_entry->id. - " GROUP BY id, version " ; + " ORDER BY version"; } - #print "$sql"; $result=get_records_sql($sql); $r = new ewiki_dbquery_result($args); - $drop = ""; - #while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) { - # $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"]; - # if ($i != $drop) { - # $drop = $i; - # $r->add($row); - # } - #} - #print "
"; print_r($result); print "
"; - if(!$result) { - $result=array(); - } - while(list($key, $val) = each($result)) { - $row=get_object_vars($val); - $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"]; - if ($i != $drop) { - $drop = $i; - $r->add($row); - } + if ($result) { + foreach($result as $val) { + $r->add(get_object_vars($val)); + } } break;