Fix for imagefield.install does not work with filefield.install update ID's

  1. <?php
  2. # imagefield.install
  3.  
  4. /**
  5.  * Convert image field type to filefield.
  6.  */
  7. function imagefield_update_6003() {
  8.   $ret = array();
  9.  
  10.   if (drupal_get_installed_schema_version('filefield', TRUE) < 6001) {
  11.     $ret['#abort'] = array('success' => FALSE, 'query' => t('FileField must be updated to Drupal 6 before ImageField can be updated.'));
  12.     return $ret;
  13.   }
  14.  
  15.   $ret[] = update_sql("UPDATE {" . content_field_tablename() . "} SET type = 'filefield', module = 'filefield', active = 1 WHERE module = 'imagefield' OR type = 'image'");
  16.   $ret[] = update_sql("UPDATE {" . content_instance_tablename() . "} SET widget_type = 'imagefield_widget', widget_module = 'imagefield', widget_active = 1 WHERE widget_type = 'image' OR widget_type = 'imagefield_widget'");
  17.   content_clear_type_cache();
  18.  
  19.   return $ret;
  20. }
  21.  
  22.  
  23. #filefield.install
  24. // Update procedures.
  25.  
  26. function filefield_update_1() {
  27.   $ret = array();
  28.  
  29.   include_once(drupal_get_path('module', 'content') .'/content.module');
  30.   include_once(drupal_get_path('module', 'content') .'/content_admin.inc');
  31.  
  32.   $fields = content_fields();
  33.  
  34.   foreach ($fields as $field) {
  35.     switch ($field['type']) {
  36.       case 'file':
  37.         $columns = array(
  38.           'list' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
  39.         );
  40.         content_alter_db_field(array(), array(), $field, $columns);
  41.         break;
  42.     }
  43.   }
  44.   db_query('DELETE FROM {cache}');
  45.   return $ret;
  46. }
  47.  
  48. function filefield_update_2() {
  49.   cache_clear_all('*', 'cache_menu', TRUE);
  50.   return array();
  51. }
  52.  
  53. ?>
  54.  
  55.  
  56. See above — imagefield.install is looking for a number > 6001, but filefield sets its update id to 1,2,3.

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.