You are here

exif.install in Exif 5

Same filename and directory in other branches
  1. 8.2 exif.install
  2. 8 exif.install
  3. 6 exif.install
  4. 7 exif.install

File

exif.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function exif_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {exif_tags} (\n          ifd int(10) unsigned NOT NULL default '0',\n          tag int(10) unsigned NOT NULL default '0',\n          status int(10) unsigned NOT NULL default '0',\n          weight int(11) NOT NULL default '0',\n          PRIMARY KEY (ifd, tag)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      db_query("CREATE TABLE {exif} (\n          fid int(10) unsigned NOT NULL default '0',\n          ifd int(10) unsigned NOT NULL default '0',\n          tag int(10) unsigned NOT NULL default '0',\n          value varchar(255) NOT NULL default '',\n          PRIMARY KEY (fid, ifd, tag)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      db_query("CREATE TABLE {exif_tags} (\n          ifd integer NOT NULL default '0',\n          tag integer NOT NULL default '0',\n          status integer NOT NULL default '0',\n          weight integer NOT NULL default '0',\n          PRIMARY KEY (ifd, tag)\n        );");
      db_query("CREATE TABLE {exif} (\n          fid int(10) unsigned NOT NULL default '0',\n          ifd int(10) unsigned NOT NULL default '0',\n          tag int(10) unsigned NOT NULL default '0',\n          value varchar(255) NOT NULL default '',\n          PRIMARY KEY (fid, ifd, tag)\n        );");
      break;
  }
}
function exif_update_1() {

  // Works for postgres??
  $ret[] = update_sql('ALTER TABLE {exif} RENAME TO {exif_tags}');

  // make new table for caching and tracking exif data.
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $ret[] = update_sql("CREATE TABLE {exif} (\n          fid int(10) unsigned NOT NULL default '0',\n          ifd int(10) unsigned NOT NULL default '0',\n          tag int(10) unsigned NOT NULL default '0',\n          value varchar(255) NOT NULL default '',\n          PRIMARY KEY (fid, ifd, tag)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $ret[] = update_sql("CREATE TABLE {exif} (\n          fid int(10) unsigned NOT NULL default '0',\n          ifd int(10) unsigned NOT NULL default '0',\n          tag int(10) unsigned NOT NULL default '0',\n          value varchar(255) NOT NULL default '',\n          PRIMARY KEY (fid, ifd, tag)\n        );");
      break;
  }
  return $ret;
}

/**
 * Add exif for existing images if they exist.
 */
function exif_update_2() {
  if (!isset($_SESSION['exif_update_2'])) {
    $_SESSION['exif_update_2']['nid'] = 0;
    $_SESSION['exif_update_2']['max'] = db_result(db_query("SELECT MAX(nid) FROM {node} WHERE type = 'image'"));
  }
  $context =& $_SESSION['exif_update_2'];
  $result = db_query_range("SELECT f.* FROM {files} f JOIN {node} n ON n.nid = f.nid\n    WHERE n.type = 'image' AND n.nid > %d AND f.filename = '_original'\n    ORDER BY n.nid DESC", $context['nid'], 0, 20);
  while ($file = db_fetch_object($result)) {
    _update_exif_data($file);
    $context['nid'] = $file->nid;
  }
  if ($context['nid'] < $context['max']) {

    // Approximation of how close to done we are...
    return array(
      '#finished' => $context['nid'] / $context['max'],
    );
  }
  else {
    unset($_SESSION['exif_update_2']);
    return array(
      '#finished' => 1,
    );
  }
}

/**
 * Implementation of hook_uninstall().
 */
function exif_uninstall() {
  db_query('DROP TABLE {exif_tags}');
  db_query('DROP TABLE {exif}');
}

Functions

Namesort descending Description
exif_install Implementation of hook_install().
exif_uninstall Implementation of hook_uninstall().
exif_update_1
exif_update_2 Add exif for existing images if they exist.