New media items not being added if ->deleteListItems() is used beforehand.
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
New media items not being added if ->deleteListItems() is used beforehand.
Laravel framework version: 9.52.4
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
Why are the new list items not added if I use deleteListItems() on the old list items beforehand?
The goal is to clear old media list items of a specific type and then add them anew.
Aimeos Laravel version: ~2022.10
PHP Version: 8.2.4
Environment: Linux
Hello,
Why are the new list items not added if I use deleteListItems() on the old list items beforehand?
The goal is to clear old media list items of a specific type and then add them anew.
Code: Select all
$media_list_items = $product_item->getListItems( 'media', 'default', 'page', false );
$product_item->deleteListItems( $media_list_items, true ); // New media list items are not added if this method is used
if( isset( $book_info['pages'] ) && sizeof( $book_info['pages'] ) > 0 ) {
foreach( $book_info['pages'] as $page ) {
$parts = explode( "/", $page );
$label = end( $parts );
$media_item = $media_manager->create();
$media_item->setType('page');
$media_item->setDomain( 'product' );
$media_item->setUrl( $page );
$media_item->setPreview( $page );
$media_item->setMimeType( 'image/jpeg' );
$media_item->setLabel( $label );
$media_list_item = $product_manager->createListItem();
$product_item->addListItem( 'media', $media_list_item, $media_item );
}
}
Re: New media items not being added if ->deleteListItems() is used beforehand.
Are you sure that addListItem() is actually called?
If you remove all items first and add them again afterwards, it will be pretty slow due to the amount of changes in the database. In the Aimeos code base, list and domain items are reused as often as possible to minimize database changes and to speed up imports.
If you remove all items first and add them again afterwards, it will be pretty slow due to the amount of changes in the database. In the Aimeos code base, list and domain items are reused as often as possible to minimize database changes and to speed up imports.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: New media items not being added if ->deleteListItems() is used beforehand.
I'm pretty sure that addListItem() is called, because if I remove deleteListItems(), the items are added.
I think it's some kind of conflict, because items are marked for deletion before they are even added.
Removing all items and re-adding them with the updated ones (if there are changes) simplifies the process and the amount of code for me.
Otherwise I will have to go through every individual file and compare the file names or file sizes, etc.
Also I won't be using this all the time, so it shouldn't take too much resources.
I think it's some kind of conflict, because items are marked for deletion before they are even added.
Removing all items and re-adding them with the updated ones (if there are changes) simplifies the process and the amount of code for me.
Otherwise I will have to go through every individual file and compare the file names or file sizes, etc.
Also I won't be using this all the time, so it shouldn't take too much resources.
Re: New media items not being added if ->deleteListItems() is used beforehand.
Removing referenced items is done here:
https://github.com/aimeos/aimeos-core/b ... p#L97-L139
They are then returned here:
https://github.com/aimeos/aimeos-core/b ... #L153-L166
And finally deleted here:
https://github.com/aimeos/aimeos-core/b ... #L254-L274
Maybe your can find out now why you have that behavior.
https://github.com/aimeos/aimeos-core/b ... p#L97-L139
They are then returned here:
https://github.com/aimeos/aimeos-core/b ... #L153-L166
And finally deleted here:
https://github.com/aimeos/aimeos-core/b ... #L254-L274
Maybe your can find out now why you have that behavior.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star