| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Getopt::Long; |
| 4 |
|
| 5 |
my ($dbtype, $dbname, $dbuser, $dbpass, $dbhost, $dbport, $help, $id, $node_name, $version); |
| 6 |
GetOptions( "type=s" => \$dbtype, |
| 7 |
"name=s" => \$dbname, |
| 8 |
"user=s" => \$dbuser, |
| 9 |
"pass=s" => \$dbpass, |
| 10 |
"host=s" => \$dbhost, |
| 11 |
"port=s" => \$dbport, |
| 12 |
"help" => \$help, |
| 13 |
"id=s" => \$id, |
| 14 |
"nodename=s" => \$node_name, |
| 15 |
"version=s" => \$version, |
| 16 |
); |
| 17 |
|
| 18 |
unless (defined($dbtype)) { |
| 19 |
print "You must supply a database type with the --type option.\n"; |
| 20 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 21 |
exit 1; |
| 22 |
} |
| 23 |
|
| 24 |
unless (defined($dbname)) { |
| 25 |
print "You must supply a database name with the --name option.\n"; |
| 26 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 27 |
exit 1; |
| 28 |
} |
| 29 |
|
| 30 |
if(defined($id) and defined($node_name)) { |
| 31 |
print "You should supply either a node name, or an id, but not both.\n"; |
| 32 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 33 |
exit 1; |
| 34 |
} |
| 35 |
|
| 36 |
if(not defined($id) and not defined($node_name)) { |
| 37 |
print "You must supply the id of the node with the --id option,\n"; |
| 38 |
print " or the node name of the node with the --nodename option.\n"; |
| 39 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 40 |
exit 1; |
| 41 |
} |
| 42 |
|
| 43 |
if ($help) { |
| 44 |
print "Help can be found by typing 'perldoc $0'\n"; |
| 45 |
exit 0; |
| 46 |
} |
| 47 |
|
| 48 |
my %setup_modules = ( postgres => "Wiki::Toolkit::Store::Pg", |
| 49 |
mysql => "Wiki::Toolkit::Store::MySQL", |
| 50 |
sqlite => "Wiki::Toolkit::Store::SQLite" |
| 51 |
); |
| 52 |
|
| 53 |
unless ( defined($setup_modules{$dbtype}) ) { |
| 54 |
print "dbtype must be one of 'postgres', 'mysql', and 'sqlite'\n"; |
| 55 |
print "further help can be found by typing 'perldoc $0'\n"; |
| 56 |
exit 1; |
| 57 |
} |
| 58 |
|
| 59 |
# Load classes |
| 60 |
require Wiki::Toolkit; |
| 61 |
my $class = $setup_modules{$dbtype}; |
| 62 |
eval "require $class"; |
| 63 |
if ( $@ ) { |
| 64 |
print "Couldn't 'use' $class: $@\n"; |
| 65 |
exit 1; |
| 66 |
} |
| 67 |
|
| 68 |
# Create a store instance |
| 69 |
my $store; |
| 70 |
my $args = "dbname=>'$dbname', dbuser=>'$dbuser'"; |
| 71 |
if($dbpass) { |
| 72 |
$args .= ", dbpass=>'$dbpass'"; |
| 73 |
} |
| 74 |
if($dbhost) { |
| 75 |
$args .= ", dbhost=>'$dbhost'"; |
| 76 |
} |
| 77 |
if($dbport) { |
| 78 |
$args .= ", dbport=>'$dbport'"; |
| 79 |
} |
| 80 |
eval "\$store = $class->new($args);"; |
| 81 |
|
| 82 |
# Create a Wiki instance |
| 83 |
my $wiki = Wiki::Toolkit->new(store=>$store); |
| 84 |
|
| 85 |
# If they gave the ID, get the name |
| 86 |
if($id) { |
| 87 |
$node_name = $wiki->store->node_name_for_id($id); |
| 88 |
unless($node_name) { |
| 89 |
die("No node found with id '$id'\n"); |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
# Report what we're going to do |
| 94 |
print "Deleting node with name '$node_name'"; |
| 95 |
if($id) { |
| 96 |
print " (id $id)"; |
| 97 |
} |
| 98 |
if($version) { |
| 99 |
print " at version $version"; |
| 100 |
} |
| 101 |
print "\n"; |
| 102 |
|
| 103 |
# Do the delete |
| 104 |
$wiki->delete_node(name => $node_name, version => $version); |
| 105 |
|
| 106 |
# All done |
| 107 |
print "done.\n"; |
| 108 |
|
| 109 |
=head1 NAME |
| 110 |
|
| 111 |
wiki-toolkit-delete-node - Delete a node stored in a Wiki::Toolkit instance. |
| 112 |
|
| 113 |
=head1 SYNOPSIS |
| 114 |
|
| 115 |
# Delete a node in a Wiki::Toolkit instance |
| 116 |
|
| 117 |
wiki-toolkit-delete-node --type postgres |
| 118 |
--name mywiki \ |
| 119 |
--user wiki \ |
| 120 |
--pass wiki \ |
| 121 |
--host 'db.example.com' \ |
| 122 |
--port 1234 \ |
| 123 |
--nodename MyNodeName |
| 124 |
|
| 125 |
wiki-toolkit-delete-node --type postgres |
| 126 |
--name mywiki \ |
| 127 |
--user wiki \ |
| 128 |
--pass wiki \ |
| 129 |
--host 'db.example.com' \ |
| 130 |
--port 1234 \ |
| 131 |
--id 2 \ |
| 132 |
--version 7 |
| 133 |
|
| 134 |
=head1 DESCRIPTION |
| 135 |
|
| 136 |
Takes four mandatory arguments: |
| 137 |
|
| 138 |
=over 4 |
| 139 |
|
| 140 |
=item type |
| 141 |
|
| 142 |
The database type. Should be one of 'postgres', 'mysql' and 'sqlite'. |
| 143 |
|
| 144 |
=item name |
| 145 |
|
| 146 |
The database name. |
| 147 |
|
| 148 |
=item nodename |
| 149 |
|
| 150 |
The name of the node to be deleted. |
| 151 |
|
| 152 |
=item id |
| 153 |
|
| 154 |
The id of the node to be deleted |
| 155 |
|
| 156 |
=back |
| 157 |
|
| 158 |
four optional arguments: |
| 159 |
|
| 160 |
=over 4 |
| 161 |
|
| 162 |
=item user |
| 163 |
|
| 164 |
The user that connects to the database. It must have permission |
| 165 |
to create and drop tables in the database. |
| 166 |
|
| 167 |
=item pass |
| 168 |
|
| 169 |
The user's database password. |
| 170 |
|
| 171 |
=item host |
| 172 |
|
| 173 |
The hostname of the machine the database server is running on (omit |
| 174 |
for local databases). |
| 175 |
|
| 176 |
=item port |
| 177 |
|
| 178 |
The port number that the database server is expecting connections to. |
| 179 |
|
| 180 |
=item version |
| 181 |
|
| 182 |
The version number of the node to delete |
| 183 |
|
| 184 |
=back |
| 185 |
|
| 186 |
=head1 AUTHOR |
| 187 |
|
| 188 |
Nick Burch |
| 189 |
|
| 190 |
=head1 COPYRIGHT |
| 191 |
|
| 192 |
Copyright (C) 2006 Nick Burch. All Rights Reserved. |
| 193 |
|
| 194 |
This code is free software; you can redistribute it and/or modify it |
| 195 |
under the same terms as Perl itself. |
| 196 |
|
| 197 |
=head1 SEE ALSO |
| 198 |
|
| 199 |
L<Wiki::Toolkit> |
| 200 |
|
| 201 |
=cut |
| 202 |
|
| 203 |
1; |