You are here

adsense.install in Google AdSense integration 5

File

adsense.install
View source
<?php

function adsense_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $success = db_query("CREATE TABLE IF NOT EXISTS {adsense_clicks} (\n        aid       INT(10)     NOT NULL AUTO_INCREMENT,\n        ip        VARCHAR(15) DEFAULT '0',\n        timestamp INT(11)     unsigned NOT NULL DEFAULT '0',\n        path      VARCHAR(255) NOT NULL DEFAULT '',\n        PRIMARY KEY  (aid),\n        KEY (timestamp)\n        ) /*!40100 DEFAULT CHARACTER SET utf8 */;");
      break;
    case 'pgsql':
      $success = db_query("CREATE TABLE {adsense_clicks} (\n        aid       SERIAL,\n        ip        VARCHAR(15) DEFAULT '0',\n        timestamp INTEGER NOT NULL DEFAULT '0',\n        path      VARCHAR(255) DEFAULT '',\n        PRIMARY KEY  (aid));");
      $success = db_query("CREATE INDEX {timestamp} ON {adsense_clicks} (timestamp);");
      break;
  }
  if ($success) {
    drupal_set_message(t('Adsense module table creation successful.'));
  }
  else {
    drupal_set_message(t('Adsense module table creation was unsuccessful.'), 'error');
  }
}

/**
 * Implementation of hook_uninstall().
 */
function adsense_uninstall() {
  db_query('DROP TABLE {adsense_clicks}');
}
function adsense_update_1() {
  adsense_install();
}
function adsense_update_2() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("ALTER TABLE {adsense_clicks} ADD `path` varchar(255) default ''");
      break;
  }
}