Diff for /loncom/publisher/lonpublisher.pm between versions 1.88 and 1.89

version 1.88, 2002/08/07 19:59:06 version 1.89, 2002/08/09 17:57:48
Line 75  use Apache::loncacc; Line 75  use Apache::loncacc;
 use DBI;  use DBI;
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::loncommon();  use Apache::loncommon();
   use Apache::lonmysql;
   
 my %addid;  my %addid;
 my %nokey;  my %nokey;
Line 467  sub fix_ids_and_indices { Line 468  sub fix_ids_and_indices {
     return ($outstring,%allow);      return ($outstring,%allow);
 }  }
   
   #########################################
   #########################################
   
   =pod
   
   =item store_metadata
   
   Store the metadata in the metadata table in the loncapa database.
   Uses lonmysql to access the database.
   
   Inputs: \%metadata
   
   Returns: (error,status).  error is undef on success, status is undef on error.
   
   =cut
   
   #########################################
   #########################################
   sub store_metadata {
       my %metadata = %{shift()};
       my $error;
       # Determine if the table exists
       my $status = &Apache::lonmysql::check_table('metadata');
       if (! defined($status)) {
           $error='<font color="red">WARNING: Cannot connect to '.
               'database!</font>';
           &Apache::lonnet::logthis($error);
           return ($error,undef);
       }
       if ($status == 0) {
           # It would be nice to actually create the table....
           $error ='<font color="red">WARNING: The metadata table does not '.
               'exist in the LON-CAPA database.</font>';
           &Apache::lonnet::logthis($error);
           return ($error,undef);
       }
       # Remove old value from table
       $status = &Apache::lonmysql::remove_from_table
           ('metadata','url',$metadata{'url'});
       if (! defined($status)) {
           $error = '<font color="red">Error when removing old values from '.
               'metadata table in LON-CAPA database.</font>';
           &Apache::lonnet::logthis($error);
           return ($error,undef);
       }
       # Store data in table.
       $status = &Apache::lonmysql::store_row('metadata',\%metadata);
       if (! defined($status)) {
           $error='<font color="red">Error occured storing new values in '.
               'metadata table in LON-CAPA database</font>';
           &Apache::lonnet::logthis($error);
           return ($error,undef);
       }
       return (undef,$status);
   }
   
 sub publish {  sub publish {
   
     my ($source,$target,$style)=@_;      my ($source,$target,$style)=@_;
Line 858  sub phasetwo { Line 915  sub phasetwo {
      }       }
   
 # -------------------------------- Synchronize entry with SQL metadata database  # -------------------------------- Synchronize entry with SQL metadata database
   my $warning;      my $warning;
       $metadatafields{'url'} = $distarget;
   unless ($metadatafields{'copyright'} eq 'priv') {      $metadatafields{'version'} = 'current';
       unless ($metadatafields{'copyright'} eq 'priv') {
     my $dbh;          my ($error,$success) = &store_metadata(\%metadatafields);
     {          if (! $success) {
  unless (              $scrout.='<p>Synchronized SQL metadata database';
  $dbh = DBI->connect("DBI:mysql:loncapa","www",              print $logfile "\nSynchronized SQL metadata database";
     $Apache::lonnet::perlvar{'lonSqlAccess'},{ RaiseError =>0,PrintError=>0})          } else {
  ) {               $warning.=$error;
     $warning='<font color=red>WARNING: Cannot connect to '.              print $logfile "\n".$error;
  'database!</font>';          }
  }      } else {
  else {          $scrout.='<p>Private Publication - did not synchronize database';
     my %sqldatafields;          print $logfile "\nPrivate: Did not synchronize data into ".
     $sqldatafields{'url'}=$distarget;              "SQL metadata database";
     my $sth=$dbh->prepare(  
   'delete from metadata where url like binary'.  
   '"'.$sqldatafields{'url'}.'"');  
     $sth->execute();  
     foreach ('title','author','subject','keywords','notes','abstract',  
      'mime','language','creationdate','lastrevisiondate','owner',  
      'copyright') {  
  my $field=$metadatafields{$_}; $field=~s/\"/\'\'/g;   
  $sqldatafields{$_}=$field;  
     }  
       
     $sth=$dbh->prepare('insert into metadata values ('.  
        '"'.delete($sqldatafields{'title'}).'"'.','.  
        '"'.delete($sqldatafields{'author'}).'"'.','.  
        '"'.delete($sqldatafields{'subject'}).'"'.','.  
        '"'.delete($sqldatafields{'url'}).'"'.','.  
        '"'.delete($sqldatafields{'keywords'}).'"'.','.  
        '"'.'current'.'"'.','.  
        '"'.delete($sqldatafields{'notes'}).'"'.','.  
        '"'.delete($sqldatafields{'abstract'}).'"'.','.  
        '"'.delete($sqldatafields{'mime'}).'"'.','.  
        '"'.delete($sqldatafields{'language'}).'"'.','.  
        '"'.  
        sqltime(delete($sqldatafields{'creationdate'}))  
        .'"'.','.  
        '"'.  
        sqltime(delete(  
        $sqldatafields{'lastrevisiondate'})).'"'.','.  
        '"'.delete($sqldatafields{'owner'}).'"'.','.  
        '"'.delete(  
        $sqldatafields{'copyright'}).'"'.')');  
     $sth->execute();  
     $dbh->disconnect;  
     $scrout.='<p>Synchronized SQL metadata database';  
     print $logfile "\nSynchronized SQL metadata database";  
  }  
     }      }
   
 } else {  
     $scrout.='<p>Private Publication - did not synchronize database';  
     print $logfile "\nPrivate: Did not synchronize data into ".  
  "SQL metadata database";  
 }  
 # ----------------------------------------------------------- Copy old versions  # ----------------------------------------------------------- Copy old versions
         
 if (-e $target) {  if (-e $target) {
Line 1210  unless ($ENV{'form.phase'} eq 'two') { Line 1225  unless ($ENV{'form.phase'} eq 'two') {
 1;  1;
 __END__  __END__
   
 =head1 NAME  =pod
   
 Apache::lonpublisher - Publication Handler  
   
 =head1 SYNOPSIS  
   
 Invoked by /etc/httpd/conf/srm.conf:  
   
  <Location /adm/publish>  
  PerlAccessHandler       Apache::lonacc  
  SetHandler perl-script  
  PerlHandler Apache::lonpublisher  
  ErrorDocument     403 /adm/login  
  ErrorDocument     404 /adm/notfound.html  
  ErrorDocument     406 /adm/unauthorized.html  
  ErrorDocument  500 /adm/errorhandler  
  </Location>  
   
 =head1 INTRODUCTION  
   
 This module publishes a file.  This involves gathering metadata,  
 versioning the file, copying file from construction space to  
 publication space, and copying metadata from construction space  
 to publication space.  
   
 This is part of the LearningOnline Network with CAPA project  
 described at http://www.lon-capa.org.  
   
 =head1 HANDLER SUBROUTINE  
   
 This routine is called by Apache and mod_perl.  
   
 =over 4  
   
 =item *  
   
 Get query string for limited number of parameters  
   
 =item *  
   
 Check filename  
   
 =item *  
   
 File is there and owned, init lookup tables  
   
 =item *  
   
 Start page output  
   
 =item *  
   
 Individual file  
   
 =item *  
   
 publish from $thisfn to $thistarget with $thisembstyle  
   
 =back  
   
 =head1 OTHER SUBROUTINES  
   
 =over 4  
   
 =item *  
   
 metaeval() : Evaluate string with metadata  
   
 =item *  
   
 metaread() : Read a metadata file  
   
 =item *  
   
 sqltime() : convert 'time' format into a datetime sql format  
   
 =item *  
   
 textfield() : form field  
   
 =item *  
   
 hiddenfield() : form field  
   
 =item *  
   
 selectbox() : form field  
   
 =item *  
   
 urlfixup() : fixup URL (Publication Step One)  
   
 =item *  
   
 publish() : publish (Publication Step One)  
   
 =item *  
   
 phasetwo() : render second interface showing status of publication steps  
 (Publication Step Two)  
   
 =back  =back
   
 =cut  =cut
   

Removed from v.1.88  
changed lines
  Added in v.1.89


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>