public function backup_migrate_item::generate_id in Backup and Migrate 7.3
Same name and namespace in other branches
- 8.2 includes/crud.inc \backup_migrate_item::generate_id()
- 8.3 includes/crud.inc \backup_migrate_item::generate_id()
- 6.3 includes/crud.inc \backup_migrate_item::generate_id()
- 6.2 includes/crud.inc \backup_migrate_item::generate_id()
- 7.2 includes/crud.inc \backup_migrate_item::generate_id()
Return a random (very very likely unique) string id for a new item.
1 call to backup_migrate_item::generate_id()
- backup_migrate_item::unique_id in includes/
crud.inc - Make sure this item has a unique id.
File
- includes/
crud.inc, line 614 - 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 generate_id() {
$id = md5(uniqid(mt_rand(), TRUE));
// Find the shortest possible unique id from (min 4 chars).
for ($i = 4; $i < 32; $i++) {
$new_id = substr($id, 0, $i);
if (!$this
->item($new_id)) {
return $new_id;
}
}
// If we get here, then all 28 increasingly complex ids were already taken
// so we'll try again; this could theoretially lead to an infinite loop,
// but the odds are incredibly low.
return $this
->generate_id();
}