Пример #1
0
 protected function _process()
 {
     $path = $this->getRequest()->getPath();
     $content = null;
     $mimeType = null;
     if ($pathRaw = $this->getRender()->getLayoutPath('resource/' . $path, null, null, true, false)) {
         $file = new CM_File($pathRaw);
         if (in_array($file->getExtension(), $this->_getFiletypesForbidden())) {
             throw new CM_Exception_Nonexistent('Forbidden filetype', CM_Exception::WARN, ['path' => $path]);
         }
         $content = $file->read();
         $mimeType = $file->getMimeType();
     } elseif ($pathTpl = $this->getRender()->getLayoutPath('resource/' . $path . '.smarty', null, null, true, false)) {
         $content = $this->getRender()->fetchTemplate($pathTpl);
         $mimeType = CM_File::getMimeTypeByContent($content);
     } else {
         throw new CM_Exception_Nonexistent('Invalid filename', CM_Exception::WARN, ['path' => $path]);
     }
     $this->setHeader('Content-Type', $mimeType);
     $this->_setContent($content);
 }
Пример #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);
 }