summaryrefslogtreecommitdiffstats
path: root/modules-available/eventlog/install.inc.php
blob: def608aa13998109310c3d8a8c2e6e716847cb9e (plain) (blame)
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
<?php

$res = array();

$res[] = tableCreate('eventlog', "
`logid` int(10) unsigned NOT NULL AUTO_INCREMENT,
`dateline` int(10) unsigned NOT NULL,
`logtypeid` varchar(30) NOT NULL,
`description` varchar(255) NOT NULL,
`extra` TEXT NOT NULL,
PRIMARY KEY (`logid`),
KEY `dateline` (`dateline`),
KEY `logtypeid` (`logtypeid`,`dateline`)
");

$res[] = tableCreate('notification_rule', '
  `ruleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `description` text,
  `type` varchar(40) CHARACTER SET ascii NOT NULL,
  `datafilter` blob NOT NULL,
  `subject` varchar(200) NOT NULL,
  `message` text NOT NULL,
  PRIMARY KEY (`ruleid`),
  KEY `type` (`type`)
');

$res[] = tableCreate('notification_backend', '
  `transportid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` varchar(100) NOT NULL,
  `description` text,
  `data` blob,
  PRIMARY KEY (`transportid`),
  KEY (`title`)
');

$res[] = tableCreate('notification_rule_x_transport', '
  `ruleid` int(10) UNSIGNED NOT NULL,
  `transportid` int(10) UNSIGNED NOT NULL,
  PRIMARY KEY (`ruleid`, `transportid`),
  KEY (`transportid`)
');

$res[] = tableCreate('notification_sample', "
  `sampleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `dateline` int(10) UNSIGNED NOT NULL,
  `extended` tinyint(1) NOT NULL DEFAULT '0',
  `type` varchar(40) CHARACTER SET ascii NOT NULL,
  `data` mediumblob,
  KEY (`type`, `dateline`),
  KEY (`extended`),
  PRIMARY KEY (`sampleid`)
");

// Update path

if (!tableHasColumn('eventlog', 'extra')) {
	if (Database::exec("ALTER TABLE `eventlog` ADD `extra` TEXT NOT NULL") === false) {
		finalResponse(UPDATE_FAILED, 'Could not add extra to eventlog: ' . Database::lastError());
	}
	$res[] = UPDATE_DONE;
}

// 2021-06-15: Add constraints to filter/backend stuff
$res[] = tableAddConstraint('notification_rule_x_transport', 'ruleid',
	'notification_rule', 'ruleid', 'ON UPDATE CASCADE ON DELETE CASCADE');
$res[] = tableAddConstraint('notification_rule_x_transport', 'transportid',
	'notification_backend', 'transportid', 'ON UPDATE CASCADE ON DELETE CASCADE');

// 2022-07-20: Add flag to see if notification_sample has been extended
if (!tableHasColumn('notification_sample', 'extended')) {
	if (Database::exec("ALTER TABLE notification_sample
    		ADD COLUMN `extended` tinyint(1) NOT NULL DEFAULT '0',
    		ADD KEY (`extended`),
    		ADD COLUMN `sampleid` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    		ADD PRIMARY KEY (`sampleid`)") === false) {
		finalResponse(UPDATE_FAILED, 'Could not add extended flag to notification_sample: ' . Database::lastError());
	}
	$res[] = UPDATE_DONE;
}

// Create response for browser

if (in_array(UPDATE_DONE, $res)) {
	finalResponse(UPDATE_DONE, 'Tables created successfully');
}

finalResponse(UPDATE_NOOP, 'Everything already up to date');