public function update_column_uuid() { $this->module->model->assert_not_has_column('uuid')->create_column('uuid'); # # Update records with UUID values. # $target = $this->module->model->target; $tokens = $target->select('nid, NULL')->pairs; foreach (array_keys($tokens) as $nid) { for (;;) { $token = \ICanBoogie\generate_v4_uuid(); if (!in_array($token, $tokens)) { break; } } $tokens[$nid] = $token; } $update = $target->prepare("UPDATE `{self}` SET `uuid` = ? WHERE `nid` = ?"); foreach ($tokens as $nid => $token) { $update($token, $nid); } # # Create index. # $this->module->model->create_unique_index('uuid'); }
/** * Returns a UUID. * * @return string */ public function obtain_uuid() { for (;;) { $uuid = \ICanBoogie\generate_v4_uuid(); if (!$this->filter_by_uuid($uuid)->exists) { return $uuid; } } }