1#!/usr/bin/env php 2<?php 3 4use Sabre\VObject; 5 6if ($argc < 2) { 7 $cmd = $argv[0]; 8 fwrite(STDERR, <<<HI 9Fruux test data generator 10 11This script generates a lot of test data. This is used for profiling and stuff. 12Currently it just generates events in a single calendar. 13 14The iCalendar output goes to stdout. Other messages to stderr. 15 16{$cmd} [events] 17 18 19HI 20 ); 21 die(); 22} 23 24$events = 100; 25 26if (isset($argv[1])) $events = (int)$argv[1]; 27 28include __DIR__ . '/../vendor/autoload.php'; 29 30fwrite(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 38while ($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} 75fwrite(STDERR, "Validating\n"); 76 77$result = $calendar->validate(); 78if ($result) { 79 fwrite(STDERR, "Errors!\n"); 80 fwrite(STDERR, print_r($result, true)); 81 die(-1); 82} 83 84fwrite(STDERR, "Serializing this beast\n"); 85 86echo $calendar->serialize(); 87 88fwrite(STDERR, "done.\n"); 89