You are here

imagecrop.install in Image javascript crop 6

Same filename and directory in other branches
  1. 5 imagecrop.install
  2. 7 imagecrop.install

Install file.

File

imagecrop.install
View source
<?php

/**
 * @file
 * Install file.
 */

/**
 * Implementation of hook_enable().
 */
function imagecrop_enable() {
  cache_clear_all('imagecache_actions', 'cache');
}

/**
 * Implementation of hook_disable().
 */
function imagecrop_disable() {
  cache_clear_all('imagecache_actions', 'cache');
}

/**
 * Implementation of hook_schema().
 */
function imagecrop_schema() {
  $schema['imagecrop'] = array(
    'fields' => array(
      'fid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'presetname' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'reference' => array(
        'type' => 'varchar',
        'length' => '40',
        'not null' => TRUE,
        'default' => '',
      ),
      'xoffset' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'yoffset' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'width' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'height' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'scale' => array(
        'type' => 'varchar',
        'length' => '10',
        'not null' => TRUE,
        'default' => 'original',
      ),
    ),
    'primary key' => array(
      'fid',
      'presetname',
      'reference',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function imagecrop_install() {
  drupal_install_schema('imagecrop');
  db_query("UPDATE {system} SET weight = 1 WHERE name = 'imagecrop'");
}

/**
 * Update 1 : set weight to 1
 */
function imagecrop_update_2() {
  $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'imagecrop'");
  return array();
}

/**
 * Update 2 : Add extra field to imagecrop table
 */
function imagecrop_update_3() {
  $ret[] = db_query("ALTER TABLE {imagecrop} ADD scale VARCHAR( 10 ) NOT NULL DEFAULT 'original'");
  return array();
}

/**
 * Update 3 : Add indexes to imagecrop table
 */
function imagecrop_update_4() {
  $ret[] = db_query("ALTER TABLE {imagecrop} ADD INDEX (fid)");
  $ret[] = db_query("ALTER TABLE {imagecrop} ADD INDEX (presetid)");
  return array();
}

/**
 * Update 6100 : Change preset ids into preset names, and add correct primary key for it.
 */
function imagecrop_update_6100() {
  $ret[] = update_sql("ALTER TABLE {imagecrop} ADD presetname VARCHAR(255)");

  // Get all presets.
  $presets = array();
  $result = db_query('SELECT presetid, presetname FROM {imagecache_preset}');
  while ($row = db_fetch_object($result)) {
    $presets[$row->presetid] = $row->presetname;
  }

  // Get all presetids and update them.
  $result = db_query('SELECT DISTINCT(presetid) FROM {imagecrop}');
  while ($row = db_fetch_object($result)) {

    // Only update when the presetname exists.
    if (!isset($presets[$row->presetid])) {
      return;
    }
    $preset = db_escape_string($presets[$row->presetid]);
    $ret[] = update_sql("UPDATE {imagecrop} SET presetname = '{$preset}' WHERE presetid = {$row->presetid}");
  }
  db_drop_index($ret, 'imagecrop', 'fid');
  db_drop_field($ret, 'imagecrop', 'presetid');
  db_add_primary_key($ret, 'imagecrop', array(
    'fid, presetname',
  ));
  return $ret;
}

/**
 * Update 6200 : Also add reference to the primary key.
 */
function imagecrop_update_6200() {
  $ret = array();
  db_drop_primary_key($ret, 'imagecrop');
  db_add_primary_key($ret, 'imagecrop', array(
    'fid, presetname',
    'reference',
  ));
  return $ret;
}

/**
 * Implementation of hook_uninstall().
 */
function imagecrop_uninstall() {
  drupal_uninstall_schema('imagecrop');
  db_query("DELETE FROM {system} where name = 'imagecrop'");
  variable_del('imagecrop_modules');
  variable_del('imagecrop_fields');
}

Functions

Namesort descending Description
imagecrop_disable Implementation of hook_disable().
imagecrop_enable Implementation of hook_enable().
imagecrop_install Implementation of hook_install().
imagecrop_schema Implementation of hook_schema().
imagecrop_uninstall Implementation of hook_uninstall().
imagecrop_update_2 Update 1 : set weight to 1
imagecrop_update_3 Update 2 : Add extra field to imagecrop table
imagecrop_update_4 Update 3 : Add indexes to imagecrop table
imagecrop_update_6100 Update 6100 : Change preset ids into preset names, and add correct primary key for it.
imagecrop_update_6200 Update 6200 : Also add reference to the primary key.