-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.php
97 lines (78 loc) · 3.03 KB
/
install.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
$conf = include 'config.php';
include_once 'include/dehasher.class.php';
$dehasher = new deHasher($conf['db']['host'], $conf['db']['base'], $conf['db']['user'], $conf['db']['pass']);
// tables
echo "Adding tables...<br>";
echo "Adding table hash...<br>";
$query = "CREATE TABLE `hash` (
`hash_id` int(10) UNSIGNED NOT NULL,
`type_id` int(10) UNSIGNED NOT NULL,
`text_id` int(10) UNSIGNED NOT NULL,
`hash_value` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$dehasher->db->query($query);
echo "Adding table text...<br>";
$query = "CREATE TABLE `text` (
`text_id` int(10) UNSIGNED NOT NULL,
`text_value` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$dehasher->db->query($query);
echo "Adding table type...<br>";
$query = "CREATE TABLE `type` (
`type_id` int(10) UNSIGNED NOT NULL,
`type_name` varchar(16) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$dehasher->db->query($query);
echo "Adding tables completed.<br>";
// indexes
echo "Adding indexes...<br>";
echo "Adding indexes for hash...<br>";
$query = "ALTER TABLE `hash`
ADD PRIMARY KEY (`hash_id`),
ADD KEY `idx_hash` (`type_id`),
ADD KEY `idx_hash_0` (`text_id`);";
$dehasher->db->query($query);
echo "Adding indexes for text...<br>";
$query = "ALTER TABLE `text`
ADD PRIMARY KEY (`text_id`);";
$dehasher->db->query($query);
echo "Adding indexes for type...<br>";
$query = "ALTER TABLE `type`
ADD PRIMARY KEY (`type_id`);";
$dehasher->db->query($query);
echo "Adding indexes completed.<br>";
// auto increments
echo "Adding auto increments...<br>";
echo "Adding auto increments for hash...<br>";
$query = "ALTER TABLE `hash`
MODIFY `hash_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;";
$dehasher->db->query($query);
echo "Adding auto increments for text...<br>";
$query = "ALTER TABLE `text`
MODIFY `text_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;";
$dehasher->db->query($query);
echo "Adding auto increments for type...<br>";
$query = "ALTER TABLE `type`
MODIFY `type_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;";
$dehasher->db->query($query);
echo "Adding auto increments completed.<br>";
// constraints
echo "Adding constraints...<br>";
echo "Adding constraints for hash...<br>";
$query = "ALTER TABLE `hash`
ADD CONSTRAINT `fk_hash` FOREIGN KEY (`type_id`) REFERENCES `type` (`type_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
ADD CONSTRAINT `fk_hash_0` FOREIGN KEY (`text_id`) REFERENCES `text` (`text_id`) ON DELETE NO ACTION ON UPDATE NO ACTION;";
$dehasher->db->query($query);
echo "Adding constraints completed.<br>";
// supported types
$types = $dehasher->getTypeList();
foreach ($types as $type) {
$dehasher->db->query("INSERT INTO `type` (`type_name`) VALUES ('" . $type . "')");
}
// exit
if (!unlink('install.php')) {
exit("Remove 'install.php' file immediately!");
} else {
exit("'install.php' file hash been removed.");
}