-
Notifications
You must be signed in to change notification settings - Fork 1
/
deArchiveCSPosts.pl
executable file
·95 lines (76 loc) · 2.99 KB
/
deArchiveCSPosts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/data/wre/prereqs/bin/perl
use lib "/data/WebGUI/lib";
use strict;
our $VERSION = "0.0.1";
use Getopt::Long;
use WebGUI::Session;
use WebGUI::Asset;
use WebGUI::VersionTag;
use WebGUI::Asset::Wobject::Collaboration;
my ($configFiles,$configFile,$allSites,$updateTime,$webguiPath);
my $session = start();
for my $key(keys %$configFiles){
if($allSites || $key eq $configFile){
updatePosts($key);
}
}
#-------------------------------------------------
sub updatePosts {
my $config = shift;
print "working on $config .. \n";
my $session = WebGUI::Session->open($webguiPath,$config);
$session->user({userId=>3});
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name => "Updating to un-archive posts in the last ".($updateTime/86400) ." days "});
my @css = $session->db->buildArray('select a.url from assetData a, Collaboration c where c.assetId = a.assetId');
my %hcss;
map($hcss{$_} = 1,@css);
for my $cs(keys %hcss){
print "\t$cs\n";
my $asset = WebGUI::Asset->newByUrl($session, $cs);
next unless defined $asset;
my $epoch = $session->datetime->time();
my $archiveDate = $epoch - $updateTime;
my $sql = "select asset.assetId, assetData.revisionDate from Post left join asset on asset.assetId=Post.assetId
left join assetData on Post.assetId=assetData.assetId and Post.revisionDate=assetData.revisionDate
where Post.revisionDate>? and assetData.status='archived' and asset.state='published'
and Post.threadId=Post.assetId and asset.lineage like ?";
my $b = $session->db->read($sql,[$archiveDate, $asset->get("lineage").'%']);
while (my ($id, $version) = $b->array) {
my $thread = WebGUI::Asset->new($session, $id, "WebGUI::Asset::Post::Thread", $version);
my $archiveIt = 1;
foreach my $post (@{$thread->getPosts}) {
$archiveIt = 0 if (defined $post && $post->get("revisionDate") < $archiveDate);
}
$thread->unarchive if ($archiveIt);
}
$b->finish;
}
$versionTag->commit;
$session->var->end;
$session->close;
print "finished\n";
}
#-------------------------------------------------
sub usage {
print <<USAGE;
Usage: $0 [ --allsites | --config-file=... ] [ --time-since=(days before now to dearchive, defaults to 5 years) ] [ --webgui-path= ]
USAGE
exit 1;
}
#-------------------------------------------------
sub start {
$| = 1; #disable output buffering
GetOptions(
'allsites' => \$allSites,
'config-file=s' => \$configFile,
'time-since=s' => \$updateTime,
'webgui-path=s' => \$webguiPath,
);
$webguiPath = "/data/WebGUI" if(! defined $webguiPath);
$updateTime = (defined $updateTime) ? ($updateTime*86400) : 157680000;
if((!defined $allSites && !defined $configFile)) {
usage();
}
$configFiles = WebGUI::Config->readAllConfigs($webguiPath);
}