Commit d8593ccbf881f51b7a19e97b8d83ccbc627ff325
- Diff rendering mode:
- inline
- side by side
app/models/source.rb
(12 / 1)
|   | |||
| 45 | 45 | end | |
| 46 | 46 | old_source_importation.touch | |
| 47 | 47 | else | |
| 48 | link = entry.links.select{ |l| l['rel'] = 'alternate' }.first.try(:href) | ||
| 49 | uri = link.present? ? Uri.find_or_create_by_uri(link) : nil | ||
| 50 | |||
| 48 | 51 | # Create new Importation | |
| 49 | 52 | source_importations.create :importation => importation_class.new.from_atom!(entry), | |
| 50 | :guid => entry.id | ||
| 53 | :guid => entry.id, | ||
| 54 | :uri => uri | ||
| 51 | 55 | end | |
| 52 | 56 | end | |
| 53 | 57 | ||
| 54 | 58 | update_attribute :imported_at, Time.now | |
| 55 | 59 | end | |
| 60 | |||
| 61 | # Destroy all importations and reset imported_at | ||
| 62 | def reset | ||
| 63 | source_importations.destroy_all | ||
| 64 | update_attribute :imported_at, nil | ||
| 65 | end | ||
| 66 | |||
| 56 | 67 | ||
| 57 | 68 | protected | |
| 58 | 69 |
|   | |||
| 1 | 1 | class SourceImportation < ActiveRecord::Base | |
| 2 | 2 | belongs_to :source | |
| 3 | 3 | belongs_to :importation, :polymorphic => true, :dependent => :destroy | |
| 4 | belongs_to :uri | ||
| 4 | 5 | end |
db/migrate/station_2_to_3.rb
(1 / 0)
|   | |||
| 18 | 18 | create_table :source_importations do |t| | |
| 19 | 19 | t.references :source | |
| 20 | 20 | t.references :importation, :polymorphic => true | |
| 21 | t.references :uri | ||
| 21 | 22 | t.string :guid | |
| 22 | 23 | t.timestamps | |
| 23 | 24 | end |
|   | |||
| 140 | 140 | create_table :source_importations do |t| | |
| 141 | 141 | t.references :source | |
| 142 | 142 | t.references :importation, :polymorphic => true | |
| 143 | t.references :uri | ||
| 143 | 144 | t.string :guid | |
| 144 | 145 | t.timestamps | |
| 145 | 146 | end |

