~ubuntu-branches/ubuntu/hoary/moodle/hoary

« back to all changes in this revision

Viewing changes to mod/glossary/db/mysql.php

  • Committer: Bazaar Package Importer
  • Author(s): Isaac Clerencia
  • Date: 2004-12-29 00:49:52 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041229004952-gliyqzpj2w3e7clx
Tags: 1.4.3-1
* Urgency high as upstream release fixes several security bugs
* New upstream release
* Write database creation errors and warn the user about it, 
closes: #285842, #285842

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?PHP   // $Id: mysql.php,v 1.26 2004/05/14 19:36:39 stronk7 Exp $
 
1
<?PHP   // $Id: mysql.php,v 1.31.2.2 2004/11/18 19:11:58 moodler Exp $
2
2
 
3
3
 
4
4
 
259
259
  
260
260
  if ( $oldversion < 2004051400 ) {
261
261
        print_simple_box("This update might take several seconds.<p>The more glossaries, entries and aliases you have created, the more it will take so please be patient.","center", "50%", "$THEME->cellheading", "20", "noticebox");
262
 
        if ( $entries = get_records("glossary_entries")) {
 
262
        if ( $entries = get_records("glossary_entries", '', '', '', 'id,concept')) {
263
263
            foreach($entries as $entry) {
264
264
                set_field("glossary_entries","concept",addslashes(trim($entry->concept)),"id",$entry->id);
265
265
            }
270
270
            }
271
271
        }
272
272
  }
 
273
 
 
274
  if ( $oldversion < 2004072300) {
 
275
      table_column("glossary_alias", "alias", "alias", "VARCHAR", "255", "", "", "NOT NULL");
 
276
  }
 
277
 
 
278
  if ( $oldversion < 2004072400) {
 
279
 
 
280
      //Create new table glossary_formats to store format info
 
281
      execute_sql("CREATE TABLE `{$CFG->prefix}glossary_formats` (
 
282
                       `id` INT(10) unsigned NOT NULL auto_increment,
 
283
                       `name` VARCHAR(50) NOT NULL,
 
284
                       `popupformatname` VARCHAR(50) NOT NULL, 
 
285
                       `visible` TINYINT(2) UNSIGNED NOT NULL default '1',
 
286
                       `showgroup` TINYINT(2) UNSIGNED NOT NULL default '1',
 
287
                       `defaultmode` VARCHAR(50) NOT NULL default '',
 
288
                       `defaulthook` VARCHAR(50) NOT NULL default '',
 
289
                       `sortkey` VARCHAR(50) NOT NULL default '',
 
290
                       `sortorder` VARCHAR(50) NOT NULL default '',
 
291
                   PRIMARY KEY  (`id`)                    
 
292
                   ) TYPE=MyISAM COMMENT='Setting of the display formats'");
 
293
 
 
294
      //Define current 0-6 format names
 
295
      $formatnames = array('dictionary','continuous','fullwithauthor','encyclopedia',
 
296
                           'faq','fullwithoutauthor','entrylist');
 
297
 
 
298
      //Fill the new table from the old one (only 'valid', 0-6, formats)
 
299
      if ($formats = get_records('glossary_displayformats')) {
 
300
          foreach ($formats as $format) {
 
301
              //Format names
 
302
              if ($format->fid >= 0 && $format->fid <= 6) {
 
303
                  $format->name = $formatnames[$format->fid];
 
304
              }
 
305
 
 
306
              //Format popupformatname
 
307
              $format->popupformatname = 'dictionary';  //Default format
 
308
              if ($format->relatedview >= 0 && $format->relatedview <= 6) {
 
309
                  $format->popupformatname = $formatnames[$format->relatedview];
 
310
              }
 
311
 
 
312
              //Insert the new record
 
313
              //Only if $format->name is set (ie. formats 0-6)
 
314
              if ($format->name) {
 
315
                  insert_record('glossary_formats',$format);
 
316
              }
 
317
              
 
318
          }
 
319
      }
 
320
 
 
321
      //Drop the old formats table
 
322
      execute_sql("DROP TABLE `{$CFG->prefix}glossary_displayformats`");
 
323
 
 
324
      //Modify the glossary->displayformat field
 
325
      table_column('glossary', 'displayformat', 'displayformat', 'VARCHAR', '50', '', 'dictionary', 'NOT NULL');
 
326
 
 
327
      //Update glossary->displayformat field
 
328
      if ($glossaries = get_records('glossary')) {
 
329
          foreach($glossaries as $glossary) {
 
330
              $displayformat = 'dictionary';  //Default format
 
331
              if ($glossary->displayformat >= 0 && $glossary->displayformat <= 6) {
 
332
                  $displayformat = $formatnames[$glossary->displayformat];
 
333
              }
 
334
              set_field('glossary','displayformat',$displayformat,'id',$glossary->id);
 
335
          }
 
336
      }
 
337
  }
 
338
 
 
339
  if ( $oldversion < 2004080800) {
 
340
      table_column("glossary","","editalways","tinyint","2", "unsigned", "0", "", "entbypage");
 
341
  }
 
342
 
 
343
  //Activate editalways in old secondary glossaries (old behaviour)
 
344
  if ( $oldversion < 2004080900) {
 
345
      set_field('glossary','editalways','1','mainglossary','0');
 
346
  }
 
347
 
 
348
  if ($oldversion < 2004080932) {
 
349
      modify_database('','ALTER TABLE prefix_glossary ADD INDEX course (course);');
 
350
      modify_database('','ALTER TABLE prefix_glossary_alias ADD INDEX entryid (entryid);');
 
351
      modify_database('','ALTER TABLE prefix_glossary_categories ADD INDEX glossaryid (glossaryid);');
 
352
      modify_database('','ALTER TABLE prefix_glossary_comments ADD INDEX entryid (entryid);');
 
353
      modify_database('','ALTER TABLE prefix_glossary_comments ADD INDEX userid (userid);');
 
354
      modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX glossaryid (glossaryid);');
 
355
      modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX userid (userid);');
 
356
      modify_database('','ALTER TABLE prefix_glossary_entries ADD INDEX concept (concept);');
 
357
      modify_database('','ALTER TABLE prefix_glossary_entries_categories ADD INDEX entryid (entryid);');
 
358
      modify_database('','ALTER TABLE prefix_glossary_entries_categories ADD INDEX categoryid (categoryid);');
 
359
      modify_database('','ALTER TABLE prefix_glossary_ratings ADD INDEX userid (userid);');
 
360
      modify_database('','ALTER TABLE prefix_glossary_ratings ADD INDEX entryid (entryid);');
 
361
 
 
362
  }
273
363
    
274
364
  return true;
275
365
}