Skip to content
better_formats.install 2.67 KiB
Newer Older
Alan Doucette's avatar
Alan Doucette committed
<?php
// $Id$

Alan Doucette's avatar
Alan Doucette committed
/**
 * @file
 * Installs the better_formats module.
 *
 * Creates a database for use of multi-layered default formats and sets 
 * default settings.
 */


Alan Doucette's avatar
Alan Doucette committed
/**
 * Implementation of hook_schema().
Alan Doucette's avatar
Alan Doucette committed
 */
function better_formats_schema() {
  $schema['better_formats_defaults'] = array(
    'fields' => array(
      'rid' => array(
        'type'     => 'int',
        'size'     => 'normal',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'type'     => 'varchar',
        'length'   => 255,
        'not null' => TRUE,
      ),
      'format' => array(
        'type' => 'int',
        'size' => 'medium',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type_weight' => array(
        'type'     => 'int',
        'size'     => 'tiny',
        'default'  => 0,
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'weight' => array(
        'type'     => 'int',
        'size'     => 'tiny',
        'default'  => 0,
        'unsigned' => FALSE,
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('rid', 'type'),
  );

  return $schema;
}

/**
 * Implementation of hook_install().
Alan Doucette's avatar
Alan Doucette committed
 */
function better_formats_install() {
  // create tables
  drupal_install_schema('better_formats');
  
  // increase module weight to prevent compatibility issues
  $sql = "UPDATE {system} 
          SET weight = 100 
          WHERE name = 'better_formats'";
  db_query($sql);
  
Alan Doucette's avatar
Alan Doucette committed
  // insert defaults
  $roles = user_roles();
  $sql   = "INSERT INTO {better_formats_defaults} 
            VALUES (%d, '%s', %d, %d, %d)";
  foreach ($roles as $rid => $role) {
    db_query($sql, $rid, 'node', 0, 1, 0);
    db_query($sql, $rid, 'comment', 0, 1, 0);
  }
  
  // default perms to be like core defaults
  $default_perms = ',show format selection,show format tips,show more format tips link,collapsible format selection,collapse format fieldset by default';
  // get current core perms
  $sql = "SELECT * 
          FROM {permission} 
          WHERE rid IN (1,2)";
  $result = db_query($sql);
  $row_perms = array();
  while ($row = db_fetch_object($result)) {
    $role_perms[] = $row;
  }
  // add perms to core roles (anonymous user, authenticated user)
  foreach ($role_perms as $perms) {
    $sql = "UPDATE {permission} 
            SET perm = '%s' 
            WHERE pid = %d";
    db_query($sql, $perms->perm . $default_perms, $perms->pid);
  }
Alan Doucette's avatar
Alan Doucette committed
}

/**
 * Implementation of hook_uninstall().
Alan Doucette's avatar
Alan Doucette committed
 */
Alan Doucette's avatar
Alan Doucette committed
function better_formats_uninstall() {
Alan Doucette's avatar
Alan Doucette committed
  drupal_uninstall_schema('better_formats');
  // delete settings variables from varible table
  $sql = "DELETE FROM {variable} 
          WHERE name LIKE 'better_formats%'";
Alan Doucette's avatar
Alan Doucette committed
}