Parent Directory
|
Revision Log
updated copyright dates
1 #!/usr/bin/env perl 2 ################################################################################ 3 # WeBWorK Online Homework Delivery System 4 # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 5 # $CVSHeader: webwork2/bin/delcourse,v 1.4 2006/01/25 23:13:45 sh002i Exp $ 6 # 7 # This program is free software; you can redistribute it and/or modify it under 8 # the terms of either: (a) the GNU General Public License as published by the 9 # Free Software Foundation; either version 2, or (at your option) any later 10 # version, or (b) the "Artistic License" which comes with this package. 11 # 12 # This program is distributed in the hope that it will be useful, but WITHOUT 13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the 15 # Artistic License for more details. 16 ################################################################################ 17 18 =head1 NAME 19 20 delcourse - delete a course 21 22 =head1 SYNOPSIS 23 24 delcourse [options] COURSEID 25 26 =head1 DESCRIPTION 27 28 Delete a course, including its database and course directory. 29 30 =head1 OPTIONS 31 32 =over 33 34 =item I<COURSEID> 35 36 The name of the course to delete. 37 38 =back 39 40 If the course's database layout is sql, the following options are valid: 41 42 =over 43 44 =item B<--sql-host>=I<HOST> 45 46 Specifies the hostname of the SQL server on the course database resides. If not 47 specified, the default for your RDBMS will be used. 48 49 =item B<--sql-port>=I<PORT> 50 51 Specifies the port of the SQL server on the course database resides. If not 52 specified, the default for your RDBMS will be used. 53 54 =item B<--sql-user>=I<USER> 55 56 Specifies the username to use when connecting to the SQL server to delete the 57 course database. This user must have CREATE, DELETE, FILE, INSERT, SELECT, and 58 UPDATE privileges, WITH GRANT OPTION. 59 60 =item B<--sql-pass>=I<PASS> 61 62 Specifies the password to use when connecting to the SQL server. 63 64 =item B<--sql-db>=I<DBNAME> 65 66 Specifies the name of the database to delete. (This is usually 67 "webwork_COURSENAME", but can be overridden by changing the database layout in 68 F<global.conf>.) 69 70 =back 71 72 =cut 73 74 BEGIN { 75 # hide arguments (there could be passwords there!) 76 $0 = "$0"; 77 } 78 79 use strict; 80 use warnings; 81 use Getopt::Long; 82 83 BEGIN { 84 die "WEBWORK_ROOT not found in environment.\n" 85 unless exists $ENV{WEBWORK_ROOT}; 86 } 87 88 use lib "$ENV{WEBWORK_ROOT}/lib"; 89 use WeBWorK::CourseEnvironment; 90 use WeBWorK::DB; 91 use WeBWorK::Utils qw(runtime_use readFile cryptPassword); 92 use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses); 93 94 sub usage { 95 print STDERR "usage: $0 [options] COURSEID\n"; 96 print STDERR "Options:\n"; 97 print STDERR " for \"sql\" database layout:\n"; 98 print STDERR " [--sql-host=HOST] [--sql-port=port]\n"; 99 print STDERR " --sql-user=USER --sql-pass=PASS\n"; 100 print STDERR " --sql-db=DBNAME\n"; 101 exit; 102 } 103 104 sub usage_error { 105 print STDERR "$0: @_\n"; 106 usage(); 107 } 108 109 my $sql_host = ""; 110 my $sql_port = ""; 111 my $sql_user = ""; 112 my $sql_pass = ""; 113 my $sql_db = ""; 114 115 ##### get command-line options ##### 116 117 GetOptions( 118 "sql-host=s" => \$sql_host, 119 "sql-port=s" => \$sql_port, 120 "sql-user=s" => \$sql_user, 121 "sql-pass=s" => \$sql_pass, 122 "sql-db=s" => \$sql_db, 123 ); 124 my $courseID = shift; 125 126 ##### perform sanity checks ##### 127 128 usage_error("must specify COURSEID.") unless $courseID; 129 130 # bring up a minimal course environment 131 my $ce = WeBWorK::CourseEnvironment->new({ 132 webwork_dir => $ENV{WEBWORK_ROOT}, 133 courseName => $courseID, 134 }); 135 136 my $dbLayout = $ce->{dbLayoutName}; 137 138 if ($dbLayout eq "sql") { 139 usage_error("must specify --sql-user.") unless $sql_user; 140 usage_error("must specify --sql-pass.") unless $sql_pass; 141 usage_error("must specify --sql-db.") unless $sql_db; 142 } 143 144 ##### set up parameters to pass to deleteCourse() ##### 145 146 my %dbOptions; 147 if ($dbLayout eq "sql") { 148 $dbOptions{host} = $sql_host if $sql_host ne ""; 149 $dbOptions{port} = $sql_port if $sql_port ne ""; 150 $dbOptions{username} = $sql_user; 151 $dbOptions{password} = $sql_pass; 152 $dbOptions{database} = $sql_db; 153 } 154 155 ##### call deleteCourse(), handle errors ##### 156 157 eval { 158 deleteCourse( 159 courseID => $courseID, 160 ce => $ce, 161 dbOptions => \%dbOptions, 162 ); 163 }; 164 165 if ($@) { 166 my $error = $@; 167 print STDERR "$error\n"; 168 exit; 169 } 170 171 =head1 AUTHOR 172 173 Written by Sam Hathaway, hathaway at users.sourceforge.net. 174 175 =cut
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |