You are here

function skinr_context_enable in Skinr 7.2

Same name and namespace in other branches
  1. 8.2 skinr_context/skinr_context.install \skinr_context_enable()

Implements hook_enable().

File

skinr_context/skinr_context.install, line 114
Contains install, update, and uninstall functions for Skinr Context.

Code

function skinr_context_enable() {
  $t = get_t();

  // Associate each skin with a group, if it isn't already.
  $query = db_select('skinr_skins', 's');
  $query
    ->leftJoin('skinr_group_skins', 'gs', 's.sid = gs.sid');
  $query
    ->fields('s');
  $query
    ->fields('gs', array(
    'gid',
  ));
  $result = $query
    ->execute();
  foreach ($result as $skin) {
    $skin->options = unserialize($skin->options);
    if (empty($skin->gid)) {
      _skinr_context_add_default_group($skin);

      // Simulate insert to ensure group is linked.
      skinr_context_skinr_skin_insert($skin);
    }
    $group = skinr_context_group_load($skin->gid);
    if ($skin->status && $group && !$group->status) {

      // Disable skins where group is disabled.
      $skin->status = 0;
      skinr_skin_save($skin);
    }
  }
}