Don't create duplicate vendors. If there is a vendor with the same name as the one being
created retrieve the duplicate vendors information for the current object and return TRUE, even though we didn't really create new vendor we can handle this error situation more gracefully than returning false.
This commit is contained in:
committed by
WineHQ
parent
f7ae814cbb
commit
b32249dec6
@@ -60,9 +60,29 @@ class Vendor {
|
||||
|
||||
/**
|
||||
* Creates a new vendor.
|
||||
*
|
||||
* NOTE: If creating a vendor with the same name as an existing vendor
|
||||
* we retrieve the existing vendors information and return true,
|
||||
* even though we didn't create the vendor, this makes it easier
|
||||
* for the user of the vendor class.
|
||||
*/
|
||||
function create()
|
||||
{
|
||||
/* Check for duplicates */
|
||||
$hResult = query_parameters("SELECT * FROM vendor WHERE vendorName = '?'",
|
||||
$this->sName);
|
||||
if($hResult && $oRow = mysql_fetch_object($hResult))
|
||||
{
|
||||
if(mysql_num_rows($hResult))
|
||||
{
|
||||
$this->vendor($oRow->vendorId);
|
||||
|
||||
/* Even though we did not create a new vendor, the caller is provided
|
||||
with an id and can proceed as normal, so we return TRUE */
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
$hResult = query_parameters("INSERT INTO vendor (vendorName, vendorURL, queued) ".
|
||||
"VALUES ('?', '?', '?')",
|
||||
$this->sName, $this->sWebpage,
|
||||
|
||||
Reference in New Issue
Block a user