You are here

function tft_archive_restore_archived_element in Taxonomy File Tree 7.2

Restore the element to its previous position.

If the previous place does not exist anymore, will be restored to the root (or any other place, specified by a third-party module).

Parameters

int $id:

string $type: The type of entity. Either 'term' or 'node'.

Return value

int

1 call to tft_archive_restore_archived_element()
tft_archive_restore_element in modules/tft_archive/includes/tft_archive.pages.inc
Page callback: restore element.

File

modules/tft_archive/tft_archive.module, line 282
Hook implementation and logic.

Code

function tft_archive_restore_archived_element($id, $type) {
  $log = db_query("SELECT * FROM {tft_archive_restore} WHERE type = :type AND id = :id", array(
    ':type' => $type,
    ':id' => $id,
  ))
    ->fetchAssoc();
  if (empty($log)) {
    $log = array(
      'id' => $id,
      'previous_parent_tid' => 0,
    );
  }
  drupal_alter('tft_archive_restore_element', $log, $id, $type);
  if ($type == 'node') {
    $node = node_load($log['id']);

    // @todo - currently supports only restoring to one single previous parent.
    $node->{"taxonomy_vocabulary_" . variable_get('tft_vocabulary_vid', 0)}[LANGUAGE_NONE][0]['tid'] = $log['previous_parent_tid'];
    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 $log['previous_parent_tid'];
}