Skip to content

Commit

Permalink
Fix to make restoring change files to local and resave everything nec…
Browse files Browse the repository at this point in the history
…essary
  • Loading branch information
cykod committed Aug 8, 2011
1 parent 741b967 commit 1d72837
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 6 additions & 4 deletions app/models/page_revision.rb
Expand Up @@ -209,10 +209,12 @@ def make_real()
container = self.revision_container

PageRevision.transaction do
real_rev = container.page_revisions.find(:all,:conditions => [ 'revision_type="real" AND revision=? AND language=? AND id != ?', self.revision,self.language,self.id] )
real_rev.each do |rev|
rev.update_attributes(:revision_type => 'old' )
DomainFileInstance.clear_targets('PageParagraph',rev.page_paragraph_ids)
real_rev = container.page_revisions.find(:all,:conditions => [ 'revision_type="real" AND revision=? AND language=? AND id != ?', self.revision,self.language,self.id] ) if container
if real_rev
real_rev.each do |rev|
rev.update_attributes(:revision_type => 'old' )
DomainFileInstance.clear_targets('PageParagraph',rev.page_paragraph_ids)
end
end
self.update_attributes( :created_at => Time.now,
:revision_type => 'real')
Expand Down
12 changes: 10 additions & 2 deletions lib/tasks/restore.rake
Expand Up @@ -92,6 +92,10 @@ namespace "cms" do
# Delete any rendered parts
DomainModel.connection.execute("DELETE FROM site_template_rendered_parts WHERE 1")


# Changed to local file storage
DomainFile.update_all("processor='local'","file_type != 'fld' AND processor != 'local'")

begin
# Resave update any file store
DomainFileInstance.rebuild_all
Expand Down Expand Up @@ -123,14 +127,18 @@ namespace "cms" do
DomainFile.update_all "server_hash = '#{server_hash}'", 'file_type != "fld" and server_hash IS NULL'
end

PageRevision.find(:all,:conditions => { :active => 1, :revision_type => 'real' }, :include => :page_paragraphs).each { |rev| rev.page_paragraphs.map(&:save); rev.make_real }

# Clear out the cache for the domain

begin
SiteTemplate.find(:all).map(&:save)
SiteFeature.find(:all).map(&:save)
SiteTemplate.find(:all).map(&:save)
rescue Exception => e
puts("There was a problem resaving site templates and features - continuing import anyway")
end

# Clear out the cache for the domain
# Resave paragraphs to fix links
DataCache.expire_domain(dmn.database)

# Make the database active again
Expand Down

0 comments on commit 1d72837

Please sign in to comment.