b7d8ee07e3e088736c8283d218b21ca0b2a6ee8b
[atutor.git] / mods / wiki / tools / cron.d / S64trashcan.php
1 <?php
2 /*
3    Any database entry (_TEXT and _BINARY) that is linked on "TrashCan"
4    will be deleted after it hasn't been removed in over a month from there.
5    
6    This is more useful for Intranats, for public Wikis is makes more sense
7    to stick to the "DeletedPage" page election method, because the TrashCan
8    entries get invalid if an entry was removed for even for only one version
9    in the configured timespam (OTH this may be a good voting method).
10    
11    You can however use the TrashCan for unwanted contributions and things
12    like clearing the SandBox from time to time automatically. But don't
13    forget that only the versions up to the $keptpages timeframe get purged.
14 */
15
16 // define("TRASHCAN_ENGAGE", 14);   // in days, how long something must be listed on the special "TrashCan" page before that deletion request is valid
17
18
19 #-- ok, let's go
20 if (defined("TRASHCAN_ENGAGE") && ($last = TRASHCAN_ENGAGE)) {
21
22    echo "[$cron]: checking out lasted entries from TrashCan for deletion:\n";
23
24    #-- get TrashCan page latest version
25    $data = ewiki_db::GET($id="TrashCan");
26    $version = $row["version"];
27    $listed = explode("\n", trim($data["refs"]));
28
29    #-- look trough all previous revisions until $last timeframe,
30    #   and compare {refs} for constant listing of all entries
31    while ($data = ewiki_db::GET($id, --$version)) {
32
33       #-- timeframe
34       if (time() >= $row["lastmodified"] + $last) {
35          break;  // done with version comparisions
36       }
37
38       #-- remove anything that isn't listed in all TrashCan page versions
39       $cmplist = explode("\n", trim($data["refs"]));
40       $listed = array_intersect($listed, $cmplist);
41    }
42
43    #-- delete anything that's still in the purge list
44    foreach ($listed as $id) {
45
46       #-- walk through all versions
47       if ($row = ewiki_db::GET($id)) {
48          echo "   $id";
49       
50          $version = $row["version"];
51          for ($version; $version >= 1; $version--) {
52
53             #-- don't kill revisions that have borought lifetime ($keptpages)
54             if ($row["lastmodified"] >= $keepuntil) {
55                continue;
56             }
57             
58             #-- oh, so sad!
59             echo " [$version]";
60             ewiki_db::DELETE($id, $version);
61
62          }
63          
64          echo "\n";
65       }
66    }
67 }
68
69
70 ?>