| 1 | #!/usr/local/bin/perl -w | ||||||||||||
| 2 | # $Id: nacho 1366 2003-08-23 08:35:54Z simon $ | ||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 9 | ▶ | use File::Path qw(mkpath); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 9 | ▶ | use File::Basename; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 9 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 9 | ▶ | use Tie::IxHash; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 9 | ▶ | use String::ShellQuote; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 9 | ▶ | use UNIVERSAL::require; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 9 | ▶ | use Siesta::Config; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 9 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=5 SCAR=16.7
| |||||||||||||
| 13 | 9 | ▶ | while (@ARGV) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 14 | 27 | ▶ | if ($ARGV[0] eq '-d') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 15 | 9 | shift; | |||||||||||
| 16 | 9 | @Siesta::Config::STORAGE = split / /, shift; | |||||||||||
| 17 | 9 | next; | |||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 18 | ▶ | if ($ARGV[0] eq '-f') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 9 | shift; | |||||||||||
| 22 | 9 | Siesta::Config->load_from( shift ); | |||||||||||
| 23 | 9 | next; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | # do create-database before the require of Siesta::List | ||||||||||||
| 27 | # otherwise Siesta::List &c will choke when they come to | ||||||||||||
| 28 | # __PACKAGE__->set_up_table | ||||||||||||
| 29 | |||||||||||||
| 30 | 9 | ▶ | if ($ARGV[0] eq 'create-database' ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 0 | require Siesta::DBI; | |||||||||||
| 32 | 0 | Siesta::DBI->init_db; | |||||||||||
| 33 | 0 | exit; | |||||||||||
| 34 | } | ||||||||||||
| 35 | 9 | last; | |||||||||||
| 36 | } | ||||||||||||
| 37 | } | ||||||||||||
| 38 | |||||||||||||
| 39 | 9 | eval { | |||||||||||
| 40 | 9 | require Siesta; | |||||||||||
| 41 | 9 | require Siesta::List; | |||||||||||
| 42 | }; | ||||||||||||
| 43 | 9 | ▶ | if ($@) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | print "Error initializing Siesta:\n$@\n"; | |||||||||||
| 45 | 0 | print "\n\nTry 'nacho create-database' if you are installing siesta for the first time\n"; | |||||||||||
| 46 | 0 | exit; | |||||||||||
| 47 | } | ||||||||||||
| 48 | |||||||||||||
| 49 | 9 | ▶ | use YAML; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 50 | 9 | Siesta->log("nacho invoked by $< $> args\n" . Dump \@ARGV); | |||||||||||
| 51 | |||||||||||||
| 52 | 9 | tie my %commands, 'Tie::IxHash'; | |||||||||||
| 53 | |||||||||||||
| 54 | =head1 NAME | ||||||||||||
| 55 | |||||||||||||
| 56 | nacho - the siesta command line configuration tool | ||||||||||||
| 57 | |||||||||||||
| 58 | =head1 DESCRIPTION | ||||||||||||
| 59 | |||||||||||||
| 60 | Via nacho you can control pretty much every aspect of you Siesta system. | ||||||||||||
| 61 | |||||||||||||
| 62 | This includes things like creating new lists, creating new members, adding | ||||||||||||
| 63 | members to lists, setting up and configuring plugins for lists and, later, | ||||||||||||
| 64 | probably handling administrative tasks. | ||||||||||||
| 65 | |||||||||||||
| 66 | =head1 COMMANDS | ||||||||||||
| 67 | |||||||||||||
| 68 | You can optionally pass a database to act on (the default is the | ||||||||||||
| 69 | one defined in Siesta::Config). By doing | ||||||||||||
| 70 | |||||||||||||
| 71 | -d database | ||||||||||||
| 72 | |||||||||||||
| 73 | |||||||||||||
| 74 | You can also specify an alternative config file using | ||||||||||||
| 75 | |||||||||||||
| 76 | -f <path to config file> | ||||||||||||
| 77 | |||||||||||||
| 78 | |||||||||||||
| 79 | The following commands are then valid | ||||||||||||
| 80 | |||||||||||||
| 81 | =cut | ||||||||||||
| 82 | |||||||||||||
| 83 | =head2 create-database | ||||||||||||
| 84 | |||||||||||||
| 85 | Initialise a new database | ||||||||||||
| 86 | |||||||||||||
| 87 | =cut | ||||||||||||
| 88 | |||||||||||||
| 89 | 0 | ▶ | $commands{'create-database'} = sub { die "dummy" }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||
| 90 | |||||||||||||
| 91 | # dummy to put a space in | ||||||||||||
| 92 | 9 | ▶ | $commands{' '} = sub { }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 93 | |||||||||||||
| 94 | ##### | ||||||||||||
| 95 | # | ||||||||||||
| 96 | # List stuff | ||||||||||||
| 97 | # | ||||||||||||
| 98 | ##### | ||||||||||||
| 99 | |||||||||||||
| 100 | =head2 show-lists | ||||||||||||
| 101 | |||||||||||||
| 102 | Show all the lists that are in the system | ||||||||||||
| 103 | |||||||||||||
| 104 | =cut | ||||||||||||
| 105 | |||||||||||||
| 106 | 0 | ▶ | $commands{'show-lists'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 107 | 0 | foreach my $list ( Siesta::List->retrieve_all ) { | |||||||||||
| 108 | 0 | print $list->name . "\n"; | |||||||||||
| 109 | } | ||||||||||||
| 110 | 0 | return; | |||||||||||
| 111 | 9 | }; | |||||||||||
| 112 | |||||||||||||
| 113 | |||||||||||||
| 114 | |||||||||||||
| 115 | =head2 create-list I<list_id> I<list_owner> I<post_address> I<return_path> | ||||||||||||
| 116 | |||||||||||||
| 117 | I<list_id> is the name of the list, I<list_owner> is the administrator | ||||||||||||
| 118 | of the list, I<post_address> is the email address that member's send mail | ||||||||||||
| 119 | to post to the list and I<return_path> is the address that bounces | ||||||||||||
| 120 | should come back to. | ||||||||||||
| 121 | |||||||||||||
| 122 | =cut | ||||||||||||
| 123 | |||||||||||||
| 124 | 1 | ▶ | $commands{'create-list'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.7
| |||||||||||||
| 125 | 1 | ▶ | my $list_id = shift || die "You must supply a list id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must supply a list id\n")
MC/DC0%0/1
shift() || die("You must supply a list id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 126 | 1 | ▶ | my $list_owner = shift || die "You must supply a list owner\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must supply a list owner\n")
MC/DC0%0/1
shift() || die("You must supply a list owner\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 127 | 1 | ▶ | my $post_addr = shift || die "You must supply a post address\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must supply a post address\n")
MC/DC0%0/1
shift() || die("You must supply a post address\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 128 | 1 | ▶ | my $return_path = shift || die "You must supply a bounce address\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must supply a bounce address\n")
MC/DC0%0/1
shift() || die("You must supply a bounce address\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 129 | |||||||||||||
| 130 | 1 | ▶ | my $list = Siesta::List->new ( | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 131 | name => $list_id, | ||||||||||||
| 132 | owner => Siesta::Member->find_or_create({ email => $list_owner }), | ||||||||||||
| 133 | post_address => $post_addr, | ||||||||||||
| 134 | return_path => $return_path, | ||||||||||||
| 135 | ) | ||||||||||||
| 136 | or die "Failed to create a new list\n"; | ||||||||||||
| 137 | |||||||||||||
| 138 | # set up default plugin queues | ||||||||||||
| 139 | 1 | $list->set_plugins( post => qw( Archive Send ) ); | |||||||||||
| 140 | 1 | $list->set_plugins( sub => qw( Subscribe ) ); | |||||||||||
| 141 | 1 | $list->set_plugins( unsub => qw( UnSubscribe ) ); | |||||||||||
| 142 | |||||||||||||
| 143 | 1 | print "Created the new list '$list_id' <$post_addr>\n"; | |||||||||||
| 144 | 1 | print "put this in your /etc/aliases"; | |||||||||||
| 145 | 1 | $commands{'show-alias'}->( $list_id); | |||||||||||
| 146 | 9 | }; | |||||||||||
| 147 | |||||||||||||
| 148 | |||||||||||||
| 149 | =head2 show-alias I<list_id> | ||||||||||||
| 150 | |||||||||||||
| 151 | Print out an alias file entry for the list specified. | ||||||||||||
| 152 | |||||||||||||
| 153 | =cut | ||||||||||||
| 154 | |||||||||||||
| 155 | 1 | ▶ | $commands{'show-alias'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||
| 156 | 1 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 157 | |||||||||||||
| 158 | 1 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 159 | or die "Not a valid list id\n"; | ||||||||||||
| 160 | |||||||||||||
| 161 | 1 | print $list->alias('nacho (the siesta configuration tool)'); | |||||||||||
| 162 | |||||||||||||
| 163 | 9 | }; | |||||||||||
| 164 | |||||||||||||
| 165 | |||||||||||||
| 166 | |||||||||||||
| 167 | =head2 describe-list I<list_id> | ||||||||||||
| 168 | |||||||||||||
| 169 | Show all the properties of a list and their values. | ||||||||||||
| 170 | |||||||||||||
| 171 | =cut | ||||||||||||
| 172 | |||||||||||||
| 173 | 0 | ▶ | $commands{'describe-list'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||
| 174 | 0 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 175 | |||||||||||||
| 176 | 0 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 177 | or die "Not a valid list id\n"; | ||||||||||||
| 178 | |||||||||||||
| 179 | 0 | foreach my $key ($list->columns) { | |||||||||||
| 180 | 0 | ▶ | my $value = $list->$key() || ''; | ||||||||||
|
Condition0%0/2
$list->$key || ''
MC/DC0%0/1
$list->$key || ''
$list->$key
Truth table0%0/2
A
A= $list->$key
| |||||||||||||
| 181 | 0 | print "$key = $value\n"; | |||||||||||
| 182 | } | ||||||||||||
| 183 | |||||||||||||
| 184 | 0 | for my $queue ($list->queues) { | |||||||||||
| 185 | 0 | ▶ | print "$queue plugins: ", join( ' ', map { ($_->personal)? "+".$_->name:$_->name } $list->plugins( $queue )), "\n"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 186 | } | ||||||||||||
| 187 | 9 | }; | |||||||||||
| 188 | |||||||||||||
| 189 | =head2 modify-list I<list_id> I<key> I<value> | ||||||||||||
| 190 | |||||||||||||
| 191 | Change a property of the list specified. See B<Siesta::List> for | ||||||||||||
| 192 | valid properties. | ||||||||||||
| 193 | |||||||||||||
| 194 | Note: you can effectively copy the configuration of a list by modifying | ||||||||||||
| 195 | the id - a new list with the new id will be created for you. | ||||||||||||
| 196 | |||||||||||||
| 197 | =cut | ||||||||||||
| 198 | |||||||||||||
| 199 | 0 | ▶ | $commands{'modify-list'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||
| 200 | 0 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 201 | |||||||||||||
| 202 | 0 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 203 | or die "Not a valid list id\n"; | ||||||||||||
| 204 | |||||||||||||
| 205 | 0 | my ( $key, $value ) = @_; | |||||||||||
| 206 | |||||||||||||
| 207 | 0 | ▶ | die "You must pass a key\n" unless defined $key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 208 | 0 | ▶ | die "You must pass a value\n" unless defined $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 209 | |||||||||||||
| 210 | 0 | my %fields = map { $_ => 1 } $list->columns; | |||||||||||
| 211 | die "'$key' is not a valid property - valid properties are\n", | ||||||||||||
| 212 | 0 | ▶ | (join "\n",$list->columns),"\n" unless $fields{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 213 | |||||||||||||
| 214 | 0 | $list->$key($value); | |||||||||||
| 215 | 0 | print "Property '$key' set to '$value' for the list $list_id\n"; | |||||||||||
| 216 | 9 | }; | |||||||||||
| 217 | |||||||||||||
| 218 | |||||||||||||
| 219 | =head2 delete-list I<list_id> | ||||||||||||
| 220 | |||||||||||||
| 221 | Remove the list indicated from the system. | ||||||||||||
| 222 | |||||||||||||
| 223 | =cut | ||||||||||||
| 224 | |||||||||||||
| 225 | 0 | ▶ | $commands{'delete-list'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 226 | 0 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 227 | |||||||||||||
| 228 | 0 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 229 | or die "Not a valid list id\n"; | ||||||||||||
| 230 | |||||||||||||
| 231 | # gosh, Class::DBI makes this easy | ||||||||||||
| 232 | 0 | $list->delete; | |||||||||||
| 233 | |||||||||||||
| 234 | 0 | print "List '$list_id' deleted\n"; | |||||||||||
| 235 | 9 | }; | |||||||||||
| 236 | |||||||||||||
| 237 | =head2 set-plugins I<list_id> I<queue> [ I<plugin> [ I<plugin>... ] ] | ||||||||||||
| 238 | |||||||||||||
| 239 | Set the list plugins to be the ones specified. | ||||||||||||
| 240 | |||||||||||||
| 241 | =cut | ||||||||||||
| 242 | |||||||||||||
| 243 | 2 | ▶ | $commands{'set-plugins'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=20.9
| |||||||||||||
| 244 | 2 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 245 | 2 | ▶ | my $queue = shift || die "need a queue\n"; | ||||||||||
|
Condition50%1/2
shift() || die("need a queue\n")
MC/DC0%0/1
shift() || die("need a queue\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 246 | 2 | my @plugins = @_; | |||||||||||
| 247 | |||||||||||||
| 248 | 2 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 249 | or die "Not a valid list id\n"; | ||||||||||||
| 250 | |||||||||||||
| 251 | 2 | ▶ | $list->set_plugins( $queue => @plugins ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 252 | or die "Sorry, couldn't do that for some reason\n"; | ||||||||||||
| 253 | |||||||||||||
| 254 | 2 | ▶ | unless (@plugins) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 255 | 0 | print "Deleted plugins from $list_id\n"; | |||||||||||
| 256 | 0 | return; | |||||||||||
| 257 | } | ||||||||||||
| 258 | 9 | }; | |||||||||||
| 259 | |||||||||||||
| 260 | |||||||||||||
| 261 | |||||||||||||
| 262 | =head2 add-member I<list_id> I<member> [I<member> ...] | ||||||||||||
| 263 | |||||||||||||
| 264 | Add the member(s) specified to the list specified. This will create new | ||||||||||||
| 265 | members if necessary. | ||||||||||||
| 266 | |||||||||||||
| 267 | =cut | ||||||||||||
| 268 | |||||||||||||
| 269 | 1 | ▶ | $commands{'add-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
| |||||||||||||
| 270 | 1 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 271 | 1 | ▶ | my $member_id = shift || die "You must pass a member id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a member id\n")
MC/DC0%0/1
shift() || die("You must pass a member id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 272 | |||||||||||||
| 273 | 1 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 274 | or die "Not a valid list id\n"; | ||||||||||||
| 275 | |||||||||||||
| 276 | 1 | ▶ | while ($member_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 277 | 2 | ▶ | my $member = Siesta::Member->find_or_create({ email => $member_id }) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 278 | or die "Couldn't get/create a member '$member_id'\n"; | ||||||||||||
| 279 | |||||||||||||
| 280 | 2 | $list->add_member($member); | |||||||||||
| 281 | 2 | print "Member <".$member->email."> (".$member->id.") added to list '$list_id'\n"; | |||||||||||
| 282 | 2 | $member_id = shift; | |||||||||||
| 283 | } | ||||||||||||
| 284 | 9 | }; | |||||||||||
| 285 | |||||||||||||
| 286 | |||||||||||||
| 287 | =head2 remove-member I<list_id> I<member> [I<member>...] | ||||||||||||
| 288 | |||||||||||||
| 289 | removes the specified I<member>(s) from the list. | ||||||||||||
| 290 | |||||||||||||
| 291 | =cut | ||||||||||||
| 292 | |||||||||||||
| 293 | 1 | ▶ | $commands{'remove-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.6
| |||||||||||||
| 294 | 1 | ▶ | my $list_id = shift || die "You must pass a list id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a list id\n")
MC/DC0%0/1
shift() || die("You must pass a list id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 295 | 1 | ▶ | my $member_id = shift || die "You must pass a member id\n"; | ||||||||||
|
Condition50%1/2
shift() || die("You must pass a member id\n")
MC/DC0%0/1
shift() || die("You must pass a member id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 296 | |||||||||||||
| 297 | 1 | ▶ | my $list = Siesta::List->load( $list_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 298 | or die "Not a valid list id\n"; | ||||||||||||
| 299 | |||||||||||||
| 300 | 1 | ▶ | while ($member_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 301 | 1 | ▶ | my $member = Siesta::Member->load($member_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 302 | or die "$member_id is not a valid member id\n"; | ||||||||||||
| 303 | |||||||||||||
| 304 | 1 | $list->remove_member($member); | |||||||||||
| 305 | 1 | print "Member '$member_id' removed from list '$list_id'\n"; | |||||||||||
| 306 | 1 | $member_id = shift; | |||||||||||
| 307 | } | ||||||||||||
| 308 | 9 | }; | |||||||||||
| 309 | |||||||||||||
| 310 | |||||||||||||
| 311 | # dummy to put a space in | ||||||||||||
| 312 | 9 | ▶ | $commands{' '} = sub { }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 313 | |||||||||||||
| 314 | ##### | ||||||||||||
| 315 | # | ||||||||||||
| 316 | # Member stuff | ||||||||||||
| 317 | # | ||||||||||||
| 318 | ##### | ||||||||||||
| 319 | |||||||||||||
| 320 | |||||||||||||
| 321 | =head2 show-members [ I<list_id> ] | ||||||||||||
| 322 | |||||||||||||
| 323 | Show all the members that are in the system or, if a list-id is | ||||||||||||
| 324 | passed, then just the ones subbed to that list | ||||||||||||
| 325 | |||||||||||||
| 326 | =cut | ||||||||||||
| 327 | |||||||||||||
| 328 | 0 | ▶ | $commands{'show-members'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||
| 329 | 0 | ▶ | if (!@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 330 | 0 | print "All members for system:\n"; | |||||||||||
| 331 | 0 | foreach my $member ( Siesta::Member->retrieve_all ) { | |||||||||||
| 332 | 0 | print $member->email, "\n"; | |||||||||||
| 333 | } | ||||||||||||
| 334 | 0 | return; | |||||||||||
| 335 | } | ||||||||||||
| 336 | 0 | for (@_) { | |||||||||||
| 337 | 0 | ▶ | my $list = Siesta::List->load($_) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 338 | or die "No list '$_'!\n"; | ||||||||||||
| 339 | 0 | print "Members of $_:\n"; | |||||||||||
| 340 | |||||||||||||
| 341 | 0 | foreach my $member ($list->members) { | |||||||||||
| 342 | 0 | print $member->email, "\n"; | |||||||||||
| 343 | } | ||||||||||||
| 344 | } | ||||||||||||
| 345 | 9 | }; | |||||||||||
| 346 | |||||||||||||
| 347 | |||||||||||||
| 348 | =head2 create-member I<member_id> | ||||||||||||
| 349 | |||||||||||||
| 350 | Add a new member to the system. | ||||||||||||
| 351 | |||||||||||||
| 352 | =cut | ||||||||||||
| 353 | |||||||||||||
| 354 | 4 | ▶ | $commands{'create-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||
| 355 | 4 | ▶ | my $email = shift | ||||||||||
|
Condition50%1/2
shift() || die("You need to pass an email address as a member id\n")
MC/DC0%0/1
shift() || die("You need to pass an email address as a member id\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 356 | || die "You need to pass an email address as a member id\n"; | ||||||||||||
| 357 | 4 | ▶ | my $member = Siesta::Member->find_or_create({ email => $email }) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 358 | or die "Errk : couldn't create a member"; | ||||||||||||
| 359 | |||||||||||||
| 360 | 4 | print "Member $email added\n"; | |||||||||||
| 361 | 9 | }; | |||||||||||
| 362 | |||||||||||||
| 363 | |||||||||||||
| 364 | =head2 describe-member I<member_id> | ||||||||||||
| 365 | |||||||||||||
| 366 | Show all the properties of a member and their values. | ||||||||||||
| 367 | |||||||||||||
| 368 | =cut | ||||||||||||
| 369 | |||||||||||||
| 370 | 0 | ▶ | $commands{'describe-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||
| 371 | 0 | ▶ | my $member_id = shift || die "You must pass a member id (i.e an email address)\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a member id (i.e an email address)\n")
MC/DC0%0/1
shift() || die("You must pass a member id (i.e an email address)\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 372 | |||||||||||||
| 373 | 0 | ▶ | my $member = Siesta::Member->load($member_id) || die "Not a valid member id\n"; | ||||||||||
|
Condition0%0/2
'Siesta::Member'->load($member_id) || die("Not a valid member id\n")
MC/DC0%0/1
'Siesta::Member'->load($member_id) || die("Not a valid member id\n")
'Siesta::Member'->load($member_id)
Truth table0%0/2
A
A= 'Siesta::Member'->load($member_id)
| |||||||||||||
| 374 | |||||||||||||
| 375 | 0 | foreach my $key ($member->columns) { | |||||||||||
| 376 | 0 | ▶ | my $value = $member->$key() || ''; | ||||||||||
|
Condition0%0/2
$member->$key || ''
MC/DC0%0/1
$member->$key || ''
$member->$key
Truth table0%0/2
A
A= $member->$key
| |||||||||||||
| 377 | 0 | print "$key = $value\n"; | |||||||||||
| 378 | } | ||||||||||||
| 379 | |||||||||||||
| 380 | 0 | print "Subscribed to : ", (join ", ", map { $_->name } $member->lists), "\n"; | |||||||||||
| 381 | 9 | }; | |||||||||||
| 382 | |||||||||||||
| 383 | |||||||||||||
| 384 | =head2 modify-member I<member_id> I<key> I<value> | ||||||||||||
| 385 | |||||||||||||
| 386 | Change a property of the member specified. See B<Siesta::Member> for | ||||||||||||
| 387 | valid properties. | ||||||||||||
| 388 | |||||||||||||
| 389 | Note: you can effectively copy the configuration of a member by modifying | ||||||||||||
| 390 | the id - a new member with the new id will be created for you. | ||||||||||||
| 391 | |||||||||||||
| 392 | =cut | ||||||||||||
| 393 | |||||||||||||
| 394 | 0 | ▶ | $commands{'modify-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||
| 395 | 0 | ▶ | my $member_id = shift || die "You must pass a member id\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a member id\n")
MC/DC0%0/1
shift() || die("You must pass a member id\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 396 | |||||||||||||
| 397 | 0 | ▶ | my $member = Siesta::Member->load( $member_id ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 398 | or die "Not a valid member id\n"; | ||||||||||||
| 399 | |||||||||||||
| 400 | 0 | my ( $key, $value ) = @_; | |||||||||||
| 401 | |||||||||||||
| 402 | 0 | ▶ | die "You must pass a key\n" unless defined $key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 403 | 0 | ▶ | die "You must pass a value\n" unless defined $value; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 404 | |||||||||||||
| 405 | 0 | my %fields = map { $_ => 1 } $member->columns; | |||||||||||
| 406 | die "'$key' is not a valid property - valid properties are\n", | ||||||||||||
| 407 | 0 | ▶ | (join "\n",$member->columns),"\n" unless $fields{$key}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 408 | |||||||||||||
| 409 | 0 | $member->$key($value); | |||||||||||
| 410 | 0 | $member->update; | |||||||||||
| 411 | 0 | print "Property '$key' set to '$value' for the list $member_id\n"; | |||||||||||
| 412 | 9 | }; | |||||||||||
| 413 | |||||||||||||
| 414 | =head2 delete-member I<member_id> | ||||||||||||
| 415 | |||||||||||||
| 416 | Remove a member from the system. | ||||||||||||
| 417 | |||||||||||||
| 418 | =cut | ||||||||||||
| 419 | |||||||||||||
| 420 | 0 | ▶ | $commands{'delete-member'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||
| 421 | 0 | ▶ | my $member_id = shift || die "You must pass a member id (i.e an email address)\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a member id (i.e an email address)\n")
MC/DC0%0/1
shift() || die("You must pass a member id (i.e an email address)\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 422 | |||||||||||||
| 423 | 0 | ▶ | my $member = Siesta::Member->load($member_id) || die "Not a valid member id\n"; | ||||||||||
|
Condition0%0/2
'Siesta::Member'->load($member_id) || die("Not a valid member id\n")
MC/DC0%0/1
'Siesta::Member'->load($member_id) || die("Not a valid member id\n")
'Siesta::Member'->load($member_id)
Truth table0%0/2
A
A= 'Siesta::Member'->load($member_id)
| |||||||||||||
| 424 | |||||||||||||
| 425 | 0 | foreach my $list ( Siesta::List->retrieve_all ) { | |||||||||||
| 426 | 0 | $list->remove_member($member); | |||||||||||
| 427 | } | ||||||||||||
| 428 | |||||||||||||
| 429 | 0 | $member->delete; | |||||||||||
| 430 | |||||||||||||
| 431 | 0 | print "Member '$member_id' deleted\n"; | |||||||||||
| 432 | 9 | }; | |||||||||||
| 433 | |||||||||||||
| 434 | |||||||||||||
| 435 | # dummy to put a space in | ||||||||||||
| 436 | 9 | ▶ | $commands{' '} = sub { }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 437 | |||||||||||||
| 438 | |||||||||||||
| 439 | ##### | ||||||||||||
| 440 | # | ||||||||||||
| 441 | # Plugin stuff | ||||||||||||
| 442 | # | ||||||||||||
| 443 | ##### | ||||||||||||
| 444 | |||||||||||||
| 445 | =head2 show-plugins <list id> | ||||||||||||
| 446 | |||||||||||||
| 447 | List all plugins available to the system or just the plugins | ||||||||||||
| 448 | for a list. | ||||||||||||
| 449 | |||||||||||||
| 450 | =cut | ||||||||||||
| 451 | |||||||||||||
| 452 | 0 | ▶ | $commands{'show-plugins'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||
| 453 | 0 | ▶ | if (!@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 454 | 0 | print "This system currently has these plugins installed : \n\n"; | |||||||||||
| 455 | 0 | foreach my $name ( Siesta->available_plugins ) { | |||||||||||
| 456 | 0 | my $p = "Siesta::Plugin::$name"; | |||||||||||
| 457 | 0 | $p->require; | |||||||||||
| 458 | 0 | printf "%s\n -\n %s\n\n",$name, $p->description; | |||||||||||
| 459 | } | ||||||||||||
| 460 | } | ||||||||||||
| 461 | |||||||||||||
| 462 | 0 | for (@_) { | |||||||||||
| 463 | 0 | ▶ | my $list = Siesta::List->load($_) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 464 | or die "No list '$_'!\n"; | ||||||||||||
| 465 | 0 | print "Plugins for $_:\n"; | |||||||||||
| 466 | |||||||||||||
| 467 | 0 | foreach my $queue ($list->queues()) { | |||||||||||
| 468 | 0 | print "\n$queue:\n"; | |||||||||||
| 469 | 0 | foreach my $plugin ($list->plugins($queue)) { | |||||||||||
| 470 | 0 | print $plugin->name,"\n"; | |||||||||||
| 471 | } | ||||||||||||
| 472 | } | ||||||||||||
| 473 | } | ||||||||||||
| 474 | 9 | }; | |||||||||||
| 475 | |||||||||||||
| 476 | |||||||||||||
| 477 | =head2 describe-plugin I<plugin> [ I<list_id> ] [ I<member_id> ] | ||||||||||||
| 478 | |||||||||||||
| 479 | List all the options for a particular plugin. If a I<list_id> is | ||||||||||||
| 480 | passed then it will show the current settings for that list. If, | ||||||||||||
| 481 | additionally, a I<member_id> is passed then the member's options | ||||||||||||
| 482 | for that list will be shown. | ||||||||||||
| 483 | |||||||||||||
| 484 | =cut | ||||||||||||
| 485 | |||||||||||||
| 486 | 0 | ▶ | $commands{'describe-plugin'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 487 | 0 | ▶ | my $plugin_id = shift || die "You must pass a plugin name\n"; | ||||||||||
|
Condition0%0/2
shift() || die("You must pass a plugin name\n")
MC/DC0%0/1
shift() || die("You must pass a plugin name\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 488 | 0 | my $list_id = shift; | |||||||||||
| 489 | |||||||||||||
| 490 | 0 | ▶ | if ($list_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 491 | 0 | _plugin_list_options($plugin_id,$list_id,@_); | |||||||||||
| 492 | } | ||||||||||||
| 493 | else { | ||||||||||||
| 494 | 0 | _plugin_options($plugin_id); | |||||||||||
| 495 | } | ||||||||||||
| 496 | |||||||||||||
| 497 | 9 | }; | |||||||||||
| 498 | |||||||||||||
| 499 | |||||||||||||
| 500 | 0 | ▶ | sub _plugin_options { | ||||||||||
|
Subroutine
_plugin_options: not called CC=3 SCAR=24.8
| |||||||||||||
| 501 | 0 | my $plugin_id = shift; | |||||||||||
| 502 | |||||||||||||
| 503 | 0 | my %plugins = map { $_ => 1 } Siesta->available_plugins; | |||||||||||
| 504 | |||||||||||||
| 505 | 0 | ▶ | die "Not a valid plugin\n" unless $plugins{$plugin_id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 506 | |||||||||||||
| 507 | 0 | my $class = "Siesta::Plugin::$plugin_id"; | |||||||||||
| 508 | 0 | $class->require; | |||||||||||
| 509 | |||||||||||||
| 510 | 0 | my $options = $class->options; | |||||||||||
| 511 | |||||||||||||
| 512 | 0 | print "\n\nThe plugin $plugin_id has the following options :\n"; | |||||||||||
| 513 | 0 | foreach my $option ( keys %{$options} ) { | |||||||||||
| 514 | 0 | print " - ", $option, " : ", $options->{$option}->{description}, "\n"; | |||||||||||
| 515 | } | ||||||||||||
| 516 | 0 | print "\n"; | |||||||||||
| 517 | } | ||||||||||||
| 518 | |||||||||||||
| 519 | 0 | ▶ | sub _plugin_list_options { | ||||||||||
|
Subroutine
_plugin_list_options: not called CC=12 SCAR=50.5
| |||||||||||||
| 520 | 0 | my ($plugin_id, $list_id, $member_id) = @_; | |||||||||||
| 521 | |||||||||||||
| 522 | 0 | ▶ | die "No plugin name passed\n" unless defined $plugin_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 523 | 0 | ▶ | die "No list name passed\n" unless defined $list_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 524 | |||||||||||||
| 525 | 0 | ▶ | my $list = Siesta::List->load($list_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 526 | or die "Not a valid list $list_id\n"; | ||||||||||||
| 527 | |||||||||||||
| 528 | 0 | my @plugins; | |||||||||||
| 529 | 0 | foreach my $queue ($list->queues) { | |||||||||||
| 530 | 0 | push @plugins, $list->plugins($queue); | |||||||||||
| 531 | } | ||||||||||||
| 532 | |||||||||||||
| 533 | 0 | my %plugins = map { $_->name => $_ } @plugins; | |||||||||||
| 534 | |||||||||||||
| 535 | 0 | ▶ | my $plugin = $plugins{$plugin_id} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 536 | or die "That plugin is not used in the list '$list_id'\n"; | ||||||||||||
| 537 | |||||||||||||
| 538 | |||||||||||||
| 539 | 0 | my $member; | |||||||||||
| 540 | 0 | ▶ | if (defined $member_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 541 | 0 | ▶ | $member = Siesta::Member->load($member_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 542 | or die "Not a valid member id\n"; | ||||||||||||
| 543 | |||||||||||||
| 544 | 0 | ▶ | die "$member_id is not subscribed to $list_id\n" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 545 | unless $list->is_member($member); | ||||||||||||
| 546 | |||||||||||||
| 547 | 0 | $plugin->member($member); | |||||||||||
| 548 | } | ||||||||||||
| 549 | |||||||||||||
| 550 | 0 | my $options = $plugin->options; | |||||||||||
| 551 | |||||||||||||
| 552 | 0 | ▶ | if (defined $member) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 553 | 0 | printf "Personal preferences for member %s on list %s\n", $member_id, $list_id; | |||||||||||
| 554 | } | ||||||||||||
| 555 | else { | ||||||||||||
| 556 | 0 | printf "Preferences for list %s\n", $list_id; | |||||||||||
| 557 | } | ||||||||||||
| 558 | |||||||||||||
| 559 | 0 | foreach my $option ( keys %{$options} ) { | |||||||||||
| 560 | 0 | print " - ", $option, " : ", $plugin->pref($option), "\n"; | |||||||||||
| 561 | } | ||||||||||||
| 562 | 0 | ▶ | print $plugin->name," is set personal\n" if $plugin->personal(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 563 | } | ||||||||||||
| 564 | |||||||||||||
| 565 | |||||||||||||
| 566 | =head2 modify-plugin I<plugin> I<list_id> I<key> I<val> [ I<member_id> ] | ||||||||||||
| 567 | |||||||||||||
| 568 | Sets the preference for a list. If optionally passed a member email, | ||||||||||||
| 569 | it will set their personal preference. | ||||||||||||
| 570 | |||||||||||||
| 571 | =cut | ||||||||||||
| 572 | |||||||||||||
| 573 | |||||||||||||
| 574 | 0 | ▶ | $commands{'modify-plugin'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=12 SCAR=50.5
| |||||||||||||
| 575 | 0 | my ($plugin_id, $list_id, $key, $val, $member_id) = @_; | |||||||||||
| 576 | |||||||||||||
| 577 | 0 | ▶ | die "No plugin name passed\n" unless defined $plugin_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 578 | 0 | ▶ | die "No list name passed\n" unless defined $list_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 579 | 0 | ▶ | die "You must pass a preference to change\n" unless defined $key; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 580 | 0 | ▶ | die "You must pass a value to the '$key' preference to\n" unless defined $val; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 581 | |||||||||||||
| 582 | 0 | ▶ | my $list = Siesta::List->load($list_id) || die "Not a valid list $list_id\n"; | ||||||||||
|
Condition0%0/2
'Siesta::List'->load($list_id) || die("Not a valid list $list_id\n")
MC/DC0%0/1
'Siesta::List'->load($list_id) || die("Not a valid list $list_id\n")
'Siesta::List'->load($list_id)
Truth table0%0/2
A
A= 'Siesta::List'->load($list_id)
| |||||||||||||
| 583 | |||||||||||||
| 584 | 0 | my %plugins = map { $_->name => $_ } $list->plugins; | |||||||||||
| 585 | 0 | ▶ | my $plugin = $plugins{$plugin_id} || die "Not a valid plugin $plugin_id\n"; | ||||||||||
|
Condition0%0/2
$plugins{$plugin_id} || die("Not a valid plugin $plugin_id\n")
MC/DC0%0/1
$plugins{$plugin_id} || die("Not a valid plugin $plugin_id\n")
$plugins{$plugin_id}
Truth table0%0/2
A
A= $plugins{$plugin_id}
| |||||||||||||
| 586 | |||||||||||||
| 587 | |||||||||||||
| 588 | 0 | my $member; | |||||||||||
| 589 | 0 | ▶ | if (defined $member_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 590 | 0 | ▶ | $member = Siesta::Member->load($member_id) | ||||||||||
|
Condition0%0/2
'Siesta::Member'->load($member_id) || die("No such member $member_id\n")
MC/DC0%0/1
'Siesta::Member'->load($member_id) || die("No such member $member_id\n")
'Siesta::Member'->load($member_id)
Truth table0%0/2
A
A= 'Siesta::Member'->load($member_id)
| |||||||||||||
| 591 | || die "No such member $member_id\n"; | ||||||||||||
| 592 | |||||||||||||
| 593 | 0 | ▶ | die "$member_id is not subscribed to $list_id\n" | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 594 | unless $list->is_member($member); | ||||||||||||
| 595 | |||||||||||||
| 596 | 0 | $plugin->member($member); | |||||||||||
| 597 | } | ||||||||||||
| 598 | |||||||||||||
| 599 | 0 | $plugin->pref($key, $val); | |||||||||||
| 600 | |||||||||||||
| 601 | 0 | my $options = $plugin->options; | |||||||||||
| 602 | |||||||||||||
| 603 | 0 | ▶ | if (defined $member) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 604 | 0 | printf "Personal preferences for member %s on list %s\n", $member_id, $list_id; | |||||||||||
| 605 | } | ||||||||||||
| 606 | else { | ||||||||||||
| 607 | 0 | printf "Preferences for list %s\n", $list_id; | |||||||||||
| 608 | } | ||||||||||||
| 609 | |||||||||||||
| 610 | 0 | foreach my $option ( keys %{$options} ) { | |||||||||||
| 611 | 0 | print " - ", $option, " : ", $plugin->pref($option), "\n"; | |||||||||||
| 612 | } | ||||||||||||
| 613 | 9 | }; | |||||||||||
| 614 | |||||||||||||
| 615 | |||||||||||||
| 616 | ##### | ||||||||||||
| 617 | # | ||||||||||||
| 618 | # Deferred message stuff | ||||||||||||
| 619 | # | ||||||||||||
| 620 | ##### | ||||||||||||
| 621 | |||||||||||||
| 622 | # dummy to put a space in | ||||||||||||
| 623 | 9 | ▶ | $commands{' '} = sub { }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 624 | |||||||||||||
| 625 | |||||||||||||
| 626 | |||||||||||||
| 627 | =head2 show-deferred [ deferred_id ] | ||||||||||||
| 628 | |||||||||||||
| 629 | Show all the deferred messages or, if an id is | ||||||||||||
| 630 | passed in, show that deferred message. | ||||||||||||
| 631 | |||||||||||||
| 632 | =cut | ||||||||||||
| 633 | |||||||||||||
| 634 | |||||||||||||
| 635 | 0 | ▶ | $commands{'show-deferred'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||
| 636 | 0 | my $mess_id = shift; | |||||||||||
| 637 | |||||||||||||
| 638 | # show an individual deferred message | ||||||||||||
| 639 | 0 | ▶ | if (defined $mess_id) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 640 | 0 | ▶ | my $deferred = Siesta::Deferred->retrieve($mess_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 641 | or die "No such deferred message\n"; | ||||||||||||
| 642 | 0 | print $deferred->message->as_string; | |||||||||||
| 643 | 0 | return; | |||||||||||
| 644 | } | ||||||||||||
| 645 | |||||||||||||
| 646 | 0 | my @all = Siesta::Deferred->retrieve_all; | |||||||||||
| 647 | 0 | ▶ | unless (@all) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 648 | 0 | print "No deferred messages\n"; | |||||||||||
| 649 | 0 | return; | |||||||||||
| 650 | } | ||||||||||||
| 651 | |||||||||||||
| 652 | 0 | foreach my $deferred (@all) { | |||||||||||
| 653 | 0 | print +( | |||||||||||
| 654 | "Deferred-Id: ", $deferred->id, | ||||||||||||
| 655 | "\nReason: ", $deferred->why, | ||||||||||||
| 656 | "\nOwner: ", $deferred->who->email, | ||||||||||||
| 657 | "\n\n From: ", $deferred->message->header('From'), | ||||||||||||
| 658 | "\n To: ", $deferred->message->header('To'), | ||||||||||||
| 659 | "\n Subject: ", $deferred->message->subject, | ||||||||||||
| 660 | "\n Date: ", $deferred->message->header('Date'), | ||||||||||||
| 661 | "\n\n", | ||||||||||||
| 662 | ); | ||||||||||||
| 663 | } | ||||||||||||
| 664 | 9 | }; | |||||||||||
| 665 | |||||||||||||
| 666 | |||||||||||||
| 667 | =head2 resume-deferred deferred_id | ||||||||||||
| 668 | |||||||||||||
| 669 | Resume a deferred message. | ||||||||||||
| 670 | |||||||||||||
| 671 | =cut | ||||||||||||
| 672 | |||||||||||||
| 673 | 0 | ▶ | $commands{'resume-deferred'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 674 | 0 | my $mess_id = shift; | |||||||||||
| 675 | |||||||||||||
| 676 | 0 | ▶ | my $message = Siesta::Deferred->retrieve($mess_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 677 | or die "No such deferred message\n"; | ||||||||||||
| 678 | |||||||||||||
| 679 | 0 | Siesta::Message->resume( $mess_id ); | |||||||||||
| 680 | |||||||||||||
| 681 | 0 | print "Sucessfully resumed message $mess_id\n"; | |||||||||||
| 682 | 9 | }; | |||||||||||
| 683 | |||||||||||||
| 684 | 0 | ▶ | $commands{'delete-deferred'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 685 | 0 | my $mess_id = shift; | |||||||||||
| 686 | |||||||||||||
| 687 | 0 | ▶ | my $message = Siesta::Deferred->retrieve($mess_id) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 688 | or die "No such deferred message\n"; | ||||||||||||
| 689 | |||||||||||||
| 690 | 0 | $message->delete; | |||||||||||
| 691 | 0 | print "Message deleted from deferral queue\n"; | |||||||||||
| 692 | 9 | }; | |||||||||||
| 693 | |||||||||||||
| 694 | |||||||||||||
| 695 | ##### | ||||||||||||
| 696 | # | ||||||||||||
| 697 | # Misc stuff | ||||||||||||
| 698 | # | ||||||||||||
| 699 | ##### | ||||||||||||
| 700 | |||||||||||||
| 701 | # dummy to put a space in | ||||||||||||
| 702 | 9 | ▶ | $commands{' '} = sub { }; | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 703 | |||||||||||||
| 704 | =head2 run-mariachi | ||||||||||||
| 705 | |||||||||||||
| 706 | invoke mariachi to make webified archives (depends on the Archive plugin) | ||||||||||||
| 707 | |||||||||||||
| 708 | =cut | ||||||||||||
| 709 | |||||||||||||
| 710 | 0 | ▶ | $commands{'run-mariachi'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 711 | 0 | for my $archive (Siesta::Plugin->search( name => 'Archive' )) { | |||||||||||
| 712 | 0 | $archive = $archive->promote; | |||||||||||
| 713 | 0 | my $input = $archive->pref('path'); | |||||||||||
| 714 | 0 | my $name = $archive->list->name; | |||||||||||
| 715 | 0 | my $output = $Siesta::Config::ROOT . "/mariachi-html/$name"; | |||||||||||
| 716 | 0 | print "invoking mariachi for $name\n"; | |||||||||||
| 717 | 0 | system 'mariachi', '-i', $input, '-o', $output, '-n', $name; | |||||||||||
| 718 | } | ||||||||||||
| 719 | 9 | }; | |||||||||||
| 720 | |||||||||||||
| 721 | |||||||||||||
| 722 | =head2 create-backup [list name] | ||||||||||||
| 723 | |||||||||||||
| 724 | Prints out shell script that will restore you system when run | ||||||||||||
| 725 | |||||||||||||
| 726 | Optionally can take a list anme and will only dump a backup script | ||||||||||||
| 727 | for that list. | ||||||||||||
| 728 | |||||||||||||
| 729 | =cut | ||||||||||||
| 730 | |||||||||||||
| 731 | 0 | ▶ | $commands{'create-backup'} = sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||
| 732 | 0 | my @members; | |||||||||||
| 733 | my @lists; | ||||||||||||
| 734 | |||||||||||||
| 735 | 0 | ▶ | if ($_[0]) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 736 | # we have been passed a list | ||||||||||||
| 737 | 0 | ▶ | my $list = Siesta::List->load($_[0]) || die "No such list '$_[0]'\n"; | ||||||||||
|
Condition0%0/2
'Siesta::List'->load($_[0]) || die("No such list '$_[0]'\n")
MC/DC0%0/1
'Siesta::List'->load($_[0]) || die("No such list '$_[0]'\n")
'Siesta::List'->load($_[0])
Truth table0%0/2
A
A= 'Siesta::List'->load($_[0])
| |||||||||||||
| 738 | 0 | push @lists, $list; | |||||||||||
| 739 | 0 | @members = $list->members(); | |||||||||||
| 740 | } | ||||||||||||
| 741 | else { | ||||||||||||
| 742 | # otherwise do everything | ||||||||||||
| 743 | 0 | @members = Siesta::Member->retrieve_all; | |||||||||||
| 744 | 0 | @lists = Siesta::List->retrieve_all; | |||||||||||
| 745 | } | ||||||||||||
| 746 | |||||||||||||
| 747 | print Siesta->bake('backup', | ||||||||||||
| 748 | 'members' => \@members, | ||||||||||||
| 749 | 'lists' => \@lists, | ||||||||||||
| 750 | 0 | ▶ | 'shellq' => sub { return shell_quote $_[0] }, | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 751 | 0 | ); | |||||||||||
| 752 | 9 | }; | |||||||||||
| 753 | |||||||||||||
| 754 | |||||||||||||
| 755 | 9 | ▶ | sub usage { | ||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||
| 756 | 9 | my $name = basename $0; | |||||||||||
| 757 | |||||||||||||
| 758 | return join '', "Usage: $name <-d database> COMMAND\nRecognised commands:", | ||||||||||||
| 759 | 9 | (map { "\n\t $_" } keys %commands ), | |||||||||||
| 760 | "\n\nSee the $name manpage for more details"; | ||||||||||||
| 761 | } | ||||||||||||
| 762 | |||||||||||||
| 763 | # not enough arguments | ||||||||||||
| 764 | 9 | my $usage = usage(); | |||||||||||
| 765 | 9 | ▶ | die "$usage\n" unless @ARGV; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 766 | |||||||||||||
| 767 | # what are we doing? | ||||||||||||
| 768 | 9 | my $mode = shift @ARGV; | |||||||||||
| 769 | |||||||||||||
| 770 | 9 | ▶ | my $cmd = $commands{$mode} | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 771 | or die usage; | ||||||||||||
| 772 | |||||||||||||
| 773 | 9 | $cmd->(@ARGV); | |||||||||||
| 774 | |||||||||||||
| 775 | 9 | exit 0; | |||||||||||
| 776 | __END__ | ||||||||||||