Skip to content

Commit

Permalink
Save the item before updating the order of the children. Also always …
Browse files Browse the repository at this point in the history
…increment the weight count (even if it is equal to the weight of the current child)
  • Loading branch information
Tim Almdal committed May 18, 2010
1 parent 83ce637 commit 73c7ec5
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions modules/gallery/helpers/item_rest.php
Expand Up @@ -126,18 +126,19 @@ static function put($request) {
}
}
}
$item->save();

$weight = 0;
if (isset($request->params->members)) {
$weight = 0;
foreach ($request->params->members as $url) {
$child = rest::resolve($url);
if ($child->parent_id == $item->id && $child->weight != $weight) {
$child->weight = $weight++;
$child->weight = $weight;
$child->save();
}
$weight++;
}
}
$item->save();
}

static function post($request) {
Expand Down

1 comment on commit 73c7ec5

@talmdal
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The why...

It seemed to make sense to save the item so the window that changes are on the fly is smaller.
If the weights are equal, then you would never increment the weight value until the next item, so it was possible to create duplicate weights. Incrementing outside of the if allows the weight value always move forward.

Please sign in to comment.