You are here

image_attach.install in Image 5.2

File

contrib/image_attach/image_attach.install
View source
<?php

function image_attach_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      db_query("CREATE TABLE {image_attach} (\n        nid int(10) unsigned NOT NULL default '0',\n        iid int(10) unsigned NOT NULL default '0',\n        PRIMARY KEY  (nid),\n        KEY (iid)\n      ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {image_attach} (\n        nid integer NOT NULL default '0',\n        iid integer NOT NULL default '0',\n        PRIMARY KEY (nid)\n      )");
      db_query("CREATE INDEX {image_attach}_iid_idx ON {image_attach}(iid)");
      break;
    case 'oracle10':
      db_query("CREATE TABLE {image_attach} (\n        nid integer default '0' NOT NULL,\n        iid integer default '0' NOT NULL,\n        CONSTRAINT {image_attach}_pkey PRIMARY KEY (nid)\n      )");
      db_query("CREATE INDEX {image_attach}_iid_idx ON {image_attach}(iid)");
      break;
  }
}
function image_attach_uninstall() {
  db_query('DROP TABLE {image_attach}');
  variable_del('image_attach_existing');
  variable_del('image_attach_block_0_size');
}

/**
 * Add an index to the image id field.
 */
function image_attach_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("ALTER TABLE {image_attach} ADD KEY (iid)");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE INDEX {image_attach}_iid_idx ON {image_attach}(iid)");
      break;
  }
  return $ret;
}

/**
 * Remove attach records that point to a missing image.
 */
function image_attach_update_2() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysqli':
    case 'mysql':
      $ret[] = update_sql("DELETE FROM {image_attach} USING {image_attach} LEFT JOIN {node} n ON {image_attach}.iid = n.nid WHERE n.nid IS NULL OR n.type != 'image'");
      break;
    case 'pgsql':
      $ret[] = update_sql("DELETE FROM {image_attach} USING {node} n WHERE {image_attach}.iid = n.nid AND (n.nid IS NULL OR n.type != 'image')");
      break;
  }
  return $ret;
}

Functions

Namesort descending Description
image_attach_install
image_attach_uninstall
image_attach_update_1 Add an index to the image id field.
image_attach_update_2 Remove attach records that point to a missing image.