VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: balai on December 20, 2016, 13:45:22 PM

Title: Generation of duplicate aliases
Post by: balai on December 20, 2016, 13:45:22 PM
File: administrator/components/com_virtuemart/helpers/vmtable.php
function checkCreateUnique

This function is called to generate unique aliases when a record is saved.
For example before the product saving:
$productTable = $productModel->getTable ('products');
$productTable->checkCreateUnique('#__virtuemart_products_' . VmConfig::$vmlang,'slug');


Though inside the function there is a code that could potentially generate duplicate values.

            if($posNbr = strrpos($this->$name,'-')){
$existingNbr = substr($this->$name,$posNbr+1);

if(is_numeric($existingNbr)){
$existingNbr++;
if($i>10){
$existingNbr = $existingNbr +  rand (1, 9);
}
$this->$name = substr($this->$name,0,$posNbr+1) . $existingNbr;
} else{
$this->$name = $this->$name . '-1';
}
}


That code:
$existingNbr++;
if($i>10){
$existingNbr = $existingNbr +  rand (1, 9);
}


The unique key is based on the number returned by the rand (1, 9)
That means that the sum of these 2 numbers  $existingNbr +  rand (1, 9) can return the same value, more than once.
Title: Re: Generation of duplicate aliases
Post by: Studio 42 on December 20, 2016, 23:03:43 PM
For my batch tool, i don't use random. but increment each time and check if the name exist. It's  slower but safe.
The only problem you can have using this. Is if you have all products having same name, eg. if you name it all 'tool', but i think noone set more then 10 time same product name ?
I don't understand why this is used in VM, it's same for Joomla using the date(i think they removed date as alias in Joomla 3)
Title: Re: Generation of duplicate aliases
Post by: balai on January 05, 2017, 13:42:02 PM
Any update about that?
Is this going to be fixed in a next release?