You are here

function fe_block_boxes_features_revert in Features Extra 7

Same name and namespace in other branches
  1. 6 fe_block.module \fe_block_boxes_features_revert()

Implements hook_features_revert().

2 calls to fe_block_boxes_features_revert()
fe_block_boxes_features_enable_feature in fe_block/fe_block.module
Implements hook_features_enable_feature().
fe_block_boxes_features_rebuild in fe_block/fe_block.module
Implements hook_features_rebuild().

File

fe_block/fe_block.module, line 821
Provide features components for exporting core blocks and settings.

Code

function fe_block_boxes_features_revert($module_name = NULL) {
  $defaults = features_get_default('fe_block_boxes', $module_name);
  if (empty($defaults)) {
    return;
  }

  // Revert.
  foreach ($defaults as $object) {
    if (empty($object->machine_name)) {
      continue;
    }
    $bid = fe_block_get_bid($object->machine_name);
    if (empty($bid) || !block_custom_block_get($bid)) {
      $result = _fe_block_save_box((array) $object);
      if (!empty($result['bid'])) {
        $or = db_or()
          ->condition('bid', $result['bid'])
          ->condition('machine_name', $object->machine_name);
        db_delete('fe_block_boxes')
          ->condition($or)
          ->execute();
        db_insert('fe_block_boxes')
          ->fields(array(
          'bid' => $result['bid'],
          'machine_name' => $object->machine_name,
        ))
          ->execute();
      }
    }
    else {
      $object->bid = $bid;
      $result = _fe_block_save_box((array) $object);
    }
  }

  // Clear block cache.
  cache_clear_all(NULL, 'cache_block');
  return TRUE;
}