You are here

function tft_restore_archived_element in Taxonomy File Tree 7.2

Same name and namespace in other branches
  1. 7 tft.module \tft_restore_archived_element()

Parameters

$id:

$type:

$og_nid:

Return value

bool

Deprecated

Archives are OG specific

1 call to tft_restore_archived_element()
tft_restore_element in ./tft.module

File

./tft.module, line 1497
Hook implementations and module logic for TFT.

Code

function tft_restore_archived_element($id, $type, $og_nid) {
  $log = db_query("SELECT * FROM {tft_archive_restore} WHERE type = :type AND id = :id", array(
    ':type' => $type,
    ':id' => $id,
  ))
    ->fetchAssoc();
  $og_tid = tft_get_og_tid($og_nid);
  $return = TRUE;
  if (empty($log)) {
    $return = FALSE;
    $log = array(
      'id' => $id,
      'previous_parent_tid' => $og_tid,
    );
  }
  elseif (!db_query("SELECT COUNT(*) FROM {taxonomy_term_data} WHERE tid = :tid", array(
    ':tid' => $log['previous_parent_tid'],
  ))
    ->fetchField()) {
    $return = FALSE;
    $log['previous_parent_tid'] = $og_tid;
  }
  else {
    if (tft_is_term_archived($log['previous_parent_tid'])) {
      $return = FALSE;
      $log['previous_parent_tid'] = $og_tid;
    }
  }
  if ($type == 'node') {
    $archive_tid = tft_get_archive_tid($og_tid);
    $node = node_load($log['id']);

    // Get original folder.
    // Reconstruct list of terms by removing all folder terms.
    $taxonomy = array();
    foreach ($node->taxonomy as $term) {
      if ($term->tid != $archive_tid) {
        $taxonomy[] = $term->tid;
      }
    }
    $taxonomy[] = $log['previous_parent_tid'];
    $node->taxonomy = $taxonomy;
    node_save($node);
  }
  else {
    db_update('taxonomy_term_hierarchy')
      ->fields(array(
      'parent' => $log['previous_parent_tid'],
    ))
      ->condition('tid', $log['id'])
      ->execute();
  }
  db_delete('tft_archive_restore')
    ->condition('id', $id)
    ->condition('type', $type)
    ->execute();
  return $return;
}