You are here

function features_semaphore in Features 7.2

Same name and namespace in other branches
  1. 6 features.export.inc \features_semaphore()
  2. 7 features.export.inc \features_semaphore()

Gets, sets or deletes a semaphore for a given component.

Parameters

string $op: One of 'get', 'set' or 'del'.

string $component: A component name, e.g. 'field_instance'.

Return value

int|false|void If $op is 'get', the semaphore, or FALSE if none found for the component. If $op is 'set' or 'del', nothing is returned.

2 calls to features_semaphore()
features_get_component_states in ./features.export.inc
Retrieve an array of features/components and their current states.
_features_restore in ./features.module
Restore the specified modules to the default state.
1 string reference to 'features_semaphore'
features_uninstall in ./features.install
Implements hook_uninstall().

File

./features.export.inc, line 1073
Contains functions that export configuration into feature modules.

Code

function features_semaphore($op, $component) {

  // Note: we don't use variable_get() here as the inited variable
  // static cache may be stale. Retrieving directly from the DB narrows
  // the possibility of collision.
  $semaphore = db_query("SELECT value FROM {variable} WHERE name = :name", array(
    ':name' => 'features_semaphore',
  ))
    ->fetchField();
  $semaphore = !empty($semaphore) ? unserialize($semaphore) : array();
  switch ($op) {
    case 'get':
      return isset($semaphore[$component]) ? $semaphore[$component] : FALSE;
    case 'set':
      $semaphore[$component] = REQUEST_TIME;
      variable_set('features_semaphore', $semaphore);
      break;
    case 'del':
      if (isset($semaphore[$component])) {
        unset($semaphore[$component]);
        variable_set('features_semaphore', $semaphore);
      }
      break;
  }
}