You are here

function scald_unregister_atom in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 scald.module \scald_unregister_atom()

Unregister a Scald Atom

Parameters

$sid: The Scald ID of the Atom being unregistered *OR* the Atom object.

Return value

boolean TRUE is the atom was successfully unregistered, FALSE otherwise

2 calls to scald_unregister_atom()
mee_field in mee/mee.module
Implementation of hook_field().
scald_composite_nodeapi in scald_composite/scald_composite.module
Implementation of hook_nodeapi().

File

./scald.module, line 1225

Code

function scald_unregister_atom($sid) {
  if (is_object($sid)) {
    $sid = $sid->sid;
  }

  // If we couldn't get back to the atom id  at this point, we won't be able to
  // unregister the atom, so let's just abort.
  if (!is_numeric($sid)) {
    return FALSE;
  }

  // Force a rebuild to ensure that the most-current instance is being used as
  //  when informing Providers of the impending destruction.
  $atom = scald_fetch($sid, TRUE);

  // If we couldn't fetch the object, abort early too, the atom has already been
  // unregistered.
  if (!is_object($atom)) {
    return FALSE;
  }
  $scald_config = variable_get('scald_config', 0);

  // @@@TODO: Figure out exactly what needs to be done in order to safely remove (or suppress the ability to retrieve) the Atom from the registry.
  db_query("UPDATE {scald_atoms} SET actions = 0 WHERE sid = %d", $sid);

  // Alert the Providers that this Atom is gone
  module_invoke($scald_config->types[$atom->type]['provider'], 'scald_unregister_atom', $atom, 'type');
  module_invoke($atom->provider, 'scald_unregister_atom', $atom, 'atom');
  foreach ($scald_config->relationships as $relationship) {
    module_invoke($relationship['provider'], 'scald_unregister_atom', $atom, 'relationship');
  }
  foreach ($scald_config->contexts as $context => $details) {
    if (isset($details['type_format'][$atom->type]) && ($transcoder = $details['type_format'][$atom->type]['transcoder'])) {
      module_invoke($scald_config->transcoders[$transcoder]['provider'], 'scald_unregister_atom', $atom, 'transcoder');
    }
  }

  // Clear the memory cache
  scald_is_registered($sid, TRUE);

  // Clear the render cache
  cache_clear_all($sid . ':', 'cache_scald', TRUE);
}