[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/imagecache/ -> imagecache.install (source)

   1  <?php
   2  
   3   function imagecache_requirements($phase) {
   4    $requirements = array();
   5    // Ensure translations don't break at install time.
   6    $t = get_t();
   7  
   8    if ($phase == 'runtime') {
   9  
  10      $imagecache_directory = file_create_path() .'/imagecache';
  11      if (!file_check_directory($imagecache_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
  12        if (!is_dir($imagecache_directory)) {
  13          $requirements['imagecache_directory'] = array(
  14            'title' => $t('ImageCache Directory'),
  15            'value' => $t('%p is not a directory or is not readable by the webserver.', array('%p' => $imagecache_directory)),
  16            'severity' => REQUIREMENT_ERROR,
  17          );
  18        }
  19        elseif (!is_writable($imagecache_directory)) {
  20          $requirements['imagecache_directory'] = array(
  21            'title' => $t('ImageCache Directory'),
  22            'value' => $t('%p is not writeable by the webserver.', array('%p' => $imagecache_directory)),
  23            'severity' => REQUIREMENT_ERROR,
  24          );
  25        }
  26        else {
  27          $requirements['imagecache_directory'] = array(
  28            'title' => $t('ImageCache Directory'),
  29            'value' => $t('An unknown error occured.'),
  30            'description' => $t('An unknown error occured trying to verify %p is a directory and is writable.', array('%p' => $imagecache_directory)),
  31            'severity' => REQUIREMENT_ERROR,
  32          );
  33        }
  34      }
  35  
  36      if (!is_writable(file_directory_temp())) {
  37        $requirements['imagecache_directory'] = array(
  38          'title' => $t('ImageCache Temp Directory'),
  39          'value' => $t('%p is not writeable by the webserver.', array('%p' => file_directory_temp())),
  40          'severity' => REQUIREMENT_ERROR,
  41        );
  42      }
  43    }
  44    return $requirements;
  45  }
  46  
  47  function imagecache_schema() {
  48      $schema['imagecache_preset'] = array(
  49      'fields' => array(
  50        'presetid' => array(
  51          'description' => t('The primary identifier for an imagecache_preset.'),
  52          'type' => 'serial',
  53          'unsigned' => TRUE,
  54          'not null' => TRUE,
  55        ),
  56        'presetname' => array(
  57          'description' => t('The primary identifier for a node.'),
  58          'type' => 'varchar',
  59          'length' => 255,
  60          'not null' => TRUE,
  61        ),
  62      ),
  63      'primary key' => array('presetid'),
  64    );
  65  
  66    $schema['imagecache_action'] = array(
  67      'fields' => array(
  68        'actionid' => array(
  69          'description' => t('The primary identifier for an imagecache_action.'),
  70          'type' => 'serial',
  71          'unsigned' => TRUE,
  72          'not null' => TRUE,
  73        ),
  74        'presetid' => array(
  75          'description' => t('The primary identifier for an imagecache_preset.'),
  76          'type' => 'int',
  77          'unsigned' => TRUE,
  78          'not null' => TRUE,
  79          'default' => 0,
  80        ),
  81        'weight' => array(
  82          'description' => t('The weight of the action in the preset.'),
  83          'type' => 'int',
  84          'not null' => TRUE,
  85          'default' => 0,
  86        ),
  87        'module' => array(
  88          'description' => t('The module that defined the action.'),
  89          'type' => 'varchar',
  90          'length' => 255,
  91          'not null' => TRUE,
  92        ),
  93        'action' => array(
  94          'description' => t('The unique ID of the action to be executed.'),
  95          'type' => 'varchar',
  96          'length' => 255,
  97          'not null' => TRUE,
  98        ),
  99        'data' => array(
 100          'description' => t('The configuration data for the action.'),
 101          'type' => 'text',
 102          'not null' => TRUE,
 103          'size' => 'big',
 104          'serialize' => TRUE,
 105        ),
 106      ),
 107      'primary key' => array('actionid'),
 108      'indexes' => array(
 109        'presetid' => array('presetid'),
 110      ),
 111    );
 112  
 113    return $schema;
 114  }
 115  
 116  /**
 117   * Implementation of hook_install().
 118   */
 119  function imagecache_install() {
 120    drupal_install_schema('imagecache');
 121  }
 122  
 123  /**
 124   * Implementation of hook_uninstall().
 125   */
 126  function imagecache_uninstall() {
 127    // Remove any cached images.
 128    $path = file_directory_path() .'/imagecache/';
 129    if (is_dir($path)) {
 130      _imagecache_recursive_delete($path);
 131    }
 132  
 133    drupal_uninstall_schema('imagecache');
 134  }
 135  
 136  // Add action id to actions table.
 137  function imagecache_update_1() {
 138    $ret = array();
 139    $ret[] = update_sql('ALTER TABLE {imagecache_actions} ADD COLUMN actionid INT UNSIGNED NOT NULL  primary key auto_increment');
 140    return $ret;
 141  }
 142  
 143  // Rename rulesets to presets; Make all table names singular;
 144  function imagecache_update_2() {
 145    $ret = array();
 146    $ret[] = update_sql('ALTER TABLE {imagecache_rulesets} RENAME TO {imagecache_preset}');
 147    $ret[] = update_sql('ALTER TABLE {imagecache_actions} RENAME TO {imagecache_action}');
 148    switch ($GLOBALS['db_type']) {
 149      case 'mysql':
 150      case 'mysqli':
 151        $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetid presetid INT UNSIGNED NOT NULL AUTO_INCREMENT');
 152        $ret[] = update_sql('ALTER TABLE {imagecache_preset} CHANGE rulesetname presetname VARCHAR(255) NOT NULL DEFAULT \'\'');
 153        $ret[] = update_sql('ALTER TABLE {imagecache_action} CHANGE rulesetid presetid  INTEGER NOT NULL DEFAULT 0');
 154        break;
 155  
 156      case 'pgsql':
 157        $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetid TO presetid');
 158        $ret[] = update_sql('ALTER TABLE {imagecache_preset} RENAME COLUMN rulesetname TO presetname');
 159        $ret[] = update_sql('ALTER TABLE {imagecache_action} RENAME COLUMN rulesetid TO presetid');
 160        break;
 161    }
 162    return $ret;
 163  }
 164  
 165  
 166  /**
 167   * Remove auto-increment from tables, instead depending on the sequences table and db_next_id()
 168   */
 169  function imagecache_update_3() {
 170    $ret = array();
 171  
 172    $count_action = db_result(db_query('SELECT max(actionid) FROM {imagecache_action}')) + 1;
 173    $count_preset = db_result(db_query('SELECT max(presetid) FROM {imagecache_preset}')) + 1;
 174  
 175    switch ($GLOBALS['db_type']) {
 176      case 'mysql':
 177      case 'mysqli':
 178        $ret[] = update_sql("ALTER TABLE {imagecache_action} CHANGE actionid actionid INT UNSIGNED NOT NULL");
 179        $ret[] = update_sql("ALTER TABLE {imagecache_preset} CHANGE presetid presetid INT UNSIGNED NOT NULL");
 180        // Add the sequences
 181        $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_action}_actionid', $count_action)");
 182        $ret[] = update_sql("INSERT INTO {sequences} (name, id) VALUES ('{imagecache_preset}_presetid', $count_preset)");
 183        break;
 184      case 'pgsql':
 185        db_change_column($ret, 'imagecache_action', 'actionid', 'actionid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
 186        db_change_column($ret, 'imagecache_preset', 'presetid', 'presetid', 'INT', $attributes = array('not null' => TRUE, 'default' => '0'));
 187        // Re-add our indexes
 188        $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD PRIMARY KEY (actionid)");
 189        $ret[] = update_sql("ALTER TABLE {imagecache_preset} ADD PRIMARY KEY (rulesetid)");
 190        // Add the sequences
 191        $ret[] = update_sql("CREATE SEQUENCE {imagecache_action}_actionid_seq INCREMENT 1 START $count_action;");
 192        $ret[] = update_sql("CREATE SEQUENCE {imagecache_preset}_presetid_seq INCREMENT 1 START $count_preset;");
 193    }
 194    return $ret;
 195  }
 196  
 197  function imagecache_update_4() {
 198    $ret = array();
 199  
 200     // add action column to the imagecache_action table just becuase serialization bugs me.
 201     switch ($GLOBALS['db_type']) {
 202      case 'mysql':
 203      case 'mysqli':
 204        $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) not null default '' after weight");
 205         break;
 206      case 'pgsql':
 207        $ret[] = update_sql("ALTER TABLE {imagecache_action} ADD COLUMN action varchar(255) NOT NULL DEFAULT ''");
 208        break;
 209    }
 210  
 211    // unserialize what we can.
 212    $result = db_query("SELECT * FROM {imagecache_action}");
 213    while ($row = db_fetch_array($result)) {
 214      $data = unserialize($row['data']);
 215  
 216      // remove function from data if present;
 217      $function = $data['function'];
 218      unset($data['function']);
 219      $data = serialize($data);
 220  
 221      // Rename scale and crop for any people who upgraded early...
 222      if ($function == 'scale and crop') {
 223        $function = 'scale_and_crop';
 224      }
 225      // Keep scale and crop and the old scale function seperate... I don't really want to break BC with
 226      // the 2.x update. We'll deprecate this version.
 227      if ($function == 'scale') {
 228        $function = 'deprecated_scale';
 229      }
 230  
 231      // prefix with module name as per new status quo.
 232      // since other modules couldn't implement actions before this update
 233      // we assume imagecache...
 234      $function = 'imagecache_'. $function;
 235  
 236      db_query("UPDATE {imagecache_action} SET action='%s', data='%s' WHERE actionid = %d", $function, $data, $row['actionid']);
 237    }
 238    cache_clear_all('*', 'cache', TRUE);
 239    return $ret;
 240  }
 241  
 242  function imagecache_update_5() {
 243    // enable image API.
 244    module_rebuild_cache(); // make sure new modules are in the system table.
 245    module_enable(array('imageapi', 'imageapi_gd', 'imageapi_imagemagick')); // enable our new module.
 246  
 247    // @todo: update formatter names: http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/imagecache/imagecache.module?r1=1.68&r2=1.68.2.8&pathrev=DRUPAL-5--2
 248    // ln: 516 diff 511.
 249  
 250    return array();
 251  }
 252  
 253  /**
 254   * Upgrade from Drupal 5 => Drupal 6.
 255   *
 256   * Use serial data type for primary keys.  Add module field and presetid index.
 257   */
 258  function imagecache_update_6000() {
 259    $ret = array();
 260  
 261    // Our additions to the schema.
 262    $schema['imagecache_preset'] = array(
 263      'fields' => array(
 264        'presetid' => array(
 265          'description' => t('The primary identifier for an imagecache_preset.'),
 266          'type' => 'serial',
 267          'unsigned' => TRUE,
 268          'not null' => TRUE,
 269        ),
 270      ),
 271      'primary key' => array('presetid'),
 272    );
 273    $schema['imagecache_action'] = array(
 274      'fields' => array(
 275        'actionid' => array(
 276          'description' => t('The primary identifier for an imagecache_action.'),
 277          'type' => 'serial',
 278          'unsigned' => TRUE,
 279          'not null' => TRUE,
 280        ),
 281        'module' => array(
 282          'description' => t('The module that defined the action.'),
 283          'type' => 'varchar',
 284          'length' => 255,
 285          'not null' => TRUE,
 286          'initial' => 'imagecache',
 287        ),
 288      ),
 289      'primary key' => array('actionid'),
 290    );
 291  
 292    // Update primary keys to serial type for Drupal 6
 293    foreach ($schema as $table => $info) {
 294      $field = $info['primary key'][0];
 295      if (db_table_exists('sequences')) {
 296        $ret[] = update_sql("DELETE FROM {sequences} WHERE name = '{{$table}}_{$field}'");
 297      }
 298      db_change_field($ret, $table, $field, $field, $info['fields'][$field]);
 299    }
 300  
 301    // Going to assume that if the table doesn't have a module column that
 302    // it needs the index as well.
 303    if (!db_column_exists('imagecache_action', 'module')) {
 304      // Add 'module' column to action table.
 305      db_add_field($ret, 'imagecache_action', 'module', $schema['imagecache_action']['fields']['module']);
 306  
 307      // Add 'presetid' index to action table
 308      db_add_index($ret, 'imagecache_action', 'presetid', array('presetid'));
 309    }
 310  
 311  
 312    return $ret;
 313  }
 314  
 315  /**
 316   * Make sure the schemas match, the weight should be signed.
 317   */
 318  function imagecache_update_6001() {
 319    $ret = array();
 320    db_change_field($ret, 'imagecache_action', 'weight', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0));
 321    return $ret;
 322  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7