Changeset 23479

Show
Ignore:
Timestamp:
14.12.2010 14:36:18 (9 years ago)
Author:
davidb
Message:

Shifting of code from buildaction over to better named indexaction.pm

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cgiactions/indexaction.pm

    r19293 r23479  
    3838 
    3939 
    40 my $action_table = {  
    41     "incremental-rebuild" =>  
    42     { 'compulsory-args' => [ "un", "metaname" ], 
    43       'optional-args'   => []  
    44       }, 
    45   }; 
     40 
     41 
     42 
     43 
     44# 'a' for action, and 'c' for collection are also compulsorary, and 
     45# added in automatically by baseaction 
     46 
     47my $action_table = 
     48{  
     49    "full-import"          => { 'compulsory-args' => [], 
     50                'optional-args'   => [] },  
     51     
     52    "full-buildcol"        => { 'compulsory-args' => [], 
     53                'optional-args'   => [] }, 
     54     
     55    "full-rebuild"         => { 'compulsory-args' => [], 
     56                'optional-args'   => [] }, 
     57     
     58     
     59    "incremental-import"   => { 'compulsory-args' => [], 
     60                'optional-args'   => [] },  
     61 
     62    "incremental-buildcol" => { 'compulsory-args' => [], 
     63                'optional-args'   => [] }, 
     64     
     65    "incremental-rebuild" => { 'compulsory-args' => [], 
     66                   'optional-args'   => [] } 
     67}; 
    4668 
    4769 
     
    5981 
    6082 
     83 
     84sub run_build_cmd 
     85{ 
     86    my $self = shift @_; 
     87    my ($cmd) = @_; 
     88 
     89    my $collect   = $self->{'collect'}; 
     90    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     91    my $gsdl_home  = $self->{'gsdlhome'}; 
     92 
     93    my $output = `$cmd 2>&1`; 
     94    my $status = $?; 
     95    my $report = undef; 
     96 
     97    if ($status == 0) { 
     98    $report = "Perl build successful: $cmd\n--\n"; 
     99    $report .= "$output\n"; 
     100    } 
     101    else { 
     102    $report = "Perl rebuild failed: $cmd\n--\n"; 
     103    $report .= "$output\n"; 
     104    $report .= "Exit status: " . ($status / 256) . "\n"; 
     105##  $report .= $gsdl_cgi->check_perl_home(); 
     106 
     107#   $report .= "PATH = ". $ENV{'PATH'}. "\n"; 
     108    } 
     109 
     110    return($status,$report); 
     111} 
     112 
     113sub full_import 
     114{ 
     115    my $self = shift @_; 
     116 
     117    my $username  = $self->{'username'}; 
     118    my $collect   = $self->{'collect'}; 
     119    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     120    my $gsdl_home  = $self->{'gsdlhome'}; 
     121 
     122    # Authenticate user if it is enabled 
     123    if ($baseaction::authentication_enabled) { 
     124    # Ensure the user is allowed to edit this collection 
     125    &authenticate_user($gsdl_cgi, $username, $collect); 
     126    } 
     127     
     128    # Obtain the collect dir 
     129    my $collect_dir = &util::filename_cat($gsdl_home, "collect"); 
     130 
     131    # Make sure the collection isn't locked by someone else 
     132    $self->lock_collection($username, $collect); 
     133 
     134    my $bin_script = &util::filename_cat($gsdl_home,"bin","script"); 
     135    my $cmd = "perl -S full-import.pl \"$collect\""; 
     136 
     137    my ($status,$report) = $self->run_build_cmd($cmd); 
     138    
     139    # Release the lock once it is done 
     140    $self->unlock_collection($username, $collect); 
     141 
     142    if ($status==0) { 
     143    $gsdl_cgi->generate_ok_message($report); 
     144    } 
     145    else { 
     146    $gsdl_cgi->generate_error($report); 
     147    } 
     148 
     149} 
     150 
     151 
     152sub full_buildcol 
     153{ 
     154    my $self = shift @_; 
     155 
     156    my $username  = $self->{'username'}; 
     157    my $collect   = $self->{'collect'}; 
     158    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     159    my $gsdl_home  = $self->{'gsdlhome'}; 
     160 
     161    # Authenticate user if it is enabled 
     162    if ($baseaction::authentication_enabled) { 
     163    # Ensure the user is allowed to edit this collection 
     164    &authenticate_user($gsdl_cgi, $username, $collect); 
     165    } 
     166     
     167    # Obtain the collect dir 
     168    my $collect_dir = &util::filename_cat($gsdl_home, "collect"); 
     169 
     170    # Make sure the collection isn't locked by someone else 
     171    $self->lock_collection($username, $collect); 
     172 
     173    my $bin_script = &util::filename_cat($gsdl_home,"bin","script"); 
     174    my $cmd = "perl -S full-buildcol.pl \"$collect\""; 
     175 
     176    my ($status,$report) = $self->run_build_cmd($cmd); 
     177    
     178    # Release the lock once it is done 
     179    $self->unlock_collection($username, $collect); 
     180 
     181    if ($status==0) { 
     182    $gsdl_cgi->generate_ok_message($report); 
     183    } 
     184    else { 
     185    $gsdl_cgi->generate_error($report); 
     186    } 
     187} 
     188 
     189 
     190sub full_rebuild 
     191{ 
     192    my $self = shift @_; 
     193 
     194    my $username  = $self->{'username'}; 
     195    my $collect   = $self->{'collect'}; 
     196    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     197    my $gsdl_home  = $self->{'gsdlhome'}; 
     198 
     199    # Authenticate user if it is enabled 
     200    if ($baseaction::authentication_enabled) { 
     201    # Ensure the user is allowed to edit this collection 
     202    &authenticate_user($gsdl_cgi, $username, $collect); 
     203    } 
     204     
     205    # Obtain the collect dir 
     206    my $collect_dir = &util::filename_cat($gsdl_home, "collect"); 
     207 
     208    # Make sure the collection isn't locked by someone else 
     209    $self->lock_collection($username, $collect); 
     210 
     211 
     212    my $bin_script = &util::filename_cat($gsdl_home,"bin","script"); 
     213    my $cmd = "perl -S full-rebuild.pl \"$collect\""; 
     214 
     215    my ($status,$report) = $self->run_build_cmd($cmd); 
     216    
     217    # Release the lock once it is done 
     218    $self->unlock_collection($username, $collect); 
     219 
     220    if ($status==0) { 
     221    $gsdl_cgi->generate_ok_message($report); 
     222    } 
     223    else { 
     224    $gsdl_cgi->generate_error($report); 
     225    } 
     226} 
     227 
     228 
     229 
     230sub incremental_import 
     231{ 
     232    my $self = shift @_; 
     233 
     234    my $username  = $self->{'username'}; 
     235    my $collect   = $self->{'collect'}; 
     236    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     237    my $gsdl_home  = $self->{'gsdlhome'}; 
     238 
     239    # Authenticate user if it is enabled 
     240    if ($baseaction::authentication_enabled) { 
     241    # Ensure the user is allowed to edit this collection 
     242    &authenticate_user($gsdl_cgi, $username, $collect); 
     243    } 
     244     
     245    # Obtain the collect dir 
     246    my $collect_dir = &util::filename_cat($gsdl_home, "collect"); 
     247 
     248    # Make sure the collection isn't locked by someone else 
     249    $self->lock_collection($username, $collect); 
     250 
     251 
     252    my $bin_script = &util::filename_cat($gsdl_home,"bin","script"); 
     253    my $cmd = "perl -S incremental-import.pl \"$collect\""; 
     254 
     255    my ($status,$report) = $self->run_build_cmd($cmd); 
     256    
     257    # Release the lock once it is done 
     258    $self->unlock_collection($username, $collect); 
     259 
     260    if ($status==0) { 
     261    $gsdl_cgi->generate_ok_message($report); 
     262    } 
     263    else { 
     264    $gsdl_cgi->generate_error($report); 
     265    } 
     266} 
     267 
     268 
     269sub incremental_buildcol 
     270{ 
     271    my $self = shift @_; 
     272 
     273    my $username  = $self->{'username'}; 
     274    my $collect   = $self->{'collect'}; 
     275    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     276    my $gsdl_home  = $self->{'gsdlhome'}; 
     277 
     278    # timestamp could turn out to be useful, but not used just now 
     279 
     280    # Authenticate user if it is enabled 
     281    if ($baseaction::authentication_enabled) { 
     282    # Ensure the user is allowed to edit this collection 
     283    &authenticate_user($gsdl_cgi, $username, $collect); 
     284    } 
     285     
     286    # Obtain the collect dir 
     287    my $collect_dir = &util::filename_cat($gsdl_home, "collect"); 
     288 
     289    # Make sure the collection isn't locked by someone else 
     290    $self->lock_collection($username, $collect); 
     291 
     292 
     293    my $bin_script = &util::filename_cat($gsdl_home,"bin","script"); 
     294    my $cmd = "perl -S incremental-buildcol.pl \"$collect\""; 
     295 
     296    my ($status,$report) = $self->run_build_cmd($cmd); 
     297    
     298    # Release the lock once it is done 
     299    $self->unlock_collection($username, $collect); 
     300 
     301    if ($status==0) { 
     302    $gsdl_cgi->generate_ok_message($report); 
     303    } 
     304    else { 
     305    $gsdl_cgi->generate_error($report); 
     306    } 
     307} 
     308 
     309 
    61310sub incremental_rebuild 
    62311{ 
     
    69318 
    70319    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
     320    my $gsdl_home  = $self->{'gsdlhome'}; 
     321 
     322    # Authenticate user if it is enabled 
     323    if ($baseaction::authentication_enabled) { 
     324    # Ensure the user is allowed to edit this collection 
     325    &authenticate_user($gsdl_cgi, $username, $collect); 
     326    } 
     327     
     328    # Make sure the collection isn't locked by someone else 
     329    $self->lock_collection($username, $collect); 
     330 
     331    my $cmd = "perl -S incremental-rebuild.pl \"$collect\""; 
     332 
     333    my ($status,$report) = $self->run_build_cmd($cmd); 
     334    
     335    # Release the lock once it is done 
     336    $self->unlock_collection($username, $collect); 
     337 
     338    if ($baseaction::mail_enabled) { 
     339    $self->send_mail("Remote Greenstone building event", "Incremental building of collection '$collect' complete."); 
     340    } 
     341 
     342    if ($status==0) { 
     343    $gsdl_cgi->generate_ok_message($report); 
     344    } 
     345    else { 
     346    $gsdl_cgi->generate_error($report); 
     347    } 
     348} 
     349 
     350 
     351 
     352 
     353sub incremental_rebuild_orig 
     354{ 
     355    my $self = shift @_; 
     356 
     357    my $username  = $self->{'username'}; 
     358    my $collect   = $self->{'collect'}; 
     359    my $timestamp = $self->{'timestamp'}; 
     360    my $site      = $self->{'site'}; 
     361 
     362    my $gsdl_cgi  = $self->{'gsdl_cgi'}; 
    71363 
    72364    # timestamp could turn out to be useful, but not used just now 
     
    82374 
    83375    $self->run_script($collect,$site,"incremental-rebuild.pl"); 
    84  
    85376 
    86377    if ($baseaction::mail_enabled) { 
     
    91382 
    92383 
     384 
     385 
     386 
    933871;