populator.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. set_include_path(__DIR__.'/..' . PATH_SEPARATOR . get_include_path());
  3. set_include_path(__DIR__.'/../../../library' . PATH_SEPARATOR . get_include_path());
  4. require_once __DIR__.'/../Show.php';
  5. require_once __DIR__.'/../StoredFile.php';
  6. require_once __DIR__.'/../Playlist.php';
  7. require_once __DIR__.'/../Schedule.php';
  8. require_once __DIR__.'/../Preference.php';
  9. require_once __DIR__.'/../RabbitMq.php';
  10. require_once __DIR__.'/../../configs/conf.php';
  11. require_once __DIR__.'/../../../install_minimal/include/AirtimeIni.php';
  12. require_once __DIR__.'/../../../install_minimal/include/AirtimeInstall.php';
  13. require_once __DIR__.'/../../../library/propel/runtime/lib/Propel.php';
  14. Propel::init(__DIR__.'/../../configs/airtime-conf.php');
  15. AirtimeInstall::DbConnect(true);
  16. $con = Propel::getConnection();
  17. $sql = "DELETE FROM cc_show";
  18. $con->exec($sql);
  19. $sql = "DELETE FROM cc_show_days";
  20. $con->exec($sql);
  21. $sql = "DELETE FROM cc_show_instances";
  22. $con->exec($sql);
  23. /*
  24. // Create a playlist
  25. $playlist = new Application_Model_Playlist();
  26. $playlist->create("Calendar Load test playlist ".uniqid());
  27. // Add a file
  28. $values = array("filepath" => __DIR__."/test10001.mp3");
  29. $storedFile = Application_Model_StoredFile::Insert($values, false);
  30. $result = $playlist->addAudioClip($storedFile->getId());
  31. // Add a file
  32. $values = array("filepath" => __DIR__."/test10002.mp3");
  33. $storedFile2 = Application_Model_StoredFile::Insert($values, false);
  34. $result = $playlist->addAudioClip($storedFile2->getId());
  35. $result = $playlist->addAudioClip($storedFile2->getId());
  36. echo "Created playlist ".$playlist->getName()." with ID ".$playlist->getId()."\n";
  37. */
  38. // Create the shows
  39. function createTestShow($showNumber, $showTime, $duration = "1:00")
  40. {
  41. $data = array();
  42. $strTime = $showTime->format("Y-m-d H:i");
  43. echo "Adding show: $strTime\n";
  44. $data['add_show_name'] = 'automated show '.$showNumber;
  45. $data['add_show_start_date'] = $showTime->format("Y-m-d");
  46. $data['add_show_start_time'] = $showTime->format("H:i");
  47. $data['add_show_duration'] = $duration;
  48. $data['add_show_no_end'] = 0;
  49. $data['add_show_repeats'] = 0;
  50. $data['add_show_description'] = 'automated show';
  51. $data['add_show_url'] = 'http://www.OfirGal.com';
  52. $data['add_show_color'] = "";
  53. $data['add_show_genre'] = "Ofir";
  54. $data['add_show_background_color'] = "";
  55. $data['add_show_record'] = 0;
  56. $data['add_show_hosts'] ="";
  57. $showId = Application_Model_Show::create($data);
  58. //echo "show created, ID: $showId\n";
  59. // populating the show with a playlist
  60. $instances = Application_Model_Show::getShows($showTime, $showTime);
  61. $instance = array_pop($instances);
  62. $show = new Application_Model_ShowInstance($instance["instance_id"]);
  63. //echo "Adding playlist to show instance ".$show->getShowInstanceId()."\n";
  64. $show->scheduleShow(array(1));
  65. //echo "done\n";
  66. //$show->scheduleShow(array($playlist->getId()));
  67. }
  68. $showTime = new DateTime();
  69. $resolution = "hour";
  70. $showNumber = 1;
  71. $numberOfDays = 180;
  72. $numberOfHours = 0;
  73. $endDate = new DateTime();
  74. $endDate->add(new DateInterval("P".$numberOfDays."DT".$numberOfHours."H"));
  75. echo "End date: ".$endDate->format("Y-m-d H:i")."\n";
  76. while ($showTime < $endDate) {
  77. echo $showTime->format("Y-m-d H:i")." < " .$endDate->format("Y-m-d H:i")."\n";
  78. if ($resolution == "minute") {
  79. createTestShow($showNumber, $showTime, "0:01");
  80. $showTime->add(new DateInterval("PT1M"));
  81. } elseif ($resolution == "hour") {
  82. createTestShow($showNumber, $showTime);
  83. $showTime->add(new DateInterval("PT1H"));
  84. }
  85. $showNumber = $showNumber + 1;
  86. }
  87. if (Application_Model_RabbitMq::$doPush) {
  88. $md = array('schedule' => Application_Model_Schedule::getSchedule());
  89. Application_Model_RabbitMq::SendMessageToPypo("update_schedule", $md);
  90. }