-
Notifications
You must be signed in to change notification settings - Fork 1
/
indexer.php
47 lines (41 loc) · 1.84 KB
/
indexer.php
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
<?php
$verbose = false;
if (isset($argv[1]) && $argv[1]=="-v") $verbose=true;
$archiveThisPad = null;
if (isset($argv[1]) && $argv[1]=="-A") $archiveThisPad=$argv[2];
include "init.php";
$instance = new EtherpadLiteClient(API_KEY, API_URL);
$sessions = array();
$updategroupId = $db->prepare("UPDATE padman_group SET group_id=? WHERE group_mapper=?");
$updateQ = $db->prepare("UPDATE padman_pad_cache SET last_edited=FROM_UNIXTIME(?), access_level=?
WHERE id=? LIMIT 1");
if (ARCHIVE_AFTER_MONTHS)
$archive_before = (new DateTime(ARCHIVE_AFTER_MONTHS." months ago"))->gettimestamp();
else
$archive_before = false;
$groups = sql("SELECT * FROM padman_group" , []);
foreach($groups as $group) {
$pads = sql("SELECT * FROM padman_pad_cache WHERE group_alias=? AND is_archived=0", [$group["group_alias"]]);
foreach($pads as $pad) {
$padID = ep_pad_id($pad);
if($verbose)echo "$padID\n";
try {
$tmpTimest = $instance->getLastEdited($padID);
$tmpPublic = $instance->getPublicStatus($padID);
$timestamp = floor($tmpTimest->lastEdited/1000);
$accessLevel = $tmpPublic->publicStatus ? 1 : 0;
if($verbose)echo " $timestamp $accessLevel\n";
dump_pad_to_file($padID, $pad['pad_name'], $group);
if(($archive_before && $timestamp && ($timestamp < $archive_before)) || $archiveThisPad === $padID) {
echo "Archiving the pad $padID $pad[pad_name] $group[group_alias] \n";
$ok=$instance->deletePad($padID);
echo "deletePad($padID);\n";
update_pad($pad['id'], [ "is_archived" => 1, "group_mapper" => "" ]);
}
$updateQ->execute([ $timestamp, $accessLevel, $pad["id"] ]);
} catch(Exception $ex) {
fprintf(STDERR, "%s", "Pad $padID found in DB, but not in Etherpad! Please check!\n$ex\n");
$updateQ->execute([ 0, 999, $pad["id"] ]);
}
}
}