Skip to content

Commit 7e8b534

Browse files
committed
Fix using internalcode for saving column in managers
1 parent abeedd9 commit 7e8b534

File tree

12 files changed

+58
-33
lines changed

12 files changed

+58
-33
lines changed

src/MAdmin/Job/Manager/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ protected function saveItem( \Aimeos\MAdmin\Job\Item\Iface $item, bool $fetch =
261261
$conn = $context->db( $this->getResourceName() );
262262

263263
$id = $item->getId();
264-
$columns = $this->object()->getSaveAttributes();
264+
$columns = $this->getSaveColumns();
265265

266266
if( $id === null )
267267
{
@@ -342,8 +342,8 @@ protected function saveItem( \Aimeos\MAdmin\Job\Item\Iface $item, bool $fetch =
342342
$idx = 1;
343343
$stmt = $this->getCachedStatement( $conn, $path, $sql );
344344

345-
foreach( $columns as $name => $entry ) {
346-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
345+
foreach( $columns as $entry ) {
346+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
347347
}
348348

349349
$stmt->bind( $idx++, $item->getLabel() );

src/MAdmin/Log/Manager/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ protected function saveItem( \Aimeos\MAdmin\Log\Item\Iface $item, bool $fetch =
435435
}
436436

437437
$id = $item->getId();
438-
$columns = $this->object()->getSaveAttributes();
438+
$columns = $this->getSaveColumns();
439439
$conn = $this->context()->db( $this->getResourceName(), true );
440440

441441
if( $id === null )
@@ -517,8 +517,8 @@ protected function saveItem( \Aimeos\MAdmin\Log\Item\Iface $item, bool $fetch =
517517
$idx = 1;
518518
$stmt = $this->getCachedStatement( $conn, $path, $sql );
519519

520-
foreach( $columns as $name => $entry ) {
521-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
520+
foreach( $columns as $entry ) {
521+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
522522
}
523523

524524

src/MShop/Basket/Manager/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function saveItem( \Aimeos\MShop\Basket\Item\Iface $item, bool $fetch
160160
$context = $this->context();
161161
$date = $context->datetime();
162162
$conn = $context->db( $this->getResourceName() );
163-
$columns = $this->object()->getSaveAttributes();
163+
$columns = $this->getSaveColumns();
164164

165165
/** mshop/basket/manager/insert/mysql
166166
* Inserts a new basket record into the database table or updates an existing one
@@ -193,8 +193,8 @@ protected function saveItem( \Aimeos\MShop\Basket\Item\Iface $item, bool $fetch
193193
$serialized = base64_encode( serialize( clone $item->getItem() ) );
194194
$idx = 1;
195195

196-
foreach( $columns as $name => $entry ) {
197-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
196+
foreach( $columns as $entry ) {
197+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
198198
}
199199

200200
// insert

src/MShop/Catalog/Manager/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ private function updateUsage( string $id, \Aimeos\MShop\Catalog\Item\Iface $item
10291029
$conn = $context->db( $this->getResourceName() );
10301030

10311031
$siteid = $context->locale()->getSiteId();
1032-
$columns = $this->object()->getSaveAttributes();
1032+
$columns = $this->getSaveColumns();
10331033

10341034
if( $case !== true )
10351035
{
@@ -1124,8 +1124,8 @@ private function updateUsage( string $id, \Aimeos\MShop\Catalog\Item\Iface $item
11241124
$stmt = $this->getCachedStatement( $conn, $path, $sql );
11251125
$idx = 1;
11261126

1127-
foreach( $columns as $name => $entry ) {
1128-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
1127+
foreach( $columns as $entry ) {
1128+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
11291129
}
11301130

11311131
$stmt->bind( $idx++, $item->getUrl() );

src/MShop/Common/Manager/DB.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,29 @@ protected function getResourceName() : string
626626
}
627627

628628

629+
/**
630+
* Returns the save attributes re-keyed by column name.
631+
*
632+
* If internalcode is set, its bare column name (without table alias/quotes)
633+
* is used as key. Otherwise the array key from getSaveAttributes() is used.
634+
*
635+
* @return \Aimeos\Base\Criteria\Attribute\Iface[] List of attribute items keyed by column name
636+
*/
637+
protected function getSaveColumns() : array
638+
{
639+
$columns = [];
640+
641+
foreach( $this->object()->getSaveAttributes() as $key => $entry )
642+
{
643+
$parts = explode( '.', (string) $entry->getInternalCode() );
644+
$col = trim( end( $parts ), '"' );
645+
$columns[$col] = $entry;
646+
}
647+
648+
return $columns;
649+
}
650+
651+
629652
/**
630653
* Returns the search attribute objects used for searching.
631654
*
@@ -910,7 +933,7 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
910933
$conn = $context->db( $this->getResourceName() );
911934

912935
$id = $item->getId();
913-
$columns = array_column( $this->object()->getSaveAttributes(), null, 'internalcode' );
936+
$columns = $this->getSaveColumns();
914937

915938
if( $id === null )
916939
{

src/MShop/Common/Manager/Methods.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ protected function createAttributes( array $list ) : array
361361
}
362362

363363

364+
365+
364366
/**
365367
* Returns the attribute helper functions for searching defined by the manager.
366368
*

src/MShop/Customer/Manager/Address/Standard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
152152
$conn = $context->db( $this->getResourceName() );
153153

154154
$id = $item->getId();
155-
$columns = array_column( $this->object()->getSaveAttributes(), null, 'internalcode' );
155+
$columns = $this->getSaveColumns();
156156

157157
if( $id === null )
158158
{
@@ -169,7 +169,7 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
169169
$values = $item->toArray( true );
170170
$stmt = $this->getCachedStatement( $conn, $path, $sql );
171171

172-
foreach( $this->object()->getSaveAttributes() as $name => $entry )
172+
foreach( $columns as $entry )
173173
{
174174
$value = $values[$entry->getCode()] ?? null;
175175
$value = $entry->getType() === 'json' ? json_encode( $value, JSON_FORCE_OBJECT ) : $value;

src/MShop/Customer/Manager/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ protected function saveItem( \Aimeos\MShop\Customer\Item\Iface $item, bool $fetc
277277

278278
$id = $item->getId();
279279
$billingAddress = $item->getPaymentAddress();
280-
$columns = $this->object()->getSaveAttributes();
280+
$columns = $this->getSaveColumns();
281281

282282
if( $id === null )
283283
{
@@ -358,8 +358,8 @@ protected function saveItem( \Aimeos\MShop\Customer\Item\Iface $item, bool $fetc
358358
$idx = 1;
359359
$stmt = $this->getCachedStatement( $conn, $path, $sql );
360360

361-
foreach( $columns as $name => $entry ) {
362-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
361+
foreach( $columns as $entry ) {
362+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
363363
}
364364

365365
$stmt->bind( $idx++, $item->getLabel() );

src/MShop/Locale/Manager/Currency/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
230230
$conn = $context->db( $this->getResourceName() );
231231

232232
$id = $item->getId();
233-
$columns = $this->object()->getSaveAttributes();
233+
$columns = $this->getSaveColumns();
234234

235235
if( $id === null )
236236
{
@@ -302,8 +302,8 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
302302
$idx = 1;
303303
$stmt = $this->getCachedStatement( $conn, $path, $sql );
304304

305-
foreach( $columns as $name => $entry ) {
306-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
305+
foreach( $columns as $entry ) {
306+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
307307
}
308308

309309
$stmt->bind( $idx++, $item->getLabel() );

src/MShop/Locale/Manager/Language/Standard.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
229229
$conn = $context->db( $this->getResourceName() );
230230

231231
$id = $item->getId();
232-
$columns = $this->object()->getSaveAttributes();
232+
$columns = $this->getSaveColumns();
233233

234234
if( $id === null )
235235
{
@@ -301,8 +301,8 @@ protected function saveBase( \Aimeos\MShop\Common\Item\Iface $item, bool $fetch
301301
$idx = 1;
302302
$stmt = $this->getCachedStatement( $conn, $path, $sql );
303303

304-
foreach( $columns as $name => $entry ) {
305-
$stmt->bind( $idx++, $item->get( $name ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
304+
foreach( $columns as $entry ) {
305+
$stmt->bind( $idx++, $item->get( $entry->getCode() ), \Aimeos\Base\Criteria\SQL::type( $entry->getType() ) );
306306
}
307307

308308
$stmt->bind( $idx++, $item->getLabel() );

0 commit comments

Comments
 (0)