Class | Update
In: | app/models/update.rb
Parent: | ActiveRecord::Base

Copyright (c) 2006 Logica

### Methods

after_create after_destroy do_update find_done find_inprogress find_todo first_update? validate

### Public Class methods

find_done()

[Source]

        # File app/models/update.rb, line 27
    27:   def self.find_done
    28:     Update.find(:all, :order => 'finished_on ASC', :conditions => ['finished_on is not null'])
    29:   end

find_inprogress()

[Source]

        # File app/models/update.rb, line 31
    31:   def self.find_inprogress
    32:     Update.find(:all, :order => 'finished_on ASC', :conditions => ['started_on is not null and finished_on is null'])
    33:   end

find_todo()

TODO validates_presence_of :user, :baseline_process, :wiki

[Source]

        # File app/models/update.rb, line 23
    23:   def self.find_todo
    24:     Update.find(:all, :order => 'created_on ASC', :conditions => ['started_on is null'])
    25:   end

### Public Instance methods

after_create()

[Source]

        # File app/models/update.rb, line 81
    81:   def after_create
    82:     if first_update?
    83:       Notifier::deliver_site_status(self, "SCHEDULED creation new Wiki #{self.wiki.title} using Baseline Process #{self.baseline_process.title}")
    84:     else
    85:       Notifier::deliver_site_status(self, "SCHEDULED update of Wiki #{self.wiki.title} with Baseline Process #{self.baseline_process.title}")
    86:     end
    87:   end

after_destroy()

[Source]

        # File app/models/update.rb, line 89
    89:   def after_destroy
    90:     Notifier::deliver_site_status(self, "CANCELLED update of Wiki #{self.wiki.title} with Baseline Process #{self.baseline_process.title}")
    91:   end

do_update()

[Source]

        # File app/models/update.rb, line 35
    35:   def do_update
    36:     logger.info("Doing update of #{self.wiki.title} with #{self.baseline_process.title}")
    37:     if self.first_update?
    38:       Notifier::deliver_site_status(self, "STARTED creating New Wiki #{self.wiki.title} using Baseline Process #{self.baseline_process.title}")
    39:       self.wiki.wikify(self)
    40:       Notifier::deliver_site_status(self, "FINISHED creating new Wiki #{self.wiki.title} using Baseline Process #{self.baseline_process.title}")
    41:     else
    42:       Notifier::deliver_site_status(self, "STARTED update of Wiki #{self.wiki.title} with Baseline Process #{self.baseline_process.title}")
    43:       self.wiki.update_wiki(self)
    44:       Notifier::deliver_site_status(self, "FINISHED update of Wiki #{self.wiki.title} with Baseline Process #{self.baseline_process.title}")
    45:     end
    46:     self.finished_on = Time.now
    47:     self.save!
    48:     users = User.find(:all, :conditions => ['notify_immediate=?', 1])
    49:     unless users.empty?
    50:         subject = "Wiki #{self.wiki.title} Updated with Baseline Process #{self.baseline_process.title}"
    51:         introduction = "User #{self.user.name} updated Wiki <a href=\"http://#{self.wiki.url(true)}\">#{self.wiki.title}</a> with Baseline Process #{self.baseline_process.title}."
    52:         Notifier::deliver_notification(users,subject,introduction, nil)
    53:     end
    54:
    55:     expire_all_pages
    56:
    57:     # Notify contributors of harvested stuff
    58:     contributions = Upload.find(:all, :conditions => ['done=? and review_note_send_on is null', 'Y']) +
    59:       Comment.find(:all, :conditions => ['done=? and review_note_send_on is null and site_id=?', 'Y', self.wiki.id]) +
    60:       UserVersion.find(:all, :conditions => ['done=? and review_note_send_on is null and wiki_id=?', 'Y', self.wiki.id])
    61:     contributions.collect{|rec|rec.user}.uniq.each do |u |
    62:       Notifier::deliver_contributions_processed(u, contributions.collect{|rec|rec if rec.user == u}.compact)
    63:     end
    64:
    65:    contributions.each do |record|
    66:       record.review_note_send_on = Time.now
    67:       record.save!
    68:     end
    69:   end

first_update?()

[Source]

        # File app/models/update.rb, line 72
    72:   def first_update?
    73:     self.wiki.updates_done.empty? && wiki.updates_inprogress.empty?
    74:   end

validate()

[Source]

        # File app/models/update.rb, line 76
    76:   def validate
    77:     errors.add(:baseline_process, 'is not a BaselineProcess') if !self.baseline_process_id.nil? && Site.find(baseline_process_id).wiki?
    78:     errors.add(:wiki, 'is not a Wiki') if !self.wiki_id.nil? && Site.find(wiki_id).baseline_process?
    79:   end

[Validate]