Skip to content

Commit

Permalink
merge origin/master
Browse files Browse the repository at this point in the history
  • Loading branch information
pdxmph committed Apr 30, 2015
2 parents e26e998 + 411b4e4 commit 53b6365
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
14 changes: 10 additions & 4 deletions app/controllers/pages_controller.rb
Expand Up @@ -4,7 +4,6 @@ class PagesController < ApplicationController

def destroy
@page = Page.find(params[:id])

begin
@page.comments.delete_all
@page.elements.delete_all
Expand All @@ -13,16 +12,15 @@ def destroy
redirect_to @page
end

if @page.delete
if @page.delete
respond_to do |format|
format.html { redirect_to project_version_path(:id => @page.version_id, :project_id => @page.version.project_id), alert: "Deleted the page #{@page.filename} from the database. Do you need to 301 Redirect it, too?"}
end
end

end



def tags
@tags = Page.tag_counts
end
Expand All @@ -45,8 +43,16 @@ def show
@page = Page.friendly.find(params[:id])
@user = current_user
@title = @page.title
rescue ActiveRecord::RecordNotFound
flash[:alert] = "Couldn't find this page. It may have been deleted by another user."
if request.env["HTTP_REFERER"]
redirect_to :back
else
redirect_to :projects
end
end


def highlight_page
@page = Page.friendly.find(params[:id])
end
Expand Down
3 changes: 2 additions & 1 deletion app/models/element.rb
@@ -1,5 +1,6 @@
class Element < ActiveRecord::Base
validates :page_id, uniqueness: {scope: :checksum}
validates :checksum, uniqueness: {scope: :page,
message: "Just one occurrence per page"}
belongs_to :page


Expand Down
14 changes: 9 additions & 5 deletions app/models/page.rb
Expand Up @@ -110,14 +110,17 @@ def content_reimport
rescue Exception => e
puts "something went wrong getting HTML for #{self.title} -- #{e}"
end

end

def element_purge
elements = self.elements
elements.delete_all
end

def element_import
self.elements.delete_all
elements = ["ol","pre","img", "ul"]
els = ["ol","pre","img", "ul"]
html = Nokogiri::HTML(content)
elements.each do |e|
els.each do |e|
html.xpath("//#{e}").each do |h|
if e == "img"
src_file = h['src']
Expand All @@ -128,6 +131,7 @@ def element_import
hash = Digest::MD5.hexdigest(h.to_html)
end
element = Element.new
element.page_id = self.id
element.checksum = hash
element.content = h.to_html
element_head = h.xpath("preceding::*[name()='h1' or name()='h2' or name()='h3' or name()='h4' or name()='h5']")
Expand All @@ -137,7 +141,7 @@ def element_import
else
element.nearest_heading = "#{self.title} (page title)"
end
element.page_id = self.id

element.filename = self.filename
element.kind = e
element.save
Expand Down
12 changes: 12 additions & 0 deletions scripts/dup_finder.rb
@@ -0,0 +1,12 @@
require 'find'

pages = Page.where(:private => true)

pages.each do |p|

others = Page.where("filename = ? AND id != ?",p.filename,p.id)
if others.size > 0
puts "duplicate found for #{p.filename}"
end
end

0 comments on commit 53b6365

Please sign in to comment.