Skip to content

Commit

Permalink
Make sure all links are deleted on node destruction.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jun 27, 2012
1 parent 9284888 commit fe6108d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 7 additions & 7 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def create_for_host(host, su_password, opts={})

unless admin_user.save
# rollback
Site.connection.execute "DELETE FROM #{Site.table_name} WHERE id = #{site.id}"
Site.connection.execute "DELETE FROM zips WHERE site_id = #{site.id}"
Zena::Db.execute "DELETE FROM #{Site.table_name} WHERE id = #{site.id}"
Zena::Db.execute "DELETE FROM zips WHERE site_id = #{site.id}"
raise Exception.new("Could not create admin user for site [#{host}] (site#{site[:id]})\n#{admin_user.errors.map{|k,v| "[#{k}] #{v}"}.join("\n")}")
end

Expand Down Expand Up @@ -349,7 +349,7 @@ def iformats
end

def iformats_updated!
Site.connection.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
Zena::Db.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
if $iformats
$iformats[self[:id]] = @iformats = nil
end
Expand All @@ -367,7 +367,7 @@ def virtual_classes
end

def iformats_updated!
Site.connection.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
Zena::Db.execute "UPDATE sites SET formats_updated_at = (SELECT updated_at FROM iformats WHERE site_id = #{self[:id]} ORDER BY iformats.updated_at DESC LIMIT 1) WHERE id = #{self[:id]}"
if $iformats
$iformats[self[:id]] = @iformats = nil
end
Expand All @@ -383,9 +383,9 @@ def clear_cache(clear_zafu = true)
FileUtils.rmtree(File.join(path, elem))
end

Site.connection.execute "DELETE FROM caches WHERE site_id = #{self[:id]}"
Site.connection.execute "DELETE FROM cached_pages_nodes WHERE cached_pages_nodes.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.site_id = #{self[:id]})"
Site.connection.execute "DELETE FROM cached_pages WHERE site_id = #{self[:id]}"
Zena::Db.execute "DELETE FROM caches WHERE site_id = #{self[:id]}"
Zena::Db.execute "DELETE FROM cached_pages_nodes WHERE cached_pages_nodes.node_id IN (SELECT nodes.id FROM nodes WHERE nodes.site_id = #{self[:id]})"
Zena::Db.execute "DELETE FROM cached_pages WHERE site_id = #{self[:id]}"
end

if clear_zafu
Expand Down
4 changes: 1 addition & 3 deletions lib/zena/use/relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ def update_relations

# Destroy all links related to this node
def destroy_links
Link.find(:all, :conditions => ["source_id = ? OR target_id = ?", self[:id], self[:id]]).each do |l|
l.destroy
end
Zena::Db.execute "DELETE FROM #{Link.table_name} WHERE source_id = #{self[:id].to_i} OR target_id = #{self[:id].to_i}"
end
end # ModelMethods
end # Relations
Expand Down

0 comments on commit fe6108d

Please sign in to comment.