diff --git a/src/Entity/Customer.php b/src/Entity/Customer.php index 4af84d96..23a49082 100644 --- a/src/Entity/Customer.php +++ b/src/Entity/Customer.php @@ -222,6 +222,12 @@ class Customer */ protected $car_club_customer_hub; + // random generated unique id + /** + * @ORM\Column(type="string", length=40, nullable=true) + */ + protected $generated_id; + public function __construct() { $this->numbers = new ArrayCollection(); @@ -259,6 +265,8 @@ class Customer $this->date_create = new DateTime(); $this->create_source = 'unknown'; + + $this->generated_id = ''; } public function getID() @@ -674,4 +682,5 @@ class Customer { return $this->car_club_customer_hub; } + } diff --git a/src/Service/UniqueIdGenerator.php b/src/Service/UniqueIdGenerator.php index c0a91d0c..7822e045 100644 --- a/src/Service/UniqueIdGenerator.php +++ b/src/Service/UniqueIdGenerator.php @@ -13,10 +13,28 @@ class UniqueIdGenerator $this->em = $em; } - public function generateUniqueId($str_length) + public function generateCustomerUniqueId($str_length) { - // TODO: retry until we get a unique id + // retry until we get a unique id + while (true) + { + try + { + } + catch (DBALException $e) + { + error_log($e->getMessage()); + // delay one second and try again + sleep(1); + continue; + } + break; + } + } + + protected function generateUniqueId($str_length) + { return substr(md5(time()), 0, $str_length); } }