[-] BO : Fixed bug PSCFV-9910 using basic queries to prevent locking errors

This commit is contained in:
Fabio Chelly committed 2013-10-25 17:01:28 +02:00
1 parent b9de912dd3
commit a7d0794c43
1 file changed
+31 -10
+31 -10
View File
@@ -312,16 +312,37 @@ class FeatureCore extends ObjectModel
*/ */
public static function cleanPositions() public static function cleanPositions()
{ {
return Db::getInstance()->execute(' //Reordering positions to remove "holes" in them (after delete for instance)
UPDATE `'._DB_PREFIX_.'feature` f $sql = "SELECT id_feature, position FROM "._DB_PREFIX_."feature ORDER BY id_feature";
LEFT JOIN ( $db = Db::getInstance();
SELECT @i := @i +1 AS rank, id_feature, position $r = $db->executeS($sql, false);
FROM `'._DB_PREFIX_.'feature` $shiftTable = array(); //List of update queries (one query is necessary for each "hole" in the table)
JOIN (SELECT @i :=1) dummy $currentDelta = 0;
ORDER by position $minId = 0;
) AS f2 $maxId = 0;
USING (id_feature) $futurePosition = 1;
SET f.position = f2.rank - 1'); while ($line = $db->nextRow($r)) {
$delta = $futurePosition - $line['position']; //Difference between current position and future position
if ($delta != $currentDelta) {
$shiftTable[] = array('minId' => $minId, 'maxId' => $maxId, 'delta' => $currentDelta);
$currentDelta = $delta;
$minId = $line['id_feature'];
}
$maxId = $line['id_feature'];
$futurePosition++;
}
$shiftTable[] = array('minId' => $minId, 'maxId' => $maxId, 'delta' => $currentDelta);
//Executing generated queries
foreach ($shiftTable as $line) {
$delta = $line['delta'];
if ($delta == 0) continue;
$delta = $delta > 0 ? '+' . (int)$delta : (int)$delta;
$minId = (int)$line['minId'];
$maxId = (int)$line['maxId'];
$sql = "UPDATE "._DB_PREFIX_."feature SET position = position $delta WHERE id_feature >= $minId AND id_feature <= $maxId";
Db::getInstance()->execute($sql);
}
} }
/** /**