Completed
Push — loadtest ( ecce75...49444c )
by Ilia
13:59
created

createObjectsFunctions.php ➔ createBlogs()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 49

Duplication

Lines 49
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
nc 9
nop 1
dl 49
loc 49
rs 8.8016
c 0
b 0
f 0
ccs 0
cts 36
cp 0
crap 30
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
    }
26
    $entityvals = implode(',', $vals);
27
    $entities = "INSERT INTO {$dbprefix}entities values {$entityvals}";
28
    //echo $entities . "<br />\n<hr />";
29
    echo insert_data($entities). "<br />\n<hr />";
30
31
    // objects
32
    $vals = array();
33
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
34
        $vals[] = "('{$i}','Super Blog ($i)','HI! TEST BLOG {$i} HERE! There are Literally {$N} of us!!!1!')";
35
    }
36
    $objectvals = implode(',', $vals);
37
    $objects = "INSERT INTO {$dbprefix}objects_entity values {$objectvals}";
38
    //echo $objects . "<br />\n<hr />";
39
    echo insert_data($objects). "<br />\n<hr />";
40
41
    // river
42
    $vals = array();
43
    $start_id = get_data("select max(id) as start from {$dbprefix}river")[0]->start + 1;  // get the max id to start from
44
    for ($i=$start_id; $i < $start_id + $N; $i++) {
45
        $guid = $i - $start_id + $start_guid;
46
        $timestamp = $t_base + $guid;  // try to keep it the same as the timestamps in the entities table
47
        $vals[] = "('{$i}','object','blog','create',2,'river/object/blog/create','{$ownerid}','{$guid}',0,0,{$timestamp},'yes')";
48
    }
49
    $rivervals = implode(',', $vals);
50
    $river = "INSERT INTO {$dbprefix}river values {$rivervals}";
51
    //echo $river . "<br />\n<hr />";
52
    echo insert_data($river). "<br />\n<hr />";
53
}
54
55 View Code Duplication
function createWire($N) {
56
    if ($N < 1){
57
        echo "usage: .../gen-content/wire/N  where N > 0  ... your N wasn't > 0 was it";
58
        return 1;
59
    }
60
    $dbprefix = elgg_get_config('dbprefix');
61
    // create N filler wire quickly
62
63
    // entities
64
    $vals = array();
65
    $subtype = get_subtype_id('object', 'thewire');
66
    $owner = get_data("select guid from {$dbprefix}users_entity limit 1");      // these will all belong to the first user we see
67
    $ownerid = $owner[0]->guid;
68
    $t_base = 150000000;
69
70
    $start_guid = get_data("select max(guid)+1 as start from {$dbprefix}entities")[0]->start;  // get the max id to start from
71
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
72
        $timestamp = $t_base + $i;
73
        $vals[] = "('{$i}','object',$subtype,$ownerid,1,$ownerid,2,$timestamp,$timestamp,$timestamp,'yes',NULL)";
74
    }
75
    $entityvals = implode(',', $vals);
76
    $entities = "INSERT INTO {$dbprefix}entities values {$entityvals}";
77
    //echo $entities . "<br />\n<hr />";
78
    echo insert_data($entities). "<br />\n<hr />";
79
80
    // objects
81
    $vals = array();
82
    for ($i=$start_guid; $i < $start_guid + $N; $i++) {
83
        $vals[] = "('{$i}','Super Wire post ($i)','HI! TEST WIRE POST {$i} HERE! There are Literally {$N} of us!!!1!')";
84
    }
85
    $objectvals = implode(',', $vals);
86
    $objects = "INSERT INTO {$dbprefix}objects_entity values {$objectvals}";
87
    //echo $objects . "<br />\n<hr />";
88
    echo insert_data($objects). "<br />\n<hr />";
89
90
    // river
91
    $vals = array();
92
    $start_id = get_data("select max(id) as start from {$dbprefix}river")[0]->start + 1;  // get the max id to start from
93
    for ($i=$start_id; $i < $start_id + $N; $i++) {
94
        $guid = $i - $start_id + $start_guid;
95
        $timestamp = $t_base + $guid;  // try to keep it the same as the timestamps in the entities table
96
        $vals[] = "('{$i}','object','thewire','create',2,'river/object/thewire/create','{$ownerid}','{$guid}',0,0,{$timestamp},'yes')";
97
    }
98
    $rivervals = implode(',', $vals);
99
    $river = "INSERT INTO {$dbprefix}river values {$rivervals}";
100
    //echo $river . "<br />\n<hr />";
101
    echo insert_data($river). "<br />\n<hr />";
102
}