denny/ShinyCMS

View on GitHub
bin/database/data/insert-events-demo-data

Summary

Maintainability
Test Coverage
#!/usr/bin/env perl

# ===================================================================
# File:        bin/database/insert-events-demo-data
# Project:    ShinyCMS
# Purpose:    Use DBIC to insert demo data for events feature
# 
# Author:    Denny de la Haye <2019@denny.me>
# Copyright (c) 2009-2019 Denny de la Haye
# 
# ShinyCMS is free software; you can redistribute it and/or modify it
# under the terms of either the GPL 2.0 or the Artistic License 2.0
# ===================================================================

use strict;
use warnings;

# CPAN modules
use DateTime::Duration;

# Load local helper lib and get connected schema object
use FindBin qw( $Bin );
use lib "$Bin/../../lib";
require 'helpers.pl';  ## no critic

my $schema = get_schema();


# Make some dates and durations
my $now   = DateTime->now;
my $hour  = DateTime::Duration->new( hours  => 1 );
my $day   = DateTime::Duration->new( days   => 1 );
my $month = DateTime::Duration->new( months => 1 );

my $tomorrow    = $now + $day;
my $last_month1 = $now - $month;
my $last_month2 = $last_month1 + $hour;

my $xmas = DateTime->new(
    year  => $now->year,
    month => 12,
    day   => 25,
);


# Create some events
my $event1 = $schema->resultset( 'Event' )->find_or_create({
    name        => 'Old Demo/Test Event',
    url_name    => 'old-event',
    start_date  => $last_month1->strftime( '%Y-%m-%d %H:%M:%S' ),
    end_date    => $last_month2->strftime( '%Y-%m-%d %H:%M:%S' ),
    description => 'This is the first event, it is in the past.',
});
my $event2 = $schema->resultset( 'Event' )->find_or_create({
    name        => 'Current Event',
    url_name    => 'current',
    start_date  => $now->strftime( '%Y-%m-%d %H:%M:%S' ),
    end_date    => $tomorrow->strftime( '%Y-%m-%d %H:%M:%S' ),
    postcode    => 'EC1V 9AU',
    link        => 'http://shinycms.org/',
    description => 'This is the second demo/test event, it is happening today!',
});
my $event3 = $schema->resultset( 'Event' )->find_or_create({
    name        => 'Christmas',
    url_name    => 'xmas',
    start_date  => $xmas->strftime( '%Y-%m-%d %H:%M:%S' ),
    end_date    => $xmas->strftime( '%Y-%m-%d %H:%M:%S' ),
    description => 'Tis the season to be jolly, tra-la-la-la-la, la-la la la.',
});