Completed
Push — loadtest ( 49444c...a21f60 )
by Ilia
15:05
created

createObjectsFunctions.php ➔ createGroups()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
nc 9
nop 1
dl 0
loc 47
ccs 0
cts 35
cp 0
crap 30
rs 8.8452
c 0
b 0
f 0
1
<?php
2
3
4
5 View Code Duplication
function createBlogs($N) {
6
    if ($N < 1){
7
        echo "usage: .../gen-content/blogs/N  where N > 0  ... your N wasn't > 0 was it";
8
        return 1;
9
    }
10
    $dbprefix = elgg_get_config('dbprefix');
11
    // create N filler blogs quickly
12
13
    // entities
14
    $vals = array();
15
    $subtype = get_subtype_id('object', 'blog');
16
    $owner = get_data("select guid from {$dbprefix}users_entity limit 1");      // these will all belong to the first user we see
17
    $ownerid = $owner[0]->guid;
18
    $t_base = 150000000;
19
20
    $start_guid = get_data("select max(guid)+1 as start from {$dbprefix}entities")[0]->start;  // get the max id to start from
21
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
22
        $timestamp = $t_base + $i;
23
        $vals[] = "('{$i}','object',$subtype,$ownerid,1,$ownerid,2,$timestamp,$timestamp,$timestamp,'yes',NULL)";
24
    }
25
    $entityvals = implode(',', $vals);
26
    $entities = "INSERT INTO {$dbprefix}entities values {$entityvals}";
27
    //echo $entities . "<br />\n<hr />";
28
    echo insert_data($entities). "<br />\n<hr />";
29
30
    // objects
31
    $vals = array();
32
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
33
        $vals[] = "('{$i}','Super Blog ($i)','HI! TEST BLOG {$i} HERE! There are Literally {$N} of us!!!1!')";
34
    }
35
    $objectvals = implode(',', $vals);
36
    $objects = "INSERT INTO {$dbprefix}objects_entity values {$objectvals}";
37
    //echo $objects . "<br />\n<hr />";
38
    echo insert_data($objects). "<br />\n<hr />";
39
40
    // river
41
    $vals = array();
42
    $start_id = get_data("select max(id) as start from {$dbprefix}river")[0]->start + 1;  // get the max id to start from
43
    for ($i=$start_id; $i < $start_id + $N; $i++) {
44
        $guid = $i - $start_id + $start_guid;
45
        $timestamp = $t_base + $guid;  // try to keep it the same as the timestamps in the entities table
46
        $vals[] = "('{$i}','object','blog','create',2,'river/object/blog/create','{$ownerid}','{$guid}',0,0,{$timestamp},'yes')";
47
    }
48
    $rivervals = implode(',', $vals);
49
    $river = "INSERT INTO {$dbprefix}river values {$rivervals}";
50
    //echo $river . "<br />\n<hr />";
51
    echo insert_data($river). "<br />\n<hr />";
52
}
53
54 View Code Duplication
function createWire($N) {
55
    if ($N < 1){
56
        echo "usage: .../gen-content/wire/N  where N > 0  ... your N wasn't > 0 was it";
57
        return 1;
58
    }
59
    $dbprefix = elgg_get_config('dbprefix');
60
    // create N filler wire quickly
61
62
    // entities
63
    $vals = array();
64
    $subtype = get_subtype_id('object', 'thewire');
65
    $owner = get_data("select guid from {$dbprefix}users_entity limit 1");      // these will all belong to the first user we see
66
    $ownerid = $owner[0]->guid;
67
    $t_base = 150000000;
68
69
    $start_guid = get_data("select max(guid)+1 as start from {$dbprefix}entities")[0]->start;  // get the max id to start from
70
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
71
        $timestamp = $t_base + $i;
72
        $vals[] = "('{$i}','object',$subtype,$ownerid,1,$ownerid,2,$timestamp,$timestamp,$timestamp,'yes',NULL)";
73
    }
74
    $entityvals = implode(',', $vals);
75
    $entities = "INSERT INTO {$dbprefix}entities values {$entityvals}";
76
    //echo $entities . "<br />\n<hr />";
77
    echo insert_data($entities). "<br />\n<hr />";
78
79
    // objects
80
    $vals = array();
81
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
82
        $vals[] = "('{$i}','Super Wire post ($i)','HI! TEST WIRE POST {$i} HERE! There are Literally {$N} of us!!!1!')";
83
    }
84
    $objectvals = implode(',', $vals);
85
    $objects = "INSERT INTO {$dbprefix}objects_entity values {$objectvals}";
86
    //echo $objects . "<br />\n<hr />";
87
    echo insert_data($objects). "<br />\n<hr />";
88
89
    // river
90
    $vals = array();
91
    $start_id = get_data("select max(id) as start from {$dbprefix}river")[0]->start + 1;  // get the max id to start from
92
    for ($i=$start_id; $i < $start_id + $N; $i++) {
93
        $guid = $i - $start_id + $start_guid;
94
        $timestamp = $t_base + $guid;  // try to keep it the same as the timestamps in the entities table
95
        $vals[] = "('{$i}','object','thewire','create',2,'river/object/thewire/create','{$ownerid}','{$guid}',0,0,{$timestamp},'yes')";
96
    }
97
    $rivervals = implode(',', $vals);
98
    $river = "INSERT INTO {$dbprefix}river values {$rivervals}";
99
    //echo $river . "<br />\n<hr />";
100
    echo insert_data($river). "<br />\n<hr />";
101
}
102
103
104
function createGroups($N) {
105
    if ($N < 1){
106
        echo "usage: .../gen-content/groups/N  where N > 0  ... your N wasn't > 0 was it";
107
        return 1;
108
    }
109
    $dbprefix = elgg_get_config('dbprefix');
110
    // create N filler groups quickly
111
112
    // entities
113
    $vals = array();
114
    $owner = get_data("select guid from {$dbprefix}users_entity limit 1");      // these will all belong to the first user we see
115
    $ownerid = $owner[0]->guid;
116
    $t_base = 150000000;
117
118
    $start_guid = get_data("select max(guid)+1 as start from {$dbprefix}entities")[0]->start;  // get the max id to start from
119
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
120
        $timestamp = $t_base + $i;
121
        $vals[] = "('{$i}','group',0,$ownerid,1,$ownerid,2,$timestamp,$timestamp,$timestamp,'yes',NULL)";
122
    }
123
    $entityvals = implode(',', $vals);
124
    $entities = "INSERT INTO {$dbprefix}entities values {$entityvals}";
125
    //echo $entities . "<br />\n<hr />";
126
    echo insert_data($entities). "<br />\n<hr />";
127
128
    // group
129
    $vals = array();
130
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
131
        $vals[] = "('{$i}','Super group ($i)','HI! TEST group {$i} HERE! There are Literally {$N} of us!!!1!')";
132
    }
133
    $objectvals = implode(',', $vals);
134
    $objects = "INSERT INTO {$dbprefix}groups_entity values {$objectvals}";
135
    //echo $objects . "<br />\n<hr />";
136
    echo insert_data($objects). "<br />\n<hr />";
137
138
    // river
139
    $vals = array();
140
    $start_id = get_data("select max(id) as start from {$dbprefix}river")[0]->start + 1;  // get the max id to start from
141
    for ($i=$start_id; $i < $start_id + $N; $i++) {
142
        $guid = $i - $start_id + $start_guid;
143
        $timestamp = $t_base + $guid;  // try to keep it the same as the timestamps in the entities table
144
        $vals[] = "('{$i}','group','','create',2,'river/group/create','{$ownerid}','{$guid}',0,0,{$timestamp},'yes')";
145
    }
146
    $rivervals = implode(',', $vals);
147
    $river = "INSERT INTO {$dbprefix}river values {$rivervals}";
148
    //echo $river . "<br />\n<hr />";
149
    echo insert_data($river). "<br />\n<hr />";
150
}