You are here

public function backup_migrate_item::unique_id in Backup and Migrate 7.3

Same name and namespace in other branches
  1. 8.3 includes/crud.inc \backup_migrate_item::unique_id()
  2. 6.3 includes/crud.inc \backup_migrate_item::unique_id()

Make sure this item has a unique id.

Should only be called for new items or the item will collide with itself.

1 call to backup_migrate_item::unique_id()
backup_migrate_item::save in includes/crud.inc
Save the item to the database.

File

includes/crud.inc, line 635
CRUD functions for backup and migrate types (schedules, profiles etc.).

Class

backup_migrate_item
A base class for items which can be stored in the database.

Code

public function unique_id() {
  $id = $this
    ->get_id();

  // Unset the autoincrement field so it can be regenerated.
  foreach ((array) $this
    ->get_primary_key() as $key) {
    $this->{$key} = NULL;
  }

  // If the item doesn't have an ID or if it's id is already taken, generate
  // random one.
  if (!$id || $this
    ->item($id)) {
    $this
      ->set_id($this
      ->generate_id());
  }
}