Example #1
0
 public function testGetUrl()
 {
     $serviceManager = new CM_Service_Manager();
     $filesystemDefault = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
     $filesystemFoo = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
     $serviceManager->registerInstance('filesystem-usercontent-default', $filesystemDefault);
     $serviceManager->registerInstance('filesystem-usercontent-foo', $filesystemFoo);
     $serviceConfig = array('default' => array('url' => 'http://example.com/default', 'filesystem' => 'filesystem-usercontent-default'), 'foo' => array('url' => 'http://example.com/foo', 'filesystem' => 'filesystem-usercontent-foo'));
     $serviceManager->registerInstance('usercontent', new CM_Service_UserContent($serviceConfig));
     $userFile = new CM_File_UserContent('foo', 'my.jpg', null, $serviceManager);
     $this->assertSame('http://example.com/foo/foo/my.jpg', $userFile->getUrl());
     $userFile = new CM_File_UserContent('bar', 'my.jpg', null, $serviceManager);
     $this->assertSame('http://example.com/default/bar/my.jpg', $userFile->getUrl());
 }
Example #2
0
 /**
  * @param string  $streamChannelMediaId
  * @param CM_File $archiveSource
  * @throws CM_Exception_Invalid
  */
 public function importArchive($streamChannelMediaId, CM_File $archiveSource)
 {
     $streamChannelMediaId = (string) $streamChannelMediaId;
     $streamChannelArchive = CM_Model_StreamChannelArchive_Media::findByMediaId($streamChannelMediaId);
     if (!$streamChannelArchive) {
         $streamChannel = CM_Model_StreamChannel_Media::findByMediaId($streamChannelMediaId);
         if ($streamChannel) {
             throw new CM_Exception_Invalid('Archive not created, please try again later', null, ['streamChannelMediaId' => $streamChannelMediaId]);
         }
         $exception = new CM_Exception_Invalid('Archive not found, stream channel not found, skipping', CM_Exception::WARN, ['streamChannelMediaId' => $streamChannelMediaId]);
         $context = new CM_Log_Context();
         $context->setException($exception);
         $this->getServiceManager()->getLogger()->warning('Archive creating error', $context);
         return;
     }
     $filename = $streamChannelArchive->getId() . '-' . $streamChannelArchive->getHash() . '-original.' . $archiveSource->getExtension();
     $archiveDestination = new CM_File_UserContent('streamChannels', $filename, $streamChannelArchive->getId());
     $archiveDestination->ensureParentDirectory();
     $archiveSource->copyToFile($archiveDestination);
     $streamChannelArchive->setFile($archiveDestination);
 }
Example #3
0
 /**
  * @param CM_File_UserContent $file
  * @return string
  */
 public function getUrlUserContent(CM_File_UserContent $file)
 {
     return $file->getUrl();
 }
Example #4
0
 public function delete($recursive = null)
 {
     CM_Db_Db::delete('cm_tmp_userfile', array('uniqid' => $this->getUniqid()));
     parent::delete();
 }
Example #5
0
 protected function _onDeleteBefore()
 {
     $this->getVideo()->delete();
     $thumbnailDir = new CM_File_UserContent('streamChannels', $this->getId() . '-' . $this->getHash() . '-thumbs/', $this->getId());
     $thumbnailDir->delete(true);
 }
Example #6
0
 protected function _onDeleteBefore()
 {
     if ($this->hasFile()) {
         $this->getFile()->delete();
     }
     $thumbnailDir = new CM_File_UserContent('streamChannels', $this->getId() . '-thumbs', $this->getId());
     $thumbnailDir->delete(true);
     /** @var CM_StreamChannel_Thumbnail $thumbnail */
     foreach ($this->getThumbnails() as $thumbnail) {
         $thumbnail->delete();
     }
 }