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
|
<?php
class InitCustomBlubberStreams extends Migration {
function description() {
return 'Introduces custom blubber streams and makes hashtags more reliable';
}
function up() {
DBManager::get()->exec("
CREATE TABLE IF NOT EXISTS `blubber_tags` (
`topic_id` varchar(32) NOT NULL,
`tag` varchar(128) NOT NULL,
PRIMARY KEY `unique_tags` (`topic_id`,`tag`),
KEY `tag` (`tag`)
) ENGINE=MyISAM
");
DBManager::get()->exec("
CREATE TABLE IF NOT EXISTS `blubber_streams` (
`stream_id` varchar(32) NOT NULL,
`user_id` varchar(32) NOT NULL,
`name` varchar(32) NOT NULL,
`sort` enum('activity','age') NOT NULL DEFAULT 'age',
`defaultstream` tinyint(2) NOT NULL DEFAULT '0',
`pool_courses` text,
`pool_groups` text,
`pool_hashtags` text,
`filter_type` text,
`filter_courses` text,
`filter_groups` text,
`filter_users` text,
`filter_hashtags` text,
`filter_nohashtags` text,
`chdate` bigint(20) NOT NULL,
`mkdate` bigint(20) NOT NULL,
PRIMARY KEY (`stream_id`),
KEY `user_id` (`user_id`)
) ENGINE=MyISAM
");
DBManager::get()->exec("ALTER TABLE `blubber` DROP INDEX `root_id` ,
ADD INDEX `root_id` ( `root_id` , `mkdate` )");
DBManager::get()->exec("ALTER TABLE `blubber` DROP INDEX `Seminar_id` ,
ADD INDEX `Seminar_id` ( `Seminar_id` , `context_type` )");
//noch Hashtags/Tags in eigene Tabelle packen:
$statement = DBManager::get()->prepare(
"SELECT blubber.* " .
"FROM blubber " .
"WHERE LOCATE('#', blubber.description) > 0 " .
"");
$statement->execute();
$hashtag_regexp = "(?:^|\s)#([\w\d_\.\-\?!\+=%]*[\w\d])";
$insert_statement = DBManager::get()->prepare(
"INSERT IGNORE INTO blubber_tags " .
"SET topic_id = :topic_id, " .
"tag = :tag " .
"");
while($blubber = $statement->fetch(PDO::FETCH_ASSOC)) {
preg_match_all("/".$hashtag_regexp."/", $blubber['description'], $matches);
foreach ($matches as $match) {
$match = trim($match[0]);
$tag = $match[0] === "#" ? substr($match, 1) : $match;
if ($tag) {
$insert_statement->execute([
'topic_id' => $blubber['root_id'],
'tag' => strtolower($tag)
]);
}
}
}
}
function down() {
}
}
|