You are here

public function MigratePathEntityHandler::complete in Migrate 7.2

File

plugins/destinations/path.inc, line 43
Support for paths in core Drupal objects

Class

MigratePathEntityHandler
@file Support for paths in core Drupal objects

Code

public function complete($entity, stdClass $row) {

  // Check if this is a forum taxonomy term.
  if (module_exists('forum')) {
    if (isset($entity->vocabulary_machine_name) && $entity->vocabulary_machine_name == 'forums') {

      // Check if a path ID exists for this term.
      $term_pid = db_select('url_alias', 'url_alias')
        ->fields('url_alias', array(
        'pid',
      ))
        ->condition('source', 'taxonomy/term/' . $entity->tid)
        ->condition('language', $entity->language)
        ->execute()
        ->fetchField();

      // Check if there is also a path ID for this term referencing forums.
      $forum_term_pid = db_select('url_alias', 'url_alias')
        ->fields('url_alias', array(
        'pid',
      ))
        ->condition('source', 'forum/' . $entity->tid)
        ->condition('language', $entity->language)
        ->execute()
        ->fetchField();

      // If both term and forum term path IDs exist, delete the term's path.
      if ($term_pid && $forum_term_pid) {
        db_delete('url_alias')
          ->condition('pid', $term_pid)
          ->execute();
      }
      elseif ($term_pid && empty($forum_term_pid)) {
        db_update('url_alias')
          ->fields(array(
          'source' => 'forum/' . $entity->tid,
        ))
          ->condition('pid', $term_pid)
          ->execute();
      }
    }
  }
}