# Tridion recursor # Richard Fairhurst 24.09.2004 / 10.1.2005 # perl recurse.pl action tcmid -[d][2|4|6][i] # action = publish|get # tcmid = CSV list of Tridion URIs # options: # d = do not recurse # 2|4|6= priority # i = save files by id rather than by name # To do: unpublish # publish to correct target (at present, it always assumes Waterscape) use Tridion::BusinessConnector; my $bc = new Tridion::BusinessConnector( hostname => 'tridion.waterscape.com', username => 'BWCMS02\rfairh', password => 'tr1d10n' ); $recurse=1; $priority=4; $files='name'; $spaces=0; ($action,$ids,$opts)=@ARGV; if ($opts=~/^\-/) { if ($opts=~/([246])/) { $priority=$1; } if ($opts=~/d/) { $recurse=0; } if ($opts=~/i/) { $files='tcm'; } } foreach $id (split(/,/,$ids)) { Process_Dir($id); } # ---- Process_Dir(tcmID) sub Process_Dir { my $tcmid=shift; my @array; my $id; my $title; my $type; my $item; my $fname; die("Invalid TCM ID\n") unless ($tcmid =~ /^tcm:\d+(\-\d+)*$/); $item = $bc->GetListItems($tcmid); @array=split(/\n/,$item->toString(1)); foreach $line (@array) { if ($line=~//) { $id=$1; $title=$2; $type=$3; print ' ' x $spaces; print "$id, $title\n"; if ($files eq 'tcm') {$fname=substr($id,4);} else {$fname=$title;} $fname=~s/\//\\/g; $fname=~s/&#x..;//g; # Process actions if ($action eq 'get') { if ($type==2 or $type==4) { mkdir $fname; } else { if (open (OUTFILE, ">$fname")) { $item=$bc->GetItem($id); print OUTFILE $item->toString(1); close OUTFILE; } else { print "*** Can't write $fname\n"; } } } elsif ($action eq 'publish' and $type!=2 and $type!=4) { $item=$bc->PublishItem($id,$priority); } # Recursive if ($recurse and ($type==2 or $type==4)) { if ($action eq 'get') { chdir $fname; } $spaces++; Process_Dir($id); $spaces--; if ($action eq 'get') { chdir '..'; } } } } }