Created
June 8, 2015 14:13
-
-
Save nfriend21/a377f0e6790e0c33b65f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SiteManager::PagesController < ApplicationController | |
end | |
def sort_children(element,dbitem) | |
+ tries = 3 | |
prevchild = nil | |
element['children'].each do |child| | |
- childitem = Page.find(child['id']) | |
- prevchild.nil? ? childitem.move_to_child_of(dbitem) : childitem.move_to_right_of(prevchild) | |
- sort_children(child, childitem) unless child['children'].nil? | |
- prevchild = childitem | |
- childitem.touch | |
+ begin | |
+ self.transaction do | |
+ childitem = Page.find(child['id']) | |
+ prevchild.nil? ? childitem.move_to_child_of(dbitem) : childitem.move_to_right_of(prevchild) | |
+ sort_children(child, childitem) unless child['children'].nil? | |
+ prevchild = childitem | |
+ childitem.touch | |
+ end | |
+ rescue ActiveRecord::StatementInvalid => e | |
+ tries -= 1 | |
+ if retries > 0 | |
+ logger.error "Error sorting Pages in SiteManager. Retry #{3-tries}" | |
+ sleep 0.2 | |
+ retry | |
+ else | |
+ raise e | |
+ end | |
+ end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment