2

Knowing I want Magento assemble and execute the following query :

UPDATE
    `catalog_product_entity_media_gallery_value` AS `tGV`
INNER JOIN `catalog_product_entity_media_gallery` AS `tG` ON
    `tG` . value_id = value_id
SET
    `tGV` . `position` = 2
WHERE
    (
        `tG` . `value` LIKE '%_pms_%'
    )

I came to the following code :

$select = $connection
    ->select()
    ->join(
        ['tG' => $tableGallery],
        '`tG`.`value_id` = `tGV`.`value_id`',
        ['position' => new Expr('2')]
    )
    ->where("`tG`.`value` LIKE '%_pms_master%'");

$update = $connection->updateFromSelect($select, ['tGV' => $tableGalleryValue]);

$connection->query($update);

This code works but it is not obvious to understand and therefore to maintain. Question is : do you have any idea how to do better : simpler / cleaner / more understandable ?

1
  • $update is a string that is the SQL statement. I would just echo $update and copy the output as comment. – kiatng Jan 16 '18 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.