So I took Roland's comment and tried to get it integrated into my code. For the tab management it worked well, but for portlet management it was a lot harder. Actually I only have a partial implementation finished. What's missing is the necessary logic to be able to move a portlet in the same tab from one column to another (there are 3 columns a portlet can be in for each tab). The thing that was most important to me was cleaning up the pruning operation. This took some trickery (aka hackery). I think its a better implementation but it does make me a bit nervous. Of course its all still very MySQL only.
Anyways so here goes the final query for moving a tab:
UPDATE user_tabs ut
JOIN user_tabs ut2
ON (ut.user_id = ut2.user_id
AND ut2.id = :id
AND ut2.pos != :pos
AND ut.pos >= LEAST(ut2.pos, :pos)
AND ut.pos …[Read more]