From eef6eedb0b86bed3c74e1527bf05b672a924d110 Mon Sep 17 00:00:00 2001 From: OpenXE <> Date: Thu, 28 Nov 2024 18:42:11 +0100 Subject: [PATCH] Bugfix copy article with properties constraint error --- .../Modules/Article/Service/ArticleService.php | 5 ++--- phpwf/plugins/class.mysql.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/classes/Modules/Article/Service/ArticleService.php b/classes/Modules/Article/Service/ArticleService.php index 5e204c5a..7d124312 100644 --- a/classes/Modules/Article/Service/ArticleService.php +++ b/classes/Modules/Article/Service/ArticleService.php @@ -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; } -} \ No newline at end of file +} diff --git a/phpwf/plugins/class.mysql.php b/phpwf/plugins/class.mysql.php index d2047e03..083a04f6 100644 --- a/phpwf/plugins/class.mysql.php +++ b/phpwf/plugins/class.mysql.php @@ -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"; }