Skip to content

Commit 1ea5666

Browse files
committedMar 1, 2012
Add fromConfig switch, to suck in info from an old config to build a new site. Keeps the database info and first sitename.
1 parent 252a50d commit 1ea5666

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed
 

‎wre/sbin/addsite.pl

+26-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
my $config = WRE::Config->new();
2222
my ($var1, $var2, $var3, $var4, $var5, $var6, $var7, $var8, $var9, $var0, $sitename, $adminPassword,
23-
$dbUser, $dbPassword, $dbName, $help) = "";
23+
$dbUser, $dbPassword, $dbName, $help, $fromConfig) = "";
2424
GetOptions(
2525
"help" => \$help,
2626
"var1=s" => \$var1,
@@ -38,11 +38,12 @@
3838
"databaseUser=s" => \$dbUser,
3939
"databasePassword=s" => \$dbPassword,
4040
"databaseName=s" => \$dbName,
41+
"fromConfig=s" => \$fromConfig,
4142
);
4243

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

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

75+
if ($fromConfig) {
76+
use Config::JSON;
77+
my $webguiConfig = Config::JSON->new($fromConfig);
78+
$sitename ||= $webguiConfig->get('sitename')->[0];
79+
$dbUser ||= $webguiConfig->get('dbuser');
80+
$dbPassword ||= $webguiConfig->get('dbpass');
81+
}
82+
7283

7384
my $site = WRE::Site->new(
7485
wreConfig => $config,
@@ -78,18 +89,18 @@
7889
);
7990
if (eval {$site->checkCreationSanity}) {
8091
$site->create({
81-
siteDatabaseUser => $dbUser,
82-
siteDatabasePassword => $dbPassword,
83-
var0 => $var0,
84-
var1 => $var1,
85-
var2 => $var2,
86-
var3 => $var3,
87-
var4 => $var4,
88-
var5 => $var5,
89-
var6 => $var6,
90-
var7 => $var7,
91-
var8 => $var8,
92-
var9 => $var9,
92+
databaseUser => $dbUser,
93+
databasePassword => $dbPassword,
94+
var0 => $var0,
95+
var1 => $var1,
96+
var2 => $var2,
97+
var3 => $var3,
98+
var4 => $var4,
99+
var5 => $var5,
100+
var6 => $var6,
101+
var7 => $var7,
102+
var8 => $var8,
103+
var9 => $var9,
93104
});
94105
print $site->sitename." was created. Don't forget to restart the web servers and Spectre.\n";
95106
}

0 commit comments

Comments
 (0)