#!/usr/local/bin/perl # This script checks the database for the old location path and moves those # documents in that location to the new docid location. # Also, it will copy the new documents that we created to this new location. # use DBI; #set the path where we want the stuff to go $doc_path = "/afs/.glue/department/oit/us/httpd/helpdesk/htdocs/public/scratch/newsite/documents"; $old_docroot_path = "/afs/.glue/department/oit/us/httpd/helpdesk/htdocs/public"; $new_docroot_path = "/afs/.glue/department/oit/us/httpd/helpdesk/htdocs/public/scratch/newsite"; open(LOG, ">>$doc_path/logfile"); main(); close(LOG); # the main part of the script, this does the stuff sub main() { getconnect(); getdocs(); print LOG `date`; print LOG "creating file structure in $doc_path\n"; while(@row = $statement->fetchrow_array) { print LOG "---- NEXT DOCUMENT ----\n"; # copies updated, non-deprecated, non-ignored documents to the correct directory if (@row[3] =~ /T/ && @row[4] =~ /F/ && @row[5] =~ /F/) { # makes the directories print LOG "creating dir @row[0]\n"; if (-e @row[0]) { `rm @row[0]`; #get rid of crap if there is crap } `mkdir @row[0]`; # copies the right stuff from updated documents to the directories # @row[3] is the updated column if you were wondering chomp @row[2]; #chop off the .shtml file part if it is there @row[2] =~ s/\/\w*.shtml//; # copies stuff in the new location to the docid directory print LOG "UPDATED DOC: copying from @row[2] to @row[0]\n"; `cp -p $new_docroot_path/@row[2]/* @row[0]`; `cp -p -R $new_docroot_path/@row[2]/RCS @row[0]`; `cp -p -R $new_docroot_path/@row[2]/images @row[0]`; update_newpath(); } if (@row[3] =~ /F/ && @row[4] =~ /F/ && @row[5] =~ /F/) { # makes the directories print LOG "creating dir @row[0]\n"; if (-e @row[0]) { `rm @row[0]`; #get rid of crap if there is crap } print LOG `mkdir @row[0]`; # copies the right stuff from updated documents to the directories # @row[3] is the updated column if you were wondering #take off the newline chomp @row[1]; # copies stuff in the new location to the docid directory print LOG "copying from @row[1] to @row[0]\n"; print LOG `cp $old_docroot_path/@row[1] @row[0]`; #chop off the .shtml file part if it is there @row[1] =~ s/\/\w*.shtml//; print LOG `cp -p $old_docroot_path/@row[1]/*.jpg @row[0]`; print LOG `cp -p $old_docroot_path/@row[1]/*.gif @row[0]`; print LOG `cp -p $old_docroot_path/@row[1]/*.G* @row[0]`; print LOG `cp -p $old_docroot_path/@row[1]/*.J* @row[0]`; print LOG `cp -p -R $old_docroot_path/@row[1]/RCS @row[0]`; update_newpath(); } } disconnect(); } # gets the document info from the database necessary for this process sub getdocs() { if ($connection) { $statement = $connection->prepare("SELECT * FROM WEB_DOCS where docid > 2001 and docid < 3000"); $statement->execute(); } } # gets a database connection sub getconnect() { $connection = DBI->connect('dbi:Oracle:', q{clecompt/n0ts0new@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST= altair.umd.edu)(PORT=1521))(CONNECT_DATA=(SID=SLIC)))}, ""); } #disconnects from the database sub disconnect() { $connection->disconnect(); } sub update_newpath() { $newpath = $connection->quote("documents/2/@row[0]"); $docid = $connection->quote("@row[0]"); $connection->do("UPDATE web_docs SET new_location=$newpath WHERE docid=$docid"); }