-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.pm
89 lines (73 loc) · 2.23 KB
/
Core.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# Paulo Graça <[email protected]>
#
package Rex::Module::CMS::WP_CLI::Core;
use strict;
use Rex::Commands;
use Rex::Module::CMS::WP_CLI;
use Rex::Logger;
use Data::Dumper;
our $WP_CLI_COMMAND = 'core';
my @subcommands = qw( download update update_db );
foreach my $subcommand (@subcommands) {
desc "$subcommand $WP_CLI_COMMAND";
task "$subcommand",
sub {
_execute(
task => task->name,
subparams => @_);
};
}
task "install" => sub {
if (is_installed()) {
Rex::Logger::info( "WP already installed, nothing to do", "warn" );
} else {
my $param = shift;
my $admin_user = $param->{'conf'}->{'admin_user'};
my $admin_email = $param->{'conf'}->{'admin_email'};
my $url = $param->{'conf'}->{'url'};
my $title = $param->{'conf'}->{'title'};
my $admin_password = $param->{'conf'}->{'admin_password'};
my $command = "--url=$url --title=$title --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email " . $param->{'params'};
_execute(
task => task->name,
subparams => $command);
}
};
task "multisite_install" => sub {
if (is_installed()) {
Rex::Logger::info( "WP already installed, nothing to do", "warn" );
} else {
my $param = shift;
my $admin_user = $param->{'conf'}->{'admin_user'};
my $admin_email = $param->{'conf'}->{'admin_email'};
my $url = $param->{'conf'}->{'url'};
my $title = $param->{'conf'}->{'title'};
my $admin_password = $param->{'conf'}->{'admin_password'};
my $command = "--url=$url --title=$title --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email " . $param->{'params'};
_execute(
task => task->name,
subparams => $command);
}
};
desc 'return 1 if not installed';
sub is_installed {
Rex::Module::CMS::WP_CLI::execute ('core is-installed');
return ($? == 0);
};
sub _execute {
my @params = @_;
my $param;
if ( ref $params[0] eq "HASH" ) {
$param = $params[0];
} else {
$param = {@params};
}
my @action = split(/\:/, $param->{task});
Rex::Module::CMS::WP_CLI::execute (
Rex::Module::CMS::WP_CLI::buildCommand(
command => $WP_CLI_COMMAND,
subcommand => $action[$#action],
parameters => $param,
), $param );
};