Index: branches/RC/core/install/upgrades.php =================================================================== diff -u -N -r11705 -r11857 --- branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11705) +++ branches/RC/core/install/upgrades.php (.../upgrades.php) (revision 11857) @@ -683,6 +683,7 @@ if ($mode == 'after') { $this->_fixSkinColors(); $this->_restructureCatalog(); + $this->_sortImages(); // $this->_sortConfigurationVariables('In-Portal', 'in-portal:configure_general'); // $this->_sortConfigurationVariables('In-Portal', 'in-portal:configure_advanced'); @@ -1098,4 +1099,35 @@ } } + /** + * Sort images in database (update Priority field) + * + */ + function _sortImages() + { + $sql = 'SELECT * + FROM ' . TABLE_PREFIX . 'Images + ORDER BY ResourceId ASC , DefaultImg DESC , ImageId ASC'; + $images = $this->Conn->Query($sql); + + $priority = 0; + $last_resource_id = false; + + foreach ($images as $image) { + if ($image['ResourceId'] != $last_resource_id) { + // each item have own priorities among it's images + $priority = 0; + $last_resource_id = $image['ResourceId']; + } + + if (!$image['DefaultImg']) { + $priority--; + } + + $sql = 'UPDATE ' . TABLE_PREFIX . 'Images + SET Priority = ' . $priority . ' + WHERE ImageId = ' . $image['ImageId']; + $this->Conn->Query($sql); + } + } } \ No newline at end of file