-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_articles.php
74 lines (56 loc) · 1.92 KB
/
update_articles.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
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
<?php
include_once ('classes/Database.php');
include_once ('user/local.php');
# database options
$db = Database::getDB();
$mysqli = $db->getCon();
# line endings
if (php_sapi_name() == 'cli') {
$line_end = "\n";
} else {
$line_end = '<br>' . "\n";
}
# rename news fields
$sql = 'ALTER TABLE `news`
CHANGE `ID` `id` INT( 11 ) NOT NULL AUTO_INCREMENT ,
CHANGE `Autor` `author` SMALLINT( 6 ) NOT NULL ,
CHANGE `Titel` `title` VARCHAR( 128 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
CHANGE `Inhalt` `content` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci ,
CHANGE `Datum` `created` DATETIME NOT NULL ,
CHANGE `enable` `public` TINYINT( 1 ) NOT NULL ,
CHANGE `Hits` `hits` INT( 11 ) NOT NULL ,
ADD `edited` DATETIME NOT NULL ;';
$result = $mysqli->multi_query($sql);
if (!$result) {
echo '<pre>'; print_r($mysqli); echo '</pre>';
echo 'could not change fields in table news' . $line_end;
} else {
echo 'changed fields in table news' . $line_end;
}
# drop deprecated fields from news table
$sql = 'ALTER TABLE `news`
DROP `Status`;';
$result = $mysqli->multi_query($sql);
if (!$result) {
echo 'could not change fields for table news' . $line_end;
} else {
echo 'changed fields for table news' . $line_end;
}
# drop deprecated fields from news table
$sql = 'UPDATE `news`
SET `edited` = `created`;';
$result = $mysqli->multi_query($sql);
if (!$result) {
echo 'could not update edited date in table news' . $line_end;
} else {
echo 'updated edited date in table news' . $line_end;
}
# rename news table
$sql = 'RENAME TABLE `'.DB_NAME.'`.`news` TO `'.DB_NAME.'`.`articles` ;';
$result = $mysqli->multi_query($sql);
if (!$result) {
echo 'could not rename table';
} else {
echo 'renamed table news to articles' . $line_end;
}
?>