function setup()
 {
     global $CC_CONFIG;
     $con = Propel::getConnection();
     // Clear the files table
     $sql = "DELETE FROM " . $CC_CONFIG["filesTable"];
     $con->exec($sql);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = Application_Model_StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
     // Clear the schedule table
     $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"];
     $con->exec($sql);
     // Create a playlist
     $playlist = new Application_Model_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 Application_Model_ScheduleGroup();
     $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId());
 }
 function setup()
 {
     global $CC_CONFIG;
     // Clear the files table
     //$sql = "DELETE FROM ".$CC_CONFIG["filesTable"];
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3");
     $this->storedFile = Application_Model_StoredFile::Insert($values, false);
     // Add a file
     $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3");
     $this->storedFile2 = Application_Model_StoredFile::Insert($values, false);
     // Clear the schedule table
     //$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"];
 }
 function testDeleteAndPutFile()
 {
     $STORAGE_SERVER_PATH = dirname(__FILE__) . "/../../";
     $filePath = dirname(__FILE__) . "/ex1.mp3";
     // Delete any old data from previous tests
     $md5 = md5_file($filePath);
     $duplicate = Application_Model_StoredFile::RecallByMd5($md5);
     if ($duplicate) {
         $duplicate->delete();
     }
     // Test inserting a file by linking
     $values = array("filepath" => $filePath, "dc:description" => "Unit test " . time());
     $storedFile = Application_Model_StoredFile::Insert($values, false);
     //var_dump($storedFile);
     $id = $storedFile->getId();
     if (!is_numeric($id)) {
         $this->fail("StoredFile not created correctly. id = " . $id);
         return;
     }
     // Test loading metadata
     $f = new Application_Model_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 = Application_Model_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;
     }
 }
 public function dispatchMetadata($md, $mode)
 {
     $return_hash = array();
     Application_Model_Preference::SetImportTimestamp();
     $con = Propel::getConnection(CcFilesPeer::DATABASE_NAME);
     $con->beginTransaction();
     try {
         // create also modifies the file if it exists
         if ($mode == "create") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = Application_Common_OsPath::normpath($filepath);
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             if (is_null($file)) {
                 $file = Application_Model_StoredFile::Insert($md, $con);
             } else {
                 // If the file already exists we will update and make sure that
                 // it's marked as 'exists'.
                 $file->setFileExistsFlag(true);
                 $file->setFileHiddenFlag(false);
                 $file->setMetadata($md);
             }
             if ($md['is_record'] != 0) {
                 $this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
             }
         } elseif ($mode == "modify") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             //File is not in database anymore.
             if (is_null($file)) {
                 $return_hash['error'] = _("File does not exist in Airtime.");
             } else {
                 //CC-5207 - restart media-monitor causes it to reevaluate all
                 //files in watched directories, and reset their cue-in/cue-out
                 //values. Since media-monitor has nothing to do with cue points
                 //let's unset it here. Note that on mode == "create", we still
                 //want media-monitor sending info about cue_out which by default
                 //will be equal to length of track until silan can take over.
                 unset($md['MDATA_KEY_CUE_IN']);
                 unset($md['MDATA_KEY_CUE_OUT']);
                 $file->setMetadata($md);
             }
         } elseif ($mode == "moved") {
             $file = Application_Model_StoredFile::RecallByFilepath($md['MDATA_KEY_ORIGINAL_PATH'], $con);
             if (is_null($file)) {
                 $return_hash['error'] = _('File does not exist in Airtime');
             } else {
                 $filepath = $md['MDATA_KEY_FILEPATH'];
                 //$filepath = str_replace("\\", "", $filepath);
                 $file->setFilePath($filepath);
             }
         } elseif ($mode == "delete") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             $filepath = str_replace("\\", "", $filepath);
             $file = Application_Model_StoredFile::RecallByFilepath($filepath, $con);
             if (is_null($file)) {
                 $return_hash['error'] = _("File doesn't exist in Airtime.");
                 Logging::warn("Attempt to delete file that doesn't exist.\n                        Path: '{$filepath}'");
             } else {
                 $file->deleteByMediaMonitor();
             }
         } elseif ($mode == "delete_dir") {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             //$filepath = str_replace("\\", "", $filepath);
             $files = Application_Model_StoredFile::RecallByPartialFilepath($filepath, $con);
             foreach ($files as $file) {
                 $file->deleteByMediaMonitor();
             }
             $return_hash['success'] = 1;
         }
         if (!isset($return_hash['error'])) {
             $return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
         }
         $con->commit();
     } catch (Exception $e) {
         Logging::warn("rolling back");
         Logging::warn($e->getMessage());
         $con->rollback();
         $return_hash['error'] = $e->getMessage();
     }
     return $return_hash;
 }
Example #5
0
 public function dispatchMetadata($md, $mode)
 {
     $return_hash = array();
     Application_Model_Preference::SetImportTimestamp();
     //Logging::info("--->Mode: $mode || file: {$md['MDATA_KEY_FILEPATH']} ");
     //Logging::info( $md );
     // create also modifies the file if it exists
     if ($mode == "create") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = Application_Common_OsPath::normpath($filepath);
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $file = Application_Model_StoredFile::Insert($md);
         } else {
             // If the file already exists we will update and make sure that
             // it's marked as 'exists'.
             $file->setFileExistsFlag(true);
             $file->setMetadata($md);
         }
         if ($md['is_record'] != 0) {
             $this->uploadRecordedActionParam($md['MDATA_KEY_TRACKNUMBER'], $file->getId());
         }
     } elseif ($mode == "modify") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         //File is not in database anymore.
         if (is_null($file)) {
             $return_hash['error'] = "File does not exist in Airtime.";
             return $return_hash;
         } else {
             $file->setMetadata($md);
         }
     } elseif ($mode == "moved") {
         $file = Application_Model_StoredFile::RecallByFilepath($md['MDATA_KEY_ORIGINAL_PATH']);
         if (is_null($file)) {
             $return_hash['error'] = 'File does not exist in Airtime';
         } else {
             $filepath = $md['MDATA_KEY_FILEPATH'];
             //$filepath = str_replace("\\", "", $filepath);
             $file->setFilePath($filepath);
         }
     } elseif ($mode == "delete") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         $filepath = str_replace("\\", "", $filepath);
         $file = Application_Model_StoredFile::RecallByFilepath($filepath);
         if (is_null($file)) {
             $return_hash['error'] = "File doesn't exist in Airtime.";
             Logging::warn("Attempt to delete file that doesn't exist.\n                    Path: '{$filepath}'");
             return $return_hash;
         } else {
             $file->deleteByMediaMonitor();
         }
     } elseif ($mode == "delete_dir") {
         $filepath = $md['MDATA_KEY_FILEPATH'];
         //$filepath = str_replace("\\", "", $filepath);
         $files = Application_Model_StoredFile::RecallByPartialFilepath($filepath);
         foreach ($files as $file) {
             $file->deleteByMediaMonitor();
         }
         $return_hash['success'] = 1;
         return $return_hash;
     }
     $return_hash['fileid'] = is_null($file) ? '-1' : $file->getId();
     return $return_hash;
 }
// 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 = Application_Model_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 = Application_Model_StoredFile::Insert($v);
}
$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
$scheduleClear = Schedule::isScheduleEmptyInRange($startTime, "01:00:00");
if (!$scheduleClear) {
    echo "\nERROR: Schedule could not be cleared.\n\n";
    var_dump(Schedule::getItems($startTime, $endTime));