You are here

jquery_countdown_block.install in jQuery Countdown 6

Provides install, upgrade and un-install functions for jquery_countdown_block module.

File

jquery_countdown_block/jquery_countdown_block.install
View source
<?php

/**
 * @file
 * Provides install, upgrade and un-install functions for jquery_countdown_block module.
 */
function jquery_countdown_block_uninstall() {

  // delete all jquery_countdown_block setting variables...
  foreach (variable_get('jquery_countdown_block_ids', array()) as $delta) {
    variable_del("jquery_countdown_block_{$delta}_settings");
  }
  variable_del('jquery_countdown_block_ids');

  // Remove block configurations.
  db_query("DELETE FROM {blocks} WHERE module = 'jquery_countdown_block'");
  db_query("DELETE FROM {blocks_roles} WHERE module = 'jquery_countdown_block'");
  cache_clear_all();
}

/**
 * Implements hook_install().
 */
function jquery_countdown_block_install() {

  // No-op.
}

/**
 * Implement hook_update_N()
 * Removes all block settings variables and store as array into one variable...
 * 
 * @param $sandbox
 * @return array
 */
function jquery_countdown_block_update_6100(&$sandbox) {
  $current_block_ids = variable_get('jquery_countdown_block_ids', array());

  // now get for every block the settings and restore it in one variable...
  foreach ($current_block_ids as $block_id) {
    $block_settings = array();
    $stored_vars = array(
      'admin_title' => 'jquery_countdown_block_' . $block_id . '_admin_title',
      'caption' => 'jquery_countdown_block_' . $block_id . '_caption',
      'date' => 'jquery_countdown_block_' . $block_id . '_date',
      'until' => 'jquery_countdown_block_' . $block_id . '_until',
      'format' => 'jquery_countdown_block_' . $block_id . '_format',
      'serversync' => 'jquery_countdown_block_' . $block_id . '_serversync',
      'compact' => 'jquery_countdown_block_' . $block_id . '_compact',
    );
    foreach ($stored_vars as $store_key => $var) {
      $var_value = variable_get($var, NULL);

      // only store if we have a value...
      if ($var_value) {
        $block_settings[$store_key] = $var_value;
      }
    }

    // save in new settings variable...
    variable_set('jquery_countdown_block_' . $block_id . '_settings', $block_settings);

    // second foreach for deleting after save... (to ensure we have all data stored)
    foreach ($stored_vars as $store_key => $var) {
      variable_del($var);
    }
  }
  return array();
}

Functions

Namesort descending Description
jquery_countdown_block_install Implements hook_install().
jquery_countdown_block_uninstall @file Provides install, upgrade and un-install functions for jquery_countdown_block module.
jquery_countdown_block_update_6100 Implement hook_update_N() Removes all block settings variables and store as array into one variable...