| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Getopt::Long; |
| 4 |
|
| 5 |
my ($dbtype, $dbname, $dbuser, $dbpass, $dbhost, $dbport, $help, $oldname, $newname); |
| 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 |
"oldname=s" => \$oldname, |
| 14 |
"newname=s" => \$newname, |
| 15 |
); |
| 16 |
|
| 17 |
unless (defined($dbtype)) { |
| 18 |
print "You must supply a database type with the --type option.\n"; |
| 19 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 20 |
exit 1; |
| 21 |
} |
| 22 |
|
| 23 |
unless (defined($dbname)) { |
| 24 |
print "You must supply a database name with the --name option.\n"; |
| 25 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 26 |
exit 1; |
| 27 |
} |
| 28 |
|
| 29 |
unless (defined($oldname)) { |
| 30 |
print "You must supply the old node name with the --oldname option.\n"; |
| 31 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 32 |
exit 1; |
| 33 |
} |
| 34 |
|
| 35 |
unless (defined($newname)) { |
| 36 |
print "You must supply the new node name with the --newname option.\n"; |
| 37 |
print "Further help can be found by typing 'perldoc $0'\n"; |
| 38 |
exit 1; |
| 39 |
} |
| 40 |
|
| 41 |
if ($help) { |
| 42 |
print "Help can be found by typing 'perldoc $0'\n"; |
| 43 |
exit 0; |
| 44 |
} |
| 45 |
|
| 46 |
my %setup_modules = ( postgres => "Wiki::Toolkit::Store::Pg", |
| 47 |
mysql => "Wiki::Toolkit::Store::MySQL", |
| 48 |
sqlite => "Wiki::Toolkit::Store::SQLite" |
| 49 |
); |
| 50 |
|
| 51 |
unless ( defined($setup_modules{$dbtype}) ) { |
| 52 |
print "dbtype must be one of 'postgres', 'mysql', and 'sqlite'\n"; |
| 53 |
print "further help can be found by typing 'perldoc $0'\n"; |
| 54 |
exit 1; |
| 55 |
} |
| 56 |
|
| 57 |
# Load classes |
| 58 |
require Wiki::Toolkit; |
| 59 |
my $class = $setup_modules{$dbtype}; |
| 60 |
eval "require $class"; |
| 61 |
if ( $@ ) { |
| 62 |
print "Couldn't 'use' $class: $@\n"; |
| 63 |
exit 1; |
| 64 |
} |
| 65 |
|
| 66 |
# Create a store instance |
| 67 |
my $store; |
| 68 |
my $args = "dbname=>'$dbname', dbuser=>'$dbuser'"; |
| 69 |
if($dbpass) { |
| 70 |
$args .= ", dbpass=>'$dbpass'"; |
| 71 |
} |
| 72 |
if($dbhost) { |
| 73 |
$args .= ", dbhost=>'$dbhost'"; |
| 74 |
} |
| 75 |
if($dbport) { |
| 76 |
$args .= ", dbport=>'$dbport'"; |
| 77 |
} |
| 78 |
eval "\$store = $class->new($args);"; |
| 79 |
|
| 80 |
# Create a Wiki instance |
| 81 |
my $wiki = Wiki::Toolkit->new(store=>$store); |
| 82 |
|
| 83 |
# Do the rename |
| 84 |
$wiki->rename_node(old_name=>$oldname, new_name=>$newname); |
| 85 |
|
| 86 |
# All done |
| 87 |
print "Renamed '$oldname' to '$newname'\n"; |
| 88 |
|
| 89 |
=head1 NAME |
| 90 |
|
| 91 |
wiki-toolkit-rename-node - Rename a node stored in a Wiki::Toolkit instance. |
| 92 |
|
| 93 |
=head1 SYNOPSIS |
| 94 |
|
| 95 |
# Rename a node in a Wiki::Toolkit instance, updating internal links |
| 96 |
# and references if the formatter supports link re-writing. |
| 97 |
|
| 98 |
wiki-toolkit-rename-node --type postgres |
| 99 |
--name mywiki \ |
| 100 |
--user wiki \ |
| 101 |
--pass wiki \ |
| 102 |
--host 'db.example.com' \ |
| 103 |
--port 1234 |
| 104 |
--oldname MyOldNodeName \ |
| 105 |
--nemname FancyNewNodeName |
| 106 |
|
| 107 |
=head1 DESCRIPTION |
| 108 |
|
| 109 |
Takes four mandatory arguments: |
| 110 |
|
| 111 |
=over 4 |
| 112 |
|
| 113 |
=item type |
| 114 |
|
| 115 |
The database type. Should be one of 'postgres', 'mysql' and 'sqlite'. |
| 116 |
|
| 117 |
=item name |
| 118 |
|
| 119 |
The database name. |
| 120 |
|
| 121 |
=item oldname |
| 122 |
|
| 123 |
The name of the node to be renamed. |
| 124 |
|
| 125 |
=item newname |
| 126 |
|
| 127 |
The new name for the node. |
| 128 |
|
| 129 |
=back |
| 130 |
|
| 131 |
four optional arguments: |
| 132 |
|
| 133 |
=over 4 |
| 134 |
|
| 135 |
=item user |
| 136 |
|
| 137 |
The user that connects to the database. It must have permission |
| 138 |
to create and drop tables in the database. |
| 139 |
|
| 140 |
=item pass |
| 141 |
|
| 142 |
The user's database password. |
| 143 |
|
| 144 |
=item host |
| 145 |
|
| 146 |
The hostname of the machine the database server is running on (omit |
| 147 |
for local databases). |
| 148 |
|
| 149 |
=item port |
| 150 |
|
| 151 |
The port number that the database server is expecting connections to. |
| 152 |
|
| 153 |
=back |
| 154 |
|
| 155 |
=head1 AUTHOR |
| 156 |
|
| 157 |
Nick Burch |
| 158 |
|
| 159 |
=head1 COPYRIGHT |
| 160 |
|
| 161 |
Copyright (C) 2006 Nick Burch. All Rights Reserved. |
| 162 |
|
| 163 |
This code is free software; you can redistribute it and/or modify it |
| 164 |
under the same terms as Perl itself. |
| 165 |
|
| 166 |
=head1 SEE ALSO |
| 167 |
|
| 168 |
L<Wiki::Toolkit> |
| 169 |
|
| 170 |
=cut |
| 171 |
|
| 172 |
1; |