Commit 296a549df0c02837907f36de114fac4ee6da320d
Committed by
Joenio Costa
1 parent
ee4ad041
Exists in
master
and in
21 other branches
improvements in core required for the newsletter plugin
* models should use acts_as_having_image transparently * force margin zero in HTML mailing * using require_dependency instead of require to avoid error: "superclass mismatch for class MailingJob" * now plugins can schedule jobs via whenever rubygem * improve 'sample-data' scripts to create some blog posts signed-off-by: Joenio Costa <joenio@colivre.coop.br>
Showing
6 changed files
with
38 additions
and
8 deletions
Show diff stats
app/mailers/mailing.rb
| 1 | -require 'mailing_job' | |
| 1 | +require_dependency 'mailing_job' | |
| 2 | 2 | |
| 3 | 3 | class Mailing < ActiveRecord::Base |
| 4 | 4 | |
| ... | ... | @@ -40,10 +40,8 @@ class Mailing < ActiveRecord::Base |
| 40 | 40 | begin |
| 41 | 41 | Mailing::Sender.notification(self, recipient.email).deliver |
| 42 | 42 | self.mailing_sents.create(:person => recipient) |
| 43 | - rescue Exception | |
| 44 | - # FIXME should not discard errors silently. An idea is to collect all | |
| 45 | - # errors and generate a task (notification) for the +source+ | |
| 46 | - # (environment/organization) listing these errors. | |
| 43 | + rescue Exception => ex | |
| 44 | + Rails.logger.error("#{ex.class.to_s} - #{ex.to_s} at #{__FILE__}:#{__LINE__}") | |
| 47 | 45 | end |
| 48 | 46 | end |
| 49 | 47 | end | ... | ... |
app/models/textile_article.rb
app/views/mailing/sender/notification.html.erb
config/schedule.rb
| ... | ... | @@ -28,3 +28,15 @@ end |
| 28 | 28 | every 30.days do |
| 29 | 29 | runner "ProfileSuggestion.generate_all_profile_suggestions" |
| 30 | 30 | end |
| 31 | + | |
| 32 | +# Loads "schedule.rb" files from plugins | |
| 33 | +# | |
| 34 | +# Allows Noosfero's plugins schedule jobs using `whenever` Ruby gem the same | |
| 35 | +# way we do here, just create the file "config/schedule.rb" into the plugin | |
| 36 | +# root directory and write jobs using the same syntax used here (see example in | |
| 37 | +# the `newsletter` plugin) | |
| 38 | + | |
| 39 | +Dir.glob("config/plugins/*/config/schedule.rb").each do |filename| | |
| 40 | + filecontent = IO.read(filename) | |
| 41 | + instance_eval(Whenever::NumericSeconds.process_string(filecontent), filename) | |
| 42 | +end | ... | ... |
lib/acts_as_having_image.rb
| ... | ... | @@ -5,6 +5,7 @@ module ActsAsHavingImage |
| 5 | 5 | belongs_to :image, dependent: :destroy |
| 6 | 6 | scope :with_image, :conditions => [ "#{table_name}.image_id IS NOT NULL" ] |
| 7 | 7 | scope :without_image, :conditions => [ "#{table_name}.image_id IS NULL" ] |
| 8 | + attr_accessible :image_builder | |
| 8 | 9 | self.send(:include, ActsAsHavingImage) |
| 9 | 10 | end |
| 10 | 11 | end |
| ... | ... | @@ -19,4 +20,4 @@ module ActsAsHavingImage |
| 19 | 20 | |
| 20 | 21 | end |
| 21 | 22 | |
| 22 | -ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods) | |
| 23 | 23 | \ No newline at end of file |
| 24 | +ActiveRecord::Base.extend(ActsAsHavingImage::ClassMethods) | ... | ... |
script/sample-articles
| ... | ... | @@ -65,3 +65,22 @@ for subject in EVENT_SUBJECTS |
| 65 | 65 | end |
| 66 | 66 | end |
| 67 | 67 | done |
| 68 | + | |
| 69 | +print "Creating some posts: " | |
| 70 | +for subject in SUBJECTS | |
| 71 | + rand(20).times do |i| | |
| 72 | + profile = profiles.sample | |
| 73 | + name = "%s #{subject}" % profile.name | |
| 74 | + article = TinyMceArticle.new( | |
| 75 | + :name => name, | |
| 76 | + :body => name, | |
| 77 | + :tag_list => [TAGS.sample, TAGS.sample], | |
| 78 | + :profile => profile, | |
| 79 | + :parent_id => profile.blog.id | |
| 80 | + ) | |
| 81 | + save article do | |
| 82 | + article.add_category categories.sample | |
| 83 | + end | |
| 84 | + end | |
| 85 | +end | |
| 86 | +done | ... | ... |