You are here

public function MigrateDestinationMenu::import in Migrate 7.2

Import a single row.

Parameters

$menu: Menu object to build. Prefilled with any fields mapped in the Migration.

$row: Raw source data object - passed through to prepare/complete handlers.

Return value

array Array of key fields of the object that was saved if successful. FALSE on failure.

Overrides MigrateDestination::import

File

plugins/destinations/menu.inc, line 65
Support for menu destinations.

Class

MigrateDestinationMenu
Destination class implementing migration into {menu_custom}.

Code

public function import(stdClass $menu, stdClass $row) {

  // Invoke migration prepare handlers
  $this
    ->prepare($menu, $row);

  // Menus are handled as arrays, so clone the object to an array.
  $menu = clone $menu;
  $menu = (array) $menu;

  // Check to see if this is a new menu.
  $update = FALSE;
  if ($data = menu_load($menu['menu_name'])) {
    $update = TRUE;
  }

  // menu_save() provides no return callback, so we can't really test this
  // without running a menu_load() check.
  migrate_instrument_start('menu_save');
  menu_save($menu);
  migrate_instrument_stop('menu_save');

  // Return the new id or FALSE on failure.
  if ($data = menu_load($menu['menu_name'])) {

    // Increment the count if the save succeeded.
    if ($update) {
      $this->numUpdated++;
    }
    else {
      $this->numCreated++;
    }

    // Return the primary key to the mapping table.
    $return = array(
      $data['menu_name'],
    );
  }
  else {
    $return = FALSE;
  }

  // Invoke migration complete handlers.
  $menu = (object) $data;
  $this
    ->complete($menu, $row);
  return $return;
}