Bugfix copy article with properties constraint error

This commit is contained in:
OpenXE 2024-11-28 18:42:11 +01:00
parent a93dd971eb
commit eef6eedb0b
2 changed files with 15 additions and 5 deletions

View File

@ -104,8 +104,7 @@ class ArticleService
$aeigenschaften = $this->app->DB->SelectArr("SELECT id FROM artikeleigenschaftenwerte WHERE artikel = '$id'");
if($aeigenschaften){
foreach($aeigenschaften as $eigenschaft){
$neue_eigenschaft = $this->app->DB->MysqlCopyRow("artikeleigenschaftenwerte", "id", $eigenschaft['id']);
$this->app->DB->Update("UPDATE artikeleigenschaftenwerte SET artikel = '$idnew' WHERE id = '$neue_eigenschaft' LIMIT 1");
$this->app->DB->MysqlCopyRow("artikeleigenschaftenwerte", "id", $eigenschaft['id'], Array('artikel' => $idnew));
}
}
}
@ -129,4 +128,4 @@ class ArticleService
return $idnew;
}
}
}

View File

@ -1417,10 +1417,11 @@ class DB{
* @param string $TableName
* @param string $IDFieldName
* @param int $IDToDuplicate
* replace array('field' => 'value')
*
* @return int|null
*/
public function MysqlCopyRow($TableName, $IDFieldName, $IDToDuplicate)
public function MysqlCopyRow($TableName, $IDFieldName, $IDToDuplicate, $replace = Array())
{
if(empty($TableName) || empty($IDFieldName) || empty($IDToDuplicate)) {
return null;
@ -1452,7 +1453,17 @@ class DB{
$comma = "";
foreach ($fields as $field => $value) {
if ($field != $IDFieldName) {
$sql .= $comma."`".$field."`";
$replaced = false;
foreach ($replace as $rkey => $rvalue) {
if ($field == $rkey) {
$sql .= $comma."'".$rvalue."' AS `".$rkey."`";
$replaced = true;
break;
}
}
if (!$replaced) {
$sql .= $comma."`".$field."`";
}
} else {
$sql .= "NULL";
}