PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/task/mediafillTask.class.php

http://streeme.googlecode.com/
PHP | 92 lines | 89 code | 3 blank | 0 comment | 0 complexity | 7de2d0d713936bbd833a4b39b28d8b02 MD5 | raw file
Possible License(s): LGPL-3.0, GPL-2.0, ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. class mediafillTask extends sfBaseTask
  3. {
  4. protected function configure()
  5. {
  6. $this->addOptions(array(
  7. new sfCommandOption( 'application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'client' ),
  8. new sfCommandOption( 'env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'test' ),
  9. new sfCommandOption( 'connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine' ),
  10. new sfCommandOption( 'count', null, sfCommandOption::PARAMETER_REQUIRED, 'The number of fake records to add', 7500),
  11. new sfCommandOption( 'max_album_size', null, sfCommandOption::PARAMETER_REQUIRED, 'The largest number of songs to add to an album', 24),
  12. new sfCommandOption('no-confirmation', null, sfCommandOption::PARAMETER_NONE, 'proceed without prompts')
  13. ));
  14. $this->namespace = '';
  15. $this->name = 'media-fill';
  16. $this->briefDescription = 'Fill the library with records';
  17. $this->detailedDescription = <<<EOF
  18. The [media-fill|INFO] task will add a specified number of records in a semi
  19. random order to help benchmark Streeme's song list performance on small and
  20. large music libraries.
  21. Types:
  22. --count=[int] - The number of records to add
  23. --max_album_size=[int]- the maximum number of member song in an album
  24. Call it with:
  25. [php symfony media-fill --count="..."|INFO]
  26. EOF;
  27. }
  28. protected function execute( $arguments = array(), $options = array() )
  29. {
  30. // initialize the database connection
  31. $databaseManager = new sfDatabaseManager($this->configuration);
  32. $environment = $this->configuration instanceof sfApplicationConfiguration ? $this->configuration->getEnvironment() : 'all';
  33. $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
  34. $media_scanner = new MediaScan();
  35. if (
  36. !$options['no-confirmation']
  37. &&
  38. !$this->askConfirmation(array_merge(
  39. array(sprintf('This command will append data in the following "%s" connection(s):', $environment), ''),
  40. array('', 'Are you sure you want to proceed? (y/N)')
  41. ), 'QUESTION_LARGE', false)
  42. )
  43. {
  44. exit;
  45. }
  46. $counter=1;
  47. for( $i=0; $i < (int) $options['count']; $i++ )
  48. {
  49. if($counter >= $group_size)
  50. {
  51. $artist_name = substr( sha1(uniqid().mt_rand(29098,209120392093029)), 0, mt_rand(4, 12));
  52. $album_name = substr( sha1(uniqid().mt_rand(3048,209120393)), 0, mt_rand(6,16));
  53. $genre_name = substr( sha1(uniqid().mt_rand(30203,2091029309213)), 0, mt_rand(10,12));
  54. $label_name = substr( sha1(uniqid().mt_rand(30203,2091029309213)), 0, mt_rand(10,12));
  55. $group_size = mt_rand(1,(int) $options['max_album_size']);
  56. $bitrate = mt_rand(48,512);
  57. $yearpublished = mt_rand(1900,2069);
  58. $counter = 1;
  59. }
  60. $song_name = substr( sha1(uniqid().mt_rand(360,20912039209213)), 0, mt_rand(10,20));
  61. $song_array = array();
  62. @$song_array[ 'artist_name' ] = $artist_name;
  63. @$song_array[ 'album_name' ] = $album_name;
  64. @$song_array[ 'song_name' ] = $song_name;
  65. @$song_array[ 'song_length' ] = mt_rand(0,60) . ':' . mt_rand(11,60);
  66. @$song_array[ 'accurate_length' ] = mt_rand(1,30409092);
  67. @$song_array[ 'genre_name' ] = $genre_name;
  68. @$song_array[ 'filesize' ] = mt_rand(256, 3141592653);
  69. @$song_array[ 'bitrate' ] = $bitrate;
  70. @$song_array[ 'yearpublished' ] = $yearpublished;
  71. @$song_array[ 'tracknumber'] = $counter;
  72. @$song_array[ 'label' ] = $label_name;
  73. @$song_array[ 'mtime' ] = mt_rand(1, 3141592653);
  74. @$song_array[ 'atime' ] = mt_rand(1, 3141592653);
  75. @$song_array[ 'filename' ] = 'file://localhost/home/user/' . $artist_name . '/' . $album_name . '/' . $song_name . '.mp3';
  76. $media_scanner->add_song( $song_array );
  77. $counter++;
  78. }
  79. echo sprintf('Filled Database %s with %d record%s', $options['env'], $i, ($i==1) ? '' : 's' );
  80. echo "\r\n";
  81. }
  82. }