#!/usr/bin/env perl #------------------------------------------------------------------- # WebGUI is Copyright 2001-2009 Plain Black Corporation. #------------------------------------------------------------------- # Please read the legal notices (docs/legal.txt) and the license # (docs/license.txt) that came with this distribution before using # this software. #------------------------------------------------------------------- # http://www.plainblack.com info@plainblack.com #------------------------------------------------------------------- use strict; use File::Basename (); use File::Spec; my $webguiRoot; BEGIN { $webguiRoot = File::Spec->rel2abs(File::Spec->catdir(File::Basename::dirname(__FILE__), File::Spec->updir)); unshift @INC, File::Spec->catdir($webguiRoot, 'lib'); } $|++; # disable output buffering our ($configFile, $help, $man); use Pod::Usage; use Getopt::Long; use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Exception; use WebGUI::Workflow::Cron; use WebGUI::Utility qw/isIn/; # Get parameters here, including $help GetOptions( 'configFile=s' => \$configFile, 'help' => \$help, 'man' => \$man, ); pod2usage( verbose => 1 ) if $help; pod2usage( verbose => 2 ) if $man; pod2usage( msg => "Must specify a config file!" ) unless $configFile; my $session = start( $webguiRoot, $configFile ); # Do your work here restoreDefaultCronJobs($session); restoreCsCronJobs($session); finish($session); #---------------------------------------------------------------------------- # Your sub here #---------------------------------------------------------------------------- # Describe what our function does sub restoreDefaultCronJobs { my $session = shift; # and here's our code print "\tRestore missing default cron jobs that may have been deleted... "; my $tasks = WebGUI::Workflow::Cron->getAllTasks($session); my @taskIds = map { $_->getId } @{ $tasks }; if (! isIn('pbcron0000000000000001', @taskIds)) { print "\n\t\tRestoring Daily Maintenance Task... "; WebGUI::Workflow::Cron->create($session, { title => "Daily Maintenance", dayOfMonth => '*', enabled => 1, monthOfYear => '*', runOnce => 0, dayOfWeek => '*', minuteOfHour => 30, workflowId => 'pbworkflow000000000001', hourOfDay => 23, priority => 3, }, 'pbcron0000000000000001'); } if (! isIn('pbcron0000000000000002', @taskIds)) { print "\n\t\tRestoring Weekly Maintenance Task... "; WebGUI::Workflow::Cron->create($session, { title => "Weekly Maintenance", dayOfMonth => '*', enabled => 1, monthOfYear => '*', runOnce => 0, dayOfWeek => '0', minuteOfHour => 30, workflowId => 'pbworkflow000000000002', hourOfDay => 1, priority => 3, }, 'pbcron0000000000000002'); } if (! isIn('pbcron0000000000000003', @taskIds)) { print "\n\t\tRestoring Hourly Maintenance Task... "; WebGUI::Workflow::Cron->create($session, { title => "Hourly Maintenance", dayOfMonth => '*', enabled => 1, monthOfYear => '*', runOnce => 0, dayOfWeek => '*', minuteOfHour => 15, workflowId => 'pbworkflow000000000004', hourOfDay => '*', priority => 3, }, 'pbcron0000000000000003'); } if (! isIn('pbcron0000000000000004', @taskIds)) { print "\n\t\tRestoring Email Delivery Task... "; WebGUI::Workflow::Cron->create($session, { title => "Send Queued Email Messages Every 5 Minutes", dayOfMonth => '*', enabled => 1, monthOfYear => '*', runOnce => 0, dayOfWeek => '*', minuteOfHour => '*/5', workflowId => 'pbworkflow000000000007', hourOfDay => '*', priority => 3, }, 'pbcron0000000000000004'); } print "DONE!\n"; } #---------------------------------------------------------------------------- # Describe what our function does sub restoreCsCronJobs { my $session = shift; print "\tRestore missing Collaboration System cron jobs that may have been deleted... "; my $i18n = WebGUI::International->new($session, "Asset_Collaboration"); my $getCs = WebGUI::Asset::Wobject::Collaboration->getIsa($session); CS: while (1) { my $cs = eval { $getCs->(); }; if (my $e = Exception::Class->caught()) { $session->log->error($@); next CS; } last CS unless $cs; ##Do something useful with $product my $cron = undef; if ($cs->get("getMailCronId")) { $cron = WebGUI::Workflow::Cron->new($session, $cs->get("getMailCronId")); } next CS if $cron; $cron = WebGUI::Workflow::Cron->create($session, { title => $cs->getTitle." ".$i18n->get("mail"), minuteOfHour => "*/".($cs->get("getMailInterval")/60), className => (ref $cs), methodName => "new", parameters => $cs->getId, workflowId => "csworkflow000000000001" }); $cs->update({getMailCronId=>$cron->getId}); if ($cs->get("getMail")) { $cron->set({enabled=>1,title=>$cs->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($cs->get("getMailInterval")/60)}); } else { $cron->set({enabled=>0,title=>$cs->getTitle." ".$i18n->get("mail"), minuteOfHour=>"*/".($cs->get("getMailInterval")/60)}); } } print "DONE!\n"; } #---------------------------------------------------------------------------- sub start { my $webguiRoot = shift; my $configFile = shift; my $session = WebGUI::Session->open($webguiRoot,$configFile); $session->user({userId=>3}); ## If your script is adding or changing content you need these lines, otherwise leave them commented # # my $versionTag = WebGUI::VersionTag->getWorking($session); # $versionTag->set({name => 'Name Your Tag'}); # ## return $session; } #---------------------------------------------------------------------------- sub finish { my $session = shift; ## If your script is adding or changing content you need these lines, otherwise leave them commented # # my $versionTag = WebGUI::VersionTag->getWorking($session); # $versionTag->commit; ## $session->var->end; $session->close; } __END__ =head1 NAME utility - A template for WebGUI utility scripts =head1 SYNOPSIS utility --configFile config.conf ... utility --help =head1 DESCRIPTION This WebGUI utility script helps you... =head1 ARGUMENTS =head1 OPTIONS =over =item B<--configFile config.conf> The WebGUI config file to use. Only the file name needs to be specified, since it will be looked up inside WebGUI's configuration directory. This parameter is required. =item B<--help> Shows a short summary and usage =item B<--man> Shows this document =back =head1 AUTHOR Copyright 2001-2009 Plain Black Corporation. =cut #vim:ft=perl