<?php

/**
 * @file
 * Install file for the Domain Theme module
 */

/**
 * Implements hook_schema().
 */
function domain_theme_schema() {
  $schema['domain_theme'] = array(
    'description' => 'Stores theme information for each domain.',
    'fields' => array(
      'domain_id' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
      'theme' => array('type' => 'varchar', 'length' => '255', 'not null' => TRUE, 'default' => ''),
      'settings' => array('type' => 'blob', 'not null' => FALSE),
      'status' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0),
      'filepath' => array('type' => 'varchar', 'length' => '255', 'not null' => FALSE)),
    'primary key' => array('domain_id', 'theme'),
    'foreign_keys' => array(
      'domain_id' => array('domain' => 'domain_id'),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function domain_theme_uninstall() {
  variable_del('domain_theme_weight');
}

/**
 * Implements hook_dependencies().
 */
function domain_theme_update_dependencies() {
  $dependencies['domain_theme'][7300] = array(
    'domain' => 7303,
  );
  return $dependencies;
}

/**
 * Remove references to row 0.
 */
function domain_theme_update_7300(&$sandbox) {
  $default_id = db_query("SELECT domain_id FROM {domain} WHERE is_default = 1")->fetchField();
  db_update('domain_theme')
    ->fields(array('domain_id' => $default_id))
    ->condition('domain_id', 0)
    ->execute();
  return t('Domain Theme zero records removed.');
}
