You are here

block_class_styles.install in Block Class Styles 7.2

Same filename and directory in other branches
  1. 7 block_class_styles.install

Handles installation steps for block_class_styles

File

block_class_styles.install
View source
<?php

/**
 * @file
 * Handles installation steps for block_class_styles
 *
 * @ingroup func_search
 * @{
 */

/*
 * Implements hook_uninstall().
 */
function block_class_styles_uninstall() {
  $vars = db_select('variable', 'v')
    ->fields('v', array(
    'name',
  ))
    ->condition('name', 'block_class_styles%', 'LIKE')
    ->execute()
    ->fetchCol();
  foreach ($vars as $var) {
    variable_del($var);
  }
}

/**
 * Implements hook_enable().
 */
function block_class_styles_enable() {

  //message about module settings
  drupal_set_message(t('You may administer your block styles now by visiting <a href="@url">@url</a>.', array(
    '@url' => url(BLOCK_CLASS_STYLES_PATH_SETTINGS),
  )));

  // Change the system weight for the module (in relation to another)...
  $weight = db_select('system', 's')
    ->fields('s', array(
    'weight',
  ))
    ->condition('name', 'block_class')
    ->execute()
    ->fetchField();
  db_update('system')
    ->fields(array(
    'weight' => ++$weight,
  ))
    ->condition('name', 'block_class_styles')
    ->execute();
}

/**
 * Grant new permission: Use Block Styles to all roles.
 */
function block_class_styles_update_7101(&$sandbox) {
  $output = array();
  try {
    $rids = user_roles();
    foreach ($rids as $rid => $name) {
      db_merge('role_permission')
        ->key(array(
        'rid' => $rid,
        'permission' => 'block_class_styles:use',
      ))
        ->fields(array(
        'module' => 'block_class_styles',
      ))
        ->execute();
    }
    $output[] = t('All roles have received new permission: %perm', array(
      '%perm' => 'Use Block Styles',
    ));
  } catch (Exception $e) {
    throw new DrupalUpdateException('FAILED: ');
  }
  if (empty($output)) {
    $output[] = t('Nothing to update.');
  }
  return implode(PHP_EOL, $output);
}

Functions

Namesort descending Description
block_class_styles_enable Implements hook_enable().
block_class_styles_uninstall
block_class_styles_update_7101 Grant new permission: Use Block Styles to all roles.