You are here

content_theme.install in Content Theme 6

Same filename and directory in other branches
  1. 7.2 content_theme.install
  2. 7 content_theme.install

Install, update and uninstall functions for the content_theme module.

File

content_theme.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the content_theme module.
 */

/**
 * Implementation of hook_schema().
 */
function content_theme_schema() {
  $schema = array();
  $schema['content_theme_node'] = array(
    'description' => 'Stores assigned themes when creating, editing, or viewing content.',
    'fields' => array(
      'ctnid' => array(
        'description' => 'Primary Key: Unique content node theme ID.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'nid' => array(
        'description' => 'Node id to which the theme is assigned.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'action' => array(
        'description' => 'Node action to which the theme is assigned.',
        'type' => 'varchar',
        'length' => 32,
        'not null' => TRUE,
        'default' => '',
      ),
      'theme' => array(
        'description' => 'Theme name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'ctnid',
    ),
    'unique keys' => array(
      'node_action' => array(
        'nid',
        'action',
      ),
    ),
    'indexes' => array(
      'list' => array(
        'nid',
        'action',
        'theme',
      ),
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function content_theme_install() {
  drupal_install_schema('content_theme');
}

/**
 * Implementation of hook_uninstall().
 */
function content_theme_uninstall() {
  drupal_uninstall_schema('content_theme');
  foreach (node_get_types('names') as $type => $name) {
    variable_del('content_theme_content_type_edit_' . $type);
    variable_del('content_theme_content_type_view_' . $type);
  }
  variable_del('content_theme_content_wide_edit');
  variable_del('content_theme_content_wide_view');
}

/**
 * Implementation of hook_update_N().
 *
 * Changes default value for theme field.
 */
function content_theme_update_6100() {
  $ret = array();
  db_drop_primary_key($ret, 'content_theme_node');
  db_change_field($ret, 'content_theme_node', 'theme', 'theme', array(
    'type' => 'varchar',
    'length' => 255,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'primary key' => array(
      'nid',
      'action',
    ),
  ));
  return $ret;
}

/**
 * Implementation of hook_update_N().
 *
 * Adds content node theme ID field and updates table indices.
 */
function content_theme_update_6101() {
  $ret = array();
  db_drop_primary_key($ret, 'content_theme_node');
  db_add_field($ret, 'content_theme_node', 'ctnid', array(
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  ), array(
    'primary key' => array(
      'ctnid',
    ),
  ));
  db_add_unique_key($ret, 'content_theme_node', 'node_action', array(
    'nid',
    'action',
  ));
  db_add_index($ret, 'content_theme_node', 'list', array(
    'nid',
    'action',
    'theme',
  ));
  return $ret;
}

/**
 * Implementation of hook_update_N().
 *
 * Updates content theme permissions.
 */
function content_theme_update_6102() {
  $ret = array();
  $result = db_query('SELECT p.rid, r.name, p.perm FROM {permission} p LEFT JOIN {role} r ON r.rid = p.rid');
  while ($row = db_fetch_object($result)) {
    $perms = array_flip(explode(', ', $row->perm));
    if (isset($perms['create content theme'])) {
      unset($perms['create content theme']);
      $perms = array_flip($perms);
      foreach (node_get_types('names') as $type => $name) {
        $perms[] = "select {$type} content editing theme";
        $perms[] = "select {$type} content viewing theme";
      }
      db_query('UPDATE {permission} SET perm = "%s" WHERE rid = %d', implode(', ', $perms), $row->rid);
      $ret[] = array(
        'success' => TRUE,
        'query' => t('Updated content theme permissions of @role', array(
          '@role' => $row->name,
        )),
      );
    }
  }
  cache_clear_all();
  return $ret;
}

Functions

Namesort descending Description
content_theme_install Implementation of hook_install().
content_theme_schema Implementation of hook_schema().
content_theme_uninstall Implementation of hook_uninstall().
content_theme_update_6100 Implementation of hook_update_N().
content_theme_update_6101 Implementation of hook_update_N().
content_theme_update_6102 Implementation of hook_update_N().