| Class | Wiki |
| In: |
app/models/wiki.rb
|
| Parent: | Site |
| DEFAULT_CSS | = | 'css/default.css' | HTML Editors remove the nowrap attribute, so we add it to the CSS-file, see Wiki.enhance_files |
| contributors | [RW] | Used only for Notifier.report TODO a better solution |
# File app/models/wiki.rb, line 40
40: def status
41: logger.debug("Determining status of wiki #{self.title}")
42: s = 'Ready'
43: if self.updates.count == 0
44: logger.debug("Wiki #{self.title} does not have any update records")
45: s = 'Pending'
46: elsif self.updates_todo.count > 0
47: logger.debug("Wiki #{self.title} has #{self.updates_todo.count.to_s} updates to do")
48: s = 'Scheduled'
49: self.updates_todo.each do |u|
50: logger.debug("Update todo #{u.baseline_process.title} is started on #{u.started_on}")
51: s = 'UpdateInProgress' if !u.started_on.nil?
52: end
53: end
54: return s
55: end
# File app/models/wiki.rb, line 57
57: def top_contributors
58: arr = User.find(:all).collect {|u|[u, Version.count(:conditions => ['user_id = ? and baseline_process_id is null and wiki_id=?',u.id, self.id]) +
59: Comment.count(:conditions => ['user_id = ? and site_id=?',u.id, self.id]) +
60: Upload.count(:conditions => ['user_id = ?',u.id])]}
61: arr = arr.sort_by{|t|-t[1]}
62: end
# File app/models/wiki.rb, line 64
64: def top_monthly_contributors
65: arr = User.find(:all).collect {|u|[u, Version.count(:conditions => ['user_id = ? and baseline_process_id is null and wiki_id=?',u.id, self.id]) +
66: Comment.count(:conditions => ['user_id = ? and site_id=?',u.id, self.id]) +
67: Upload.count(:conditions => ['user_id = ?',u.id])]}
68: arr = arr.sort_by{|t|-t[1]}
69: end
Method update_wiki updates a Wiki with a BaselineProcess with the following steps:
TODO: notify users that want to be notified (add about notify_baseline_updates column to users) TODO: Change 68 - Update should continue with checkouts and should not overwrite not harvested changes
# File app/models/wiki.rb, line 113
113: def update_wiki(update)
114: update.update_attributes(:started_on => Time.now)
115: bp = update.baseline_process
116: logger.info("Starting update of wiki #{self.title} from baseline process #{self.baseline_process.title} (#{self.baseline_process.id}) to #{bp.title} (#{bp.id})")
117: logger.info("Copy update site " + bp.path + " to " + self.path)
118: cadmin = User.find_central_admin
119: # 1.
120: bp.copy_to(self, nil)
121:
122: # 2. Update status of EPFC pages to 'undetermined'
123: Page.update_all( "status = 'Undetermined'", ["tool = ? and site_id = ? ", 'EPFC', self.id, ])
124:
125: # 3. Update
126: bp.scan4content if bp.content_scanned_on.nil?
127: bp.pages.each do |p|
128: page = Page.find_by_site_id_and_rel_path(self.id, p.rel_path)
129: if page
130: page.status = 'Updated'
131: no = page.max_version_no + 1
132: else
133: page = WikiPage.new(:rel_path => p.rel_path, :site => self, :tool => 'EPFC', :status => 'New')
134: self.pages << page
135: no = 0
136: end
137: # create baseversion
138: baseversion = BaselineProcessVersion.new(:baseline_update => update,:user => cadmin, :page => page,
139: :wiki => self, :version => no, :done => 'Y', :note => 'Automatically created',
140: :baseline_process_id => bp.id)
141: page.baseline_process_versions << baseversion
142: page.save!
143: end
144:
145: # 4.
146: Page.find(:all, :conditions => ['site_id = ? and status = ?', self.id, 'Undetermined']).each do |p|
147: p.status = 'RemovedOrMoved'
148: p.save!
149: end
150:
151: # 5.
152: Page.find(:all, :conditions => ['site_id = ? and tool = ?', self.id, 'Wiki']).each do |p|
153: if p.harvested?
154: p.status = 'Harvested'
155: end
156: end
157:
158: # 6.
159: enhance_files
160:
161: # Change 68 - current versions not harvested
162: versions = UserVersion.find(:all, :conditions => ['wiki_id =? and done <> ? and version is not null', self.id, 'Y'])
163: logger.info("Found #{versions.size.to_s} versions with unharvested changes")
164: pages = versions.collect{|version| version.page}.uniq
165: if pages
166: logger.info("Found #{pages.size.to_s} pages with unharvested changes") if pages
167: snippets = Page.get_snippets
168: pages.each do |page|
169: logger.info("Processing page #{page.presentation_name}")
170: if page.checkout
171: logger.info("Page has unharvested versions, we don't need to set a current version")
172: else
173: cv = page.current_version
174: unless cv.nil?
175: if cv.current
176: logger.info("Page #{page.presentation_name} already has current version with id #{cv.id}, we don't need to set a current version")
177: else
178: logger.info("Page #{page.presentation_name} does not have a current version")
179: # set the current version equal to the last version that is not part of the update we are doing
180: page.current_version = Version.find(:first, :order => 'version DESC', :conditions => ['page_id=? and version is not null and update_id is null',page.id])
181: end
182: page.html = page.current_version.html
183: Page.enhance_file(page.path, snippets)
184: end
185: end
186: end
187: end
188: self.baseline_updated_on = Time.now
189: self.baseline_process = bp
190: self.save!
191: end
# File app/models/wiki.rb, line 193
193: def url(absolute = false, request_host = ENV['EPFWIKI_HOST'])
194: #--
195: # TODO anomaly, the following line shouldn't be necessary but is, in some cases.
196: # When this method is called from page.url request_host will be nil
197: #++
198: request_host = ENV['EPFWIKI_HOST'] if request_host.nil?
199:
200: logger.debug("url for site #{self.title}, absolute #{absolute.inspect}, request_host #{request_host.inspect}")
201: s = "/#{ENV['EPFWIKI_WIKIS_FOLDER']}/#{self.folder}/"
202: s = "http://#{request_host}#{s}" if absolute
203: logger.debug("returning: #{s}")
204: s
205: end
# File app/models/wiki.rb, line 217
217: def users
218: return User.find(:all, :conditions => ['exists (select * from versions vsn where vsn.wiki_id = ? and vsn.user_id = users.id and baseline_process_id is null) or exists (select * from da_texts cmt where cmt.user_id = users.id and cmt.site_id = ?) or exists (select * from uploads where uploads.user_id = ?)', id, id, id])
219: end
# File app/models/wiki.rb, line 207
207: def validate_on_create
208: logger.info("Folder #{ENV['EPFWIKI_WIKIS_PATH']}/#{self.folder} should not exists already")
209: errors.add(:folder, 'already exists') if (!self.folder.blank? && File.exists?("#{ENV['EPFWIKI_WIKIS_PATH']}/#{self.folder}")) || !Wiki.find_by_folder(self.folder).nil?
210: if self.title == 'Templates'
211: if Wiki.find(:first, :conditions => ['title = ?','Templates'])
212: errors.add(:title, ' "Templates" has been used. There can only be one Wiki with that name.')
213: end
214: end
215: end
Method wikify does the actual wikifying of the content. It is the second step of the two step process (the first step created the Wiki record and Update record).
NOTE: This method is typically not called directly but called via Update.wikify
# File app/models/wiki.rb, line 78
78: def wikify(update)
79: bp = update.baseline_process
80: logger.info("Updating Wiki #{self.title} with baseline process #{bp.title}")
81: raise 'The site was updated already or has a an update in progress!' if !update.first_update?
82: raise "Can only update with a baseline process (static site)" if bp.wiki?
83: update.update_attributes(:started_on => Time.now) # changes the wiki status to 'UpdateInProgress'
84: File.makedirs(self.path)
85: logger.info("Copying files from #{bp.path} to #{self.path}")
86: FileUtils.cp_r(bp.path + "/.", self.path) # How to copy the contents of a folder and not the folder [http://www.ruby-doc.org/core/classes/FileUtils.html#M001703]
87: bp.scan4content if !bp.content_scanned_on
88: cadmin = User.find_central_admin
89: bp.pages.each do |p|
90: newp = WikiPage.new(:rel_path => p.rel_path, :site => self, :tool => 'EPFC', :status => 'New')
91: self.pages << newp
92: # create baseversion
93: baseversion = BaselineProcessVersion.new(:baseline_update => update, :user => cadmin, :page => newp,
94: :wiki => self, :version => 0, :done => 'Y', :note => 'Automatically created',
95: :baseline_process_id => bp.id)
96: newp.baseline_process_versions << baseversion
97: end
98: enhance_files
99: self.baseline_process = bp
100: self.wikified_on = Time.now
101: self.save!
102: end