Merged MDL-13717 Applied hack from Nicklas to fix sitemp etc. It worked for me in a quick test.

This commit is contained in:
moodler 2008-03-02 01:22:51 +00:00
parent a487c55b03
commit f76fa797eb

View file

@ -176,50 +176,52 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
} }
break; break;
/* Returns an array of __all__ pages, where each entry is made up /* Returns an array of the lastest versions of __all__ pages,
of the fields from the database requested with the $args array, where each entry is made up of the fields from the database
e.g. array("flags","meta","lastmodified"); requested with the $args array, e.g.
array("flags","meta","lastmodified");
*/ */
case "GETALL": case "GETALL":
switch ($CFG->dbfamily) { switch ($CFG->dbfamily) {
case 'postgres': 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) . implode(", ", $args) .
" FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME . " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
" WHERE wiki = ".$wiki_entry->id. " WHERE wiki = ".$wiki_entry->id.
" GROUP BY pagename, ".implode(", ", $args); " ORDER BY pagename, version DESC";
break; break;
default: case 'mysql':
// All but the latest version eliminated by
// mysql-specific GROUP BY-semantics
$sql= "SELECT pagename AS id, ". $sql= "SELECT pagename AS id, ".
implode(", ", $args) . implode(", ", $args) .
" FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME . " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
" WHERE wiki = ".$wiki_entry->id. " WHERE wiki = ".$wiki_entry->id.
" GROUP BY id, version " ; " 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.
" ORDER BY version";
} }
#print "$sql";
$result=get_records_sql($sql); $result=get_records_sql($sql);
$r = new ewiki_dbquery_result($args); $r = new ewiki_dbquery_result($args);
$drop = ""; if ($result) {
#while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) { foreach($result as $val) {
# $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"]; $r->add(get_object_vars($val));
# if ($i != $drop) { }
# $drop = $i;
# $r->add($row);
# }
#}
#print "<pre>"; print_r($result); print "</pre>";
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);
}
} }
break; break;