use lib "../lib"; use strict; use Getopt::Long; use WebGUI::Session; use WebGUI::Utility; #-------------------------------------------------------------------- # csArchiver is Copyright 2008 by Oqapi Software BV #-------------------------------------------------------------------- # This software is GPLv2 licenced. The GPLv2 licence can be obtained # at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html and also # comes with WebGUI in the docs directory. #-------------------------------------------------------------------- # http://www.oqapi.nl info@oqapi.nl #-------------------------------------------------------------------- my $session = start(); my ($list, $archive, $unarchive, $doit, $parentAssetId, $includePending, $setArchivalPeriod ); $parentAssetId = WebGUI::Asset->getRoot( $session )->getId unless $parentAssetId; if ($list) { list( $session, $parentAssetId ); } elsif ($doit && $archive) { archivePosts( $session, $parentAssetId ); } elsif ($doit && $unarchive) { unarchivePosts( $session, $parentAssetId ); } elsif ($doit && $setArchivalPeriod) { setArchiveAfter( $session, $parentAssetId, $setArchivalPeriod ); } else { print help(); } finish($session); #------------------------------------------------- sub getAssets { my $session = shift; my $parentAssetId = shift; my $classes = shift; my $includePending = shift; my $rules; my $startAsset = WebGUI::Asset->newByDynamicClass( $session, $parentAssetId ); die "Could not instantciate parent asset (id: [$parentAssetId]" unless $startAsset; $rules->{ returnObjects } = 1; $rules->{ includeOnlyClasses } = $classes; $rules->{ statusToInclude } = $includePending ? [ qw/approved pending archived/ ] : [ qw/approved archived/ ]; return $startAsset->getLineage( ['self', 'descendants'], $rules ); } #------------------------------------------------- sub getPosts { my $session = shift; my $parentAssetId = shift; return getAssets( $session, $parentAssetId, [ qw/WebGUI::Asset::Post WebGUI::Asset::Post::Thread/ ], $includePending ); } #------------------------------------------------- sub getCSs { my $session = shift; my $parentAssetId = shift; return getAssets( $session, $parentAssetId, [ qw/WebGUI::Asset::Wobject::Collaboration/ ], $includePending ); } #------------------------------------------------- sub list { my $session = shift; my $parentAssetId = shift; print "Affected collaboration systems:\n\t"; print join "\n\t", map { $_->get('title')." (url: ".$_->getUrl.", assetId: ".$_->getId.")" } @{ getCSs($session, $parentAssetId) }; print "\n\n"; print "Affected posts:\n\t"; print join "\n\t", map { $_->get('title')." (url: ".$_->getUrl.", assetId: ".$_->getId.")" } @{ getPosts($session, $parentAssetId) }; print "\n"; } #------------------------------------------------- sub archivePosts { my $session = shift; my $parentAssetId = shift; foreach my $asset (@{ getPosts( $session, $parentAssetId ) }) { print "\tArchiving ".$asset->get('title')." (url: ".$asset->getUrl.", assetId: ".$asset->getId.")\n"; $asset->update({ status => 'archived' }); } } #------------------------------------------------- sub unarchivePosts { my $session = shift; my $parentAssetId = shift; foreach my $asset (@{ getPosts( $session, $parentAssetId ) }) { print "\tUnarchiving ".$asset->get('title')." (url: ".$asset->getUrl.", assetId: ".$asset->getId.")\n"; $asset->update({ status => 'approved' }); } } #------------------------------------------------- sub setArchiveAfter { my $session = shift; my $parentAssetId = shift; my $archiveAfter = shift; my ($interval, $units) = $archiveAfter =~ m/^(\d+)(\w+)$/; die "No valid archival period given [$interval,$units]." unless ( $interval && isIn(lc($units), qw/years months weeks days hours minutes seconds/) ); my $archivalPeriodInSeconds = $session->datetime->intervalToSeconds( $interval, $units ); foreach my $asset (@{ getCSs( $session, $parentAssetId ) }) { print "\tSetting archive after period for CS ".$asset->get('title')." (url: ".$asset->getUrl.", assetId: ".$asset->getId.")\n"; $asset->update({ archiveAfter => $archivalPeriodInSeconds, }); } } #------------------------------------------------- sub help { return < \$configFile, 'list' => \$list, 'archive' => \$archive, 'unarchive' => \$unarchive, 'doit' => \$doit, 'parentAssetId=s' => \$parentAssetId, 'includePending' => \$includePending, 'setArchivalPeriod=s' => \$setArchivalPeriod, ); print help and exit unless $configFile; my $session = WebGUI::Session->open("..",$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; }