|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +class EventDuplicator |
| 4 | + def initialize(event, submitter = nil) |
| 5 | + @event = event |
| 6 | + @submitter = submitter |
| 7 | + end |
| 8 | + |
| 9 | + def duplicate(count = 1) |
| 10 | + duplicated_events = [] |
| 11 | + @event.class.transaction do |
| 12 | + count.times do |
| 13 | + duplicated_events << create_duplicate |
| 14 | + end |
| 15 | + end |
| 16 | + duplicated_events |
| 17 | + end |
| 18 | + |
| 19 | + private |
| 20 | + |
| 21 | + def create_duplicate |
| 22 | + duplicate_event = Event.create!( |
| 23 | + # Content fields |
| 24 | + title: @event.title, |
| 25 | + subtitle: @event.subtitle, |
| 26 | + abstract: @event.abstract, |
| 27 | + description: @event.description, |
| 28 | + submission_text: @event.submission_text, |
| 29 | + committee_review: @event.committee_review, |
| 30 | + proposal_additional_speakers: @event.proposal_additional_speakers, |
| 31 | + event_type: @event.event_type, |
| 32 | + track: @event.track, |
| 33 | + difficulty_level: @event.difficulty_level, |
| 34 | + language: @event.language, |
| 35 | + presentation_mode: @event.presentation_mode, |
| 36 | + require_registration: @event.require_registration, |
| 37 | + max_attendees: @event.max_attendees, |
| 38 | + program: @event.program, |
| 39 | + state: 'new', |
| 40 | + progress: @event.progress, |
| 41 | + public: @event.public, |
| 42 | + is_highlight: @event.is_highlight, |
| 43 | + superevent: @event.superevent, |
| 44 | + |
| 45 | + # Don't copy: start_time, room_id, parent_id (reset to nil) |
| 46 | + start_time: nil, |
| 47 | + room_id: nil, |
| 48 | + parent_id: nil, |
| 49 | + |
| 50 | + # Submitter |
| 51 | + submitter: @submitter |
| 52 | + ) |
| 53 | + |
| 54 | + # Copy speakers and volunteers |
| 55 | + duplicate_event.speakers = @event.speakers |
| 56 | + duplicate_event.volunteers = @event.volunteers |
| 57 | + duplicate_event.save! |
| 58 | + |
| 59 | + duplicate_event |
| 60 | + end |
| 61 | +end |
0 commit comments