ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
generateicalendardata.php
Go to the documentation of this file.
1 #!/usr/bin/env php
2 <?php
3 
4 use Sabre\VObject;
5 
6 if ($argc < 2) {
7  $cmd = $argv[0];
8  fwrite(STDERR, <<<HI
9 Fruux test data generator
10 
11 This script generates a lot of test data. This is used for profiling and stuff.
12 Currently it just generates events in a single calendar.
13 
14 The iCalendar output goes to stdout. Other messages to stderr.
15 
16 {$cmd} [events]
17 
18 
19 HI
20  );
21  die();
22 }
23 
24 $events = 100;
25 
26 if (isset($argv[1])) $events = (int)$argv[1];
27 
28 include __DIR__ . '/../vendor/autoload.php';
29 
30 fwrite(STDERR, "Generating " . $events . " events\n");
31 
32 $currentDate = new DateTime('-' . round($events / 2) . ' days');
33 
34 $calendar = new VObject\Component\VCalendar();
35 
36 $ii = 0;
37 
38 while ($ii < $events) {
39 
40  $ii++;
41 
42  $event = $calendar->add('VEVENT');
43  $event->DTSTART = 'bla';
44  $event->SUMMARY = 'Event #' . $ii;
45  $event->UID = md5(microtime(true));
46 
47  $doctorRandom = mt_rand(1, 1000);
48 
49  switch ($doctorRandom) {
50  // All-day event
51  case 1 :
52  $event->DTEND = 'bla';
53  $dtStart = clone $currentDate;
54  $dtEnd = clone $currentDate;
55  $dtEnd->modify('+' . mt_rand(1, 3) . ' days');
56  $event->DTSTART->setDateTime($dtStart);
57  $event->DTSTART['VALUE'] = 'DATE';
58  $event->DTEND->setDateTime($dtEnd);
59  break;
60  case 2 :
61  $event->RRULE = 'FREQ=DAILY;COUNT=' . mt_rand(1, 10);
62  // No break intentional
63  default :
64  $dtStart = clone $currentDate;
65  $dtStart->setTime(mt_rand(1, 23), mt_rand(0, 59), mt_rand(0, 59));
66  $event->DTSTART->setDateTime($dtStart);
67  $event->DURATION = 'PT' . mt_rand(1, 3) . 'H';
68  break;
69 
70  }
71 
72  $currentDate->modify('+ ' . mt_rand(0, 3) . ' days');
73 
74 }
75 fwrite(STDERR, "Validating\n");
76 
77 $result = $calendar->validate();
78 if ($result) {
79  fwrite(STDERR, "Errors!\n");
80  fwrite(STDERR, print_r($result, true));
81  die(-1);
82 }
83 
84 fwrite(STDERR, "Serializing this beast\n");
85 
86 echo $calendar->serialize();
87 
88 fwrite(STDERR, "done.\n");
global $argv
Definition: svg-scanner.php:41
if($argc< 2) $events
test()
Definition: build.php:107
$this data['403_header']