annotate vendor/sabre/vobject/bin/generateicalendardata.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 #!/usr/bin/env php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4 use Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 if ($argc<2) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 $cmd = $argv[0];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 fwrite(STDERR, <<<HI
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 Fruux test data generator
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 This script generates a lot of test data. This is used for profiling and stuff.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 Currently it just generates events in a single calendar.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 The iCalendar output goes to stdout. Other messages to stderr.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 {$cmd} [events]
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 HI
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 die();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 $events = 100;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 if (isset($argv[1])) $events = (int)$argv[1];
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 include __DIR__ . '/../vendor/autoload.php';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 fwrite(STDERR, "Generating " . $events . " events\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 $currentDate = new DateTime('-' . round($events/2) . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 $calendar = VObject\Component::create('VCALENDAR');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 $calendar->version = '2.0';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 $calendar->calscale = 'GREGORIAN';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 $ii=0;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 while($ii < $events) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 $ii++;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 $event = VObject\Component::create('VEVENT');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 $event->DTSTART = 'bla';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 $event->SUMMARY = 'Event #' . $ii;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 $event->UID = md5(microtime(true));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 $doctorRandom = mt_rand(1,1000);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 switch($doctorRandom) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 // All-day event
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 case 1 :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 $event->DTEND = 'bla';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 $dtStart = clone $currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 $dtEnd = clone $currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 $dtEnd->modify('+' . mt_rand(1,3) . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 $event->DTSTART->setDateTime($dtStart, VObject\Property\DateTime::DATE);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 $event->DTEND->setDateTime($dtEnd, VObject\Property\DateTime::DATE);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 case 2 :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 $event->RRULE = 'FREQ=DAILY;COUNT=' . mt_rand(1,10);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 // No break intentional
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 default :
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 $dtStart = clone $currentDate;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 $dtStart->setTime(mt_rand(1,23), mt_rand(0,59), mt_rand(0,59));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 $event->DTSTART->setDateTime($dtStart, VObject\Property\DateTime::UTC);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 $event->DURATION = 'PT'.mt_rand(1,3).'H';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 break;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 $calendar->add($event);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 $currentDate->modify('+ ' . mt_rand(0,3) . ' days');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 fwrite(STDERR, "Validating\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 $result = $calendar->validate();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 if ($result) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 fwrite(STDERR, "Errors!\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 fwrite(STDERR, print_r($result,true));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 die(-1);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 fwrite(STDERR, "Serializing this beast\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 echo $calendar->serialize();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 fwrite(STDERR, "done.\n");
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91