Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merged MDL-13717 Applied hack from Nicklas to fix sitemp etc. It work…

…ed for me in a quick test.
  • Loading branch information...
commit 09e3e4efb642e7b7876a87b9a1a9fdf9d0c4727b 1 parent e7d53ba
authored March 02, 2008

Showing 1 changed file with 28 additions and 26 deletions. Show diff stats Hide diff stats

  1. 54  mod/wiki/ewikimoodlelib.php
54  mod/wiki/ewikimoodlelib.php
@@ -176,50 +176,52 @@ function ewiki_database_moodle($action, &$args, $sw1, $sw2) {
176 176
          }
177 177
       break;
178 178
 
179  
-      /*  Returns an array of __all__ pages, where each entry is made up
180  
-          of the fields from the database requested with the $args array,
181  
-          e.g. array("flags","meta","lastmodified");
  179
+      /*  Returns an array of the lastest versions of __all__ pages,
  180
+          where each entry is made up of the fields from the database
  181
+          requested with the $args array, e.g.
  182
+          array("flags","meta","lastmodified");
182 183
       */
183 184
       case "GETALL":
184 185
          switch ($CFG->dbfamily) {
185 186
              case 'postgres':
186  
-                 $sql= "SELECT pagename AS id, ".
  187
+                 // All but the latest version eliminated by DISTINCT
  188
+                 // ON (pagename)
  189
+                 $sql= "SELECT DISTINCT ON (pagename) pagename AS id, ".
187 190
                       implode(", ", $args) .
188 191
                       " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
189 192
                       " WHERE wiki = ".$wiki_entry->id.
190  
-                      " GROUP BY pagename, ".implode(", ", $args);
  193
+                      " ORDER BY pagename, version DESC";
191 194
                  break;
  195
+             case 'mysql':
  196
+                 // All but the latest version eliminated by
  197
+                 // mysql-specific GROUP BY-semantics
  198
+                 $sql= "SELECT pagename AS id, ".
  199
+                 implode(", ", $args) .
  200
+                      " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
  201
+                      " WHERE wiki = ".$wiki_entry->id.
  202
+                      " GROUP BY id, version DESC " ;
192 203
              default:
  204
+                 // All but the latest version are here eliminated in
  205
+                 // get_records_sql, since it will return an array
  206
+                 // with only one result per id-field value. Note,
  207
+                 // that for this to work the query needs to order the
  208
+                 // records ascending by version, so later versions
  209
+                 // will overwrite previous ones in
  210
+                 // recordset_to_array. This is not pretty.
193 211
                  $sql= "SELECT pagename AS id, ".
194 212
                  implode(", ", $args) .
195 213
                       " FROM ". $CFG->prefix.EWIKI_DB_TABLE_NAME .
196 214
                       " WHERE wiki = ".$wiki_entry->id.
197  
-                      " GROUP BY id, version " ;
  215
+                      " ORDER BY version";
198 216
          }
199 217
 
200  
-         #print "$sql";
201 218
          $result=get_records_sql($sql);
202 219
          $r = new ewiki_dbquery_result($args);
203 220
 
204  
-         $drop = "";
205  
-         #while ($result && ($row = mysql_fetch_array($result, MYSQL_ASSOC))) {
206  
-         #   $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
207  
-         #   if ($i != $drop) {
208  
-         #      $drop = $i;
209  
-         #      $r->add($row);
210  
-         #   }
211  
-         #}
212  
-         #print "<pre>"; print_r($result); print "</pre>";
213  
-         if(!$result) {
214  
-           $result=array();
215  
-         }
216  
-         while(list($key, $val) = each($result)) {
217  
-            $row=get_object_vars($val);
218  
-            $i = EWIKI_CASE_INSENSITIVE ? strtolower($row["id"]) : $row["id"];
219  
-            if ($i != $drop) {
220  
-               $drop = $i;
221  
-               $r->add($row);
222  
-            }
  221
+         if ($result) {
  222
+             foreach($result as $val) {
  223
+                 $r->add(get_object_vars($val));
  224
+             }
223 225
          }
224 226
 
225 227
          break;

0 notes on commit 09e3e4e

Please sign in to comment.
Something went wrong with that request. Please try again.