Ejemplo n.º 1
0
 function setup()
 {
     global $CC_CONFIG, $CC_DBC;
     // Clear the files table
     $sql = "DELETE FROM " . $CC_CONFIG["filesTable"];
     $CC_DBC->query($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = StoredFile::Insert($values, false);
     // Clear the schedule table
     $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"];
     $CC_DBC->query($sql);
     // Create a playlist
     $playlist = new Playlist();
     $playlist->create("Scheduler Unit Test");
     $result = $playlist->addAudioClip($this->storedFile->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     $result = $playlist->addAudioClip($this->storedFile2->getId());
     // Schedule it
     $i = new ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
 }
Ejemplo n.º 2
0
 function setup()
 {
     global $CC_CONFIG, $CC_DBC;
     // Clear the files table
     //$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
     //$CC_DBC->query($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = StoredFile::Insert($values, false);
     // Clear the schedule table
     //$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
     //$CC_DBC->query($sql);
 }
Ejemplo n.º 3
0
 function testDeleteAndPutFile()
 {
     $STORAGE_SERVER_PATH = dirname(__FILE__) . "/../../";
     $filePath = dirname(__FILE__) . "/ex1.mp3";
     // Delete any old data from previous tests
     $md5 = md5_file($filePath);
     $duplicate = StoredFile::RecallByMd5($md5);
     if ($duplicate) {
         $duplicate->delete();
     }
     // Test inserting a file by linking
     $values = array("filepath" => $filePath, "dc:description" => "Unit test " . time());
     $storedFile = StoredFile::Insert($values, false);
     if (PEAR::isError($storedFile)) {
         $this->fail("Failed to create StoredFile: " . $storedFile->getMessage());
         return;
     }
     //var_dump($storedFile);
     $id = $storedFile->getId();
     if (!is_numeric($id)) {
         $this->fail("StoredFile not created correctly. id = " . $id);
         return;
     }
     // Test loading metadata
     $f = new StoredFile();
     $f->__setGunid($storedFile->getGunid());
     $f->loadMetadata();
     if (!is_array($md = $f->getMetadata())) {
         $this->fail("Unable to load metadata.");
         return;
     }
     //var_dump($md);
     // Check if the length field has been set.
     $f2 = StoredFile::RecallByGunid($storedFile->getGunid());
     $m2 = $f2->getMetadata();
     if (!isset($m2["length"]) || $m2["length"] == "00:00:00.000000") {
         $this->fail("Length not reporting correctly in metadata.");
         return;
     }
 }
// Delete any old playlists
$pl2 = Playlist::findPlaylistByName($playlistName);
foreach ($pl2 as $playlist) {
    //var_dump($playlist);
    $playlist->delete();
}
echo "done.\n";
// Create a new playlist
echo "Creating new playlist '{$playlistName}'...";
$pl = new Playlist();
$pl->create($playlistName);
$mediaFile = StoredFile::findByOriginalName("Peter_Rudenko_-_Opening.mp3");
if (is_null($mediaFile)) {
    echo "Adding test audio clip to the database.\n";
    $v = array("filepath" => __DIR__ . "/../../../audio_samples/vorbis.com/Hydrate-Kenny_Beltrey.ogg");
    $mediaFile = StoredFile::Insert($v);
    if (PEAR::isError($mediaFile)) {
        var_dump($mediaFile);
        exit;
    }
}
$pl->addAudioClip($mediaFile->getId());
echo "done.\n";
//$pl2 = Playlist::findPlaylistByName("pypo_playlist_test");
//var_dump($pl2);
// Get current time
// In the format YYYY-MM-DD HH:MM:SS.nnnnnn
$startTime = date("Y-m-d H:i:s");
$endTime = date("Y-m-d H:i:s", time() + 60 * 60);
echo "Removing everything from the scheduler between {$startTime} and {$endTime}...";
// Check for succces
Ejemplo n.º 5
0
 public function reloadMetadataAction()
 {
     global $CC_CONFIG;
     $request = $this->getRequest();
     $api_key = $request->getParam('api_key');
     if (!in_array($api_key, $CC_CONFIG["apiKey"])) {
         header('HTTP/1.0 401 Unauthorized');
         print 'You are not allowed to access this resource.';
         exit;
     }
     $mode = $request->getParam('mode');
     $params = $request->getParams();
     $md = array();
     //extract all file metadata params from the request.
     foreach ($params as $key => $value) {
         if (preg_match('/^MDATA_KEY/', $key)) {
             $md[$key] = $value;
         }
     }
     // update import timestamp
     Application_Model_Preference::SetImportTimestamp();
     if ($mode == "create") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = str_replace("\\", "", $filepath);
         $file = StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $file = StoredFile::Insert($md);
         } else {
             $this->view->error = "File already exists in Airtime.";
             return;
         }
     } else {
         if ($mode == "modify") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = str_replace("\\", "", $filepath);
             $file = StoredFile::RecallByFilepath($filepath);
             //File is not in database anymore.
             if (is_null($file)) {
                 $this->view->error = "File does not exist in Airtime.";
                 return;
             } else {
                 $file->setMetadata($md);
             }
         } else {
             if ($mode == "moved") {
                 $md5 = $md['MDATA_KEY_MD5'];
                 $file = StoredFile::RecallByMd5($md5);
                 if (is_null($file)) {
                     $this->view->error = "File doesn't exist in Airtime.";
                     return;
                 } else {
                     $filepath = $md['MDATA_KEY_FILEPATH'];
                     $filepath = str_replace("\\", "", $filepath);
                     $file->setFilePath($filepath);
                     //$file->setMetadata($md);
                 }
             } else {
                 if ($mode == "delete") {
                     $filepath = $md['MDATA_KEY_FILEPATH'];
                     $filepath = str_replace("\\", "", $filepath);
                     $file = StoredFile::RecallByFilepath($filepath);
                     if (is_null($file)) {
                         $this->view->error = "File doesn't exist in Airtime.";
                         return;
                     } else {
                         $file->delete();
                     }
                 }
             }
         }
     }
     $this->view->id = $file->getId();
 }