summaryrefslogtreecommitdiffstats
path: root/modules-available/news/install.inc.php
blob: a60f7748ebe024272718d259d5a0e7fd56ae1bb5 (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
<?php

$dbret = array();



if (tableExists('news')) {

	/* rename news and add column "type" */
	if (!tableRename('news', 'vmchooser_pages')) {
		finalResponse(UPDATE_FAILED, "Could not rename news to vmchooser_pages: " . Database::lastError());
	}
	$dbret[] = UPDATE_DONE;
	if (false === Database::exec("ALTER TABLE `vmchooser_pages` ADD COLUMN type VARCHAR(10) CHARACTER SET ascii NOT NULL")) {
		EventLog::warning("Could not add type column to vmchooser_pages: " . Database::lastError());
	}
	if (false === Database::exec("UPDATE `vmchooser_pages` SET `type` = 'news' WHERE 1")) {
		EventLog::warning("News module update: Could not set default type to news: " . Database::lastError());
	}

}

$dbret[] = tableCreate('vmchooser_pages', "
	`newsid` int(10) unsigned NOT NULL AUTO_INCREMENT,
	`dateline` int(10) unsigned NOT NULL,
	`expires` int(10) unsigned NOT NULL,
	`locationid` int(11) NULL,
	`title` varchar(200) DEFAULT NULL,
	`content` text NOT NULL,
	`type` varchar(10) CHARACTER SET ascii NOT NULL,
	PRIMARY KEY (`newsid`),
	KEY `type` (`type`, `dateline`)
");

if (tableGetIndex('vmchooser_pages', ['dateline']) !== false) {
	Database::exec('ALTER TABLE vmchooser_pages DROP KEY `dateline`');
	Database::exec('ALTER TABLE vmchooser_pages ADD KEY `type` (`type`, `dateline`)');
	$dbret[] = UPDATE_DONE;
}
if (tableGetIndex('vmchooser_pages', ['type', 'expires', 'dateline']) === false) {
	Database::exec('ALTER TABLE vmchooser_pages ADD KEY `all3` (`type`, `expires`, `dateline`)');
	$dbret[] = UPDATE_DONE;
}
if (!tableHasColumn('vmchooser_pages', 'expires')) {
	Database::exec('ALTER TABLE vmchooser_pages ADD COLUMN `expires` int(10) unsigned NOT NULL AFTER `dateline`');
	Database::exec('UPDATE vmchooser_pages SET expires = dateline + 86400 * 3650 WHERE expires = 0'); // ~10 Years
	$dbret[] = UPDATE_DONE;
}

if (!tableHasColumn('vmchooser_pages', 'locationid')) {
	Database::exec('ALTER TABLE vmchooser_pages ADD COLUMN `locationid` int(11) NULL AFTER `expires`');
	$dbret[] = UPDATE_DONE;
}

Database::exec('ALTER TABLE vmchooser_pages MODIFY `type` varchar(10) CHARACTER SET ascii NOT NULL');

$dbret[] = tableAddConstraint('vmchooser_pages', 'locationid', 'location', 'locationid',
	'ON UPDATE CASCADE ON DELETE CASCADE');

// Create response for browser

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

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