You are here

ed_classified.install in Classified Ads 5

File

ed_classified.install
View source
<?php

/*
 * @file
 * Installer
 */
define('ED_CLASSIFIED_MODULE_NAME', 'ed_classified');
function ed_classified_install() {
  switch (reset(explode('.', VERSION))) {
    case 5:
      break;
    case 6:
      drupal_install_schema('ed_classified');
      break;
    case 7:
      break;
  }
  ed_classified_init_taxonomy();
}

/**
 * Implementation of hook_schema().
 */
function ed_classified_schema() {
  $schema['edi_classified_nodes'] = array(
    'fields' => array(
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'expires_on' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'expiration_notify_last_sent' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );
  return $schema;
}
function ed_classified_init_taxonomy() {
  drupal_set_message(t('Creating classified ads taxonomy terms'));
  $vid = variable_get('ed_classified_vocabulary', '');
  if (empty($vid)) {
    $vid = db_result(db_query("SELECT vid FROM {vocabulary} WHERE module='%s'", ED_CLASSIFIED_MODULE_NAME));
    if (!$vid) {
      $vocabulary = array(
        'name' => 'Classified Ad Category',
        'description' => t('Vocabulary required by Classified Ads (ed_classified) module.  <strong>Warning:  You should not delete this vocabulary unless you intend to uninstall (or have already uninstalled) the Classified Ads module.</strong>'),
        'multiple' => '0',
        'required' => '1',
        'hierarchy' => '1',
        'relations' => '0',
        'module' => ED_CLASSIFIED_MODULE_NAME,
        'nodes' => array(
          ED_CLASSIFIED_MODULE_NAME => 1,
        ),
      );
      taxonomy_save_vocabulary($vocabulary);
      $vid = $vocabulary['vid'];
    }
    variable_set('ed_classified_vocabulary', $vid);
  }
  $msg = t('Install: Classified Ad vocabulary !vid created.', array(
    '!vid' => $vid,
  ));
  drupal_set_message($msg);
  watchdog('Classified Ads', $msg);
}

/**
* Implementation of hook_uninstall().
*/
function ed_classified_uninstall() {
  switch (reset(explode('.', VERSION))) {
    case 5:
      db_query('DROP TABLE {edi_classified_nodes}');
      break;
    case 6:
      drupal_uninstall_schema('ed_classified');
      break;
    case 7:
      break;
  }
  db_query('DELETE FROM {variable} WHERE name LIKE "ed_classified%";');
  db_query('DELETE FROM {vocabulary} WHERE module = "%s"', ED_CLASSIFIED_MODULE_NAME);
}

Functions

Namesort descending Description
ed_classified_init_taxonomy
ed_classified_install
ed_classified_schema Implementation of hook_schema().
ed_classified_uninstall Implementation of hook_uninstall().

Constants