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
|
<?php
/*
* SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to UNLICENSE
*/
require_once "class/database.class.php";
/*
* This file is intended to be run periodically by the local cron daemon
* and will perform tasks such as reacting to incoming emails and running
* garbage collection on the object database.
*/
/*
* Remove all orphaned objects from Scrott's object database. These are
* any object with either a parent or owner set, which doesn't exist.
* Metadata tables (members, views, etc.) are also updated to drop all rows
* related to purged objects.
*/
function gc() : void
{
$query = "CREATE TEMPORARY TABLE IF NOT EXISTS objtmp AS (SELECT * FROM objects)";
database::query($query);
/* cleanup base objects table */
$query = "DELETE FROM objects WHERE parent != '' AND parent NOT IN (SELECT guid FROM objtmp)";
database::query($query);
$query = "DELETE FROM objects WHERE owner != '' AND owner NOT IN (SELECT guid FROM objtmp)";
database::query($query);
/* cleanup sub tables */
$query = "DELETE FROM users WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM groups WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM pads WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM stages WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM issues WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM mesgs WHERE guid NOT IN (SELECT guid FROM objects)";
database::query($query);
/* cleanup metadata tables */
$query = "DELETE FROM members WHERE guid NOT IN (SELECT guid FROM objects) " .
"OR member NOT IN (SELECT guid FROM objects)";
database::query($query);
$query = "DELETE FROM views WHERE guid NOT IN (SELECT guid FROM objects) " .
"OR viewer NOT IN (SELECT guid FROM objects)";
database::query($query);
}
/* Run maintenance routines */
gc();
?>
|