denny/ShinyCMS

View on GitHub
bin/database/data/insert-required-data

Summary

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

# ===================================================================
# File:        bin/database/insert-required-data
# Project:    ShinyCMS
# Purpose:    Insert basic required data via DBIC
# 
# 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;

# 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();


# Create the user roles
$schema->resultset( 'Role' )->find_or_create({ role => 'CMS Page Editor'           });
$schema->resultset( 'Role' )->find_or_create({ role => 'CMS Page Admin'            });
$schema->resultset( 'Role' )->find_or_create({ role => 'CMS Template Admin'        });
$schema->resultset( 'Role' )->find_or_create({ role => 'CMS Form Admin'            });
$schema->resultset( 'Role' )->find_or_create({ role => 'Shared Content Editor'     });
$schema->resultset( 'Role' )->find_or_create({ role => 'Shared Content Admin'      });
$schema->resultset( 'Role' )->find_or_create({ role => 'File Admin'                });
$schema->resultset( 'Role' )->find_or_create({ role => 'News Admin'                });
$schema->resultset( 'Role' )->find_or_create({ role => 'Blog Author'               });
$schema->resultset( 'Role' )->find_or_create({ role => 'Blog Admin'                });
$schema->resultset( 'Role' )->find_or_create({ role => 'Forums Admin'              });
$schema->resultset( 'Role' )->find_or_create({ role => 'Comment Moderator'         });
$schema->resultset( 'Role' )->find_or_create({ role => 'Discussion Admin'          });
$schema->resultset( 'Role' )->find_or_create({ role => 'Poll Admin'                });
$schema->resultset( 'Role' )->find_or_create({ role => 'Events Admin'              });
$schema->resultset( 'Role' )->find_or_create({ role => 'Shop Admin'                });
$schema->resultset( 'Role' )->find_or_create({ role => 'Newsletter Admin'          });
$schema->resultset( 'Role' )->find_or_create({ role => 'Newsletter Template Admin' });
$schema->resultset( 'Role' )->find_or_create({ role => 'Fileserver Admin'          });
$schema->resultset( 'Role' )->find_or_create({ role => 'User Admin'                });


# Create an admin user, give them full privileges
my $user1 = $schema->resultset( 'User' )->find_or_create({
    username     => 'admin',
    password     => 'changeme',
    email        => 'changeme@example.com',
    firstname    => 'Default',
    surname      => 'Admin',
    display_name => 'Admin',
    admin_notes  => 'This is the default admin user account.  Please either '.
                    'remove it before putting your site online, or at least '.
                    'make sure that you change the password - and preferably, '.
                    'change the username too!',
});
my @roles = $schema->resultset( 'Role' )->all;
foreach my $role ( @roles ) {
    $user1->user_roles->find_or_create({ role => $role->id });
}


# Create a blog for blog posts to be added to
$schema->resultset( 'Blog' )->find_or_create({ title => '' });