public function testFindByMediaId() { $this->assertNull(CM_Model_StreamChannelArchive_Media::findByMediaId('foo')); /** @var CM_Model_StreamChannel_Media $streamChannel */ $streamChannel = $streamChannel = CMTest_TH::createStreamChannel(null, null, 'foo'); $this->assertEquals($streamChannel, CM_Model_StreamChannel_Media::findByMediaId($streamChannel->getMediaId())); }
/** * @param string $streamName * @param int $streamChannelType * @param int $serverId * @param string|null $mediaId * @return CM_Model_StreamChannel_Abstract * @throws CM_Exception_Invalid */ public function createStreamChannel($streamName, $streamChannelType, $serverId, $mediaId = null) { if (null !== $mediaId) { $mediaId = (string) $mediaId; if (null !== CM_Model_StreamChannelArchive_Media::findByMediaId($mediaId)) { throw new CM_Exception_Invalid('Channel archive with this mediaId already exists', null, ['mediaId' => $mediaId]); } } return CM_Model_StreamChannel_Abstract::createType($streamChannelType, ['key' => $streamName, 'adapterType' => $this->_adapterType, 'serverId' => (int) $serverId, 'mediaId' => $mediaId]); }
/** * @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); }