Skip to content
Permalink
Browse files

Add fromConfig switch, to suck in info from an old config to build a …

…new site. Keeps the database info and first sitename.
  • Loading branch information...
perlDreamer committed Mar 1, 2012
1 parent c85f218 commit 765a60093f966972a6366179ca0151d635b08e57
Showing with 26 additions and 15 deletions.
  1. +26 −15 wre/sbin/addsite.pl
@@ -20,7 +20,7 @@

my $config = WRE::Config->new();
my ($var1, $var2, $var3, $var4, $var5, $var6, $var7, $var8, $var9, $var0, $sitename, $adminPassword,
$dbUser, $dbPassword, $dbName, $help) = "";
$dbUser, $dbPassword, $dbName, $help, $fromConfig) = "";
GetOptions(
"help" => \$help,
"var1=s" => \$var1,
@@ -38,11 +38,12 @@
"databaseUser=s" => \$dbUser,
"databasePassword=s" => \$dbPassword,
"databaseName=s" => \$dbName,
"fromConfig=s" => \$fromConfig,
);

my $dbAdminUser = $config->get("mysql/adminUser");

if ($help || $adminPassword eq "" || $sitename eq "") {
if ($help || $adminPassword eq "" || ($sitename eq "" && $fromConfig eq '')) {
print <<STOP;
Usage: $0 --sitename=www.example.com --adminPassword=123qwe
@@ -54,13 +55,15 @@
--databasePassword The password you'd like created to access this site's database.
--databaseName The name of the database to create in MySQL (defaults to www_site_com for the domain www.site.com).
--databaseName The name of the database to create in MySQL (defaults to www_site_com for the domain www.site.com).
--help This message.
--sitename The name of the site you'd like to create. For example: www.example.com
or intranet.example.com
--fromConfig Pull the sitename, dbUser and dbPassword from the referenced config file
--var0-9 A series of variables you can use to arbitrary information into the site
creation process. These variables will be exposed to all templates used to
create this site.
@@ -69,6 +72,14 @@
exit;
}

if ($fromConfig) {
use Config::JSON;
my $webguiConfig = Config::JSON->new($fromConfig);
$sitename ||= $webguiConfig->get('sitename')->[0];
$dbUser ||= $webguiConfig->get('dbuser');
$dbPassword ||= $webguiConfig->get('dbpass');
}


my $site = WRE::Site->new(
wreConfig => $config,
@@ -78,18 +89,18 @@
);
if (eval {$site->checkCreationSanity}) {
$site->create({
siteDatabaseUser => $dbUser,
siteDatabasePassword => $dbPassword,
var0 => $var0,
var1 => $var1,
var2 => $var2,
var3 => $var3,
var4 => $var4,
var5 => $var5,
var6 => $var6,
var7 => $var7,
var8 => $var8,
var9 => $var9,
databaseUser => $dbUser,
databasePassword => $dbPassword,
var0 => $var0,
var1 => $var1,
var2 => $var2,
var3 => $var3,
var4 => $var4,
var5 => $var5,
var6 => $var6,
var7 => $var7,
var8 => $var8,
var9 => $var9,
});
print $site->sitename." was created. Don't forget to restart the web servers and Spectre.\n";
}

0 comments on commit 765a600

Please sign in to comment.
You can’t perform that action at this time.