You are here

google_adwords.install in Google AdWords Conversion Tracking 6

File

google_adwords.install
View source
<?php

// $Id$

/**
 * Implementation of hook_install().
 */
function google_adwords_install() {

  // Create table
  $created = drupal_install_schema('google_adwords');
  if ($created) {
    drupal_set_message(t('Google AdWords module installed successfully. You must set <a href="/admin/user/permissions#module-google_adwords">permissions</a> and <a href="/admin/settings/google_adwords">configure</a> the module. '));
  }
  else {
    drupal_set_message(t('Table installation for the Google AdWords module was unsuccessful. The tables may need to be installed by hand. See google_adwords.install file for a list of the installation queries.'), 'error');
  }
  return;
}

/**
 * Implementation of hook_uninstall().
 */
function google_adwords_uninstall() {

  // Remove variables
  db_query('DELETE FROM {variable} WHERE name LIKE "google_adwords_%"');

  // Remove table
  $deleted = drupal_uninstall_schema('google_adwords');
  if ($deleted) {
    drupal_set_message(t('Google AdWords module has been uninstalled successfully.'));
  }
  else {
    drupal_set_message(t('Table removal for the Google AdWords module was unsuccessful. The tables may need to be uninstalled by hand. See google_adwords.install file for a list of the uninstall queries.'), 'error');
  }
  return;
}

/**
 * Implementation of hook_schema().
 */
function google_adwords_schema() {
  $schema['google_adwords'] = array(
    'description' => t('Stores Google AdWords for nodes.'),
    'primary key' => array(
      'vid',
    ),
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('The {node}.nid to associated with the Google AdWords.'),
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => t('Primary Key: The {node}.vid associated with the Google AdWords.'),
      ),
      'enabled' => array(
        'type' => 'int',
        'description' => t('Useful to turn on and off Google AdWords on a per node basis.'),
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'label' => array(
        'type' => 'varchar',
        'default' => '',
        'length' => 255,
      ),
      'format' => array(
        'type' => 'varchar',
        'default' => '',
        'length' => 10,
      ),
    ),
  );
  return $schema;
}
function google_adwords_update_6001() {
  $ret = array();
  db_add_field($ret, 'google_adwords', 'format', array(
    'type' => 'varchar',
    'length' => 10,
  ));
  db_add_field($ret, 'google_adwords', 'color', array(
    'type' => 'varchar',
    'length' => 10,
  ));
  return $ret;
}

/**
 * Translate old role tracking variables to new role tracking variables
 *
 * Update for 6.x-1.x branches should start with 6101, not 6001
 * @see http://api.drupal.org/api/drupal/developer--hooks--install.php/function/hook_update_N/6
 */
function google_adwords_update_6102() {
  $roles = user_roles();
  foreach ($roles as $rid => $name) {
    $old_key = 'google_adwords_track_' . str_replace(' ', '_', $name);
    $new_key = 'google_adwords_track_' . $rid;
    variable_set($new_key, variable_get($old_key, FALSE));
    variable_del($old_key);
  }
  return array();
}

Functions

Namesort descending Description
google_adwords_install Implementation of hook_install().
google_adwords_schema Implementation of hook_schema().
google_adwords_uninstall Implementation of hook_uninstall().
google_adwords_update_6001
google_adwords_update_6102 Translate old role tracking variables to new role tracking variables