Added post mime type saving

This commit is contained in:
Marcin Kurczewski 2014-09-18 19:30:12 +02:00
parent 34752529b5
commit 13a15a3a6b
7 changed files with 52 additions and 2 deletions

View file

@ -11,7 +11,7 @@
<% } else if (post.contentType == 'flash') { %>
<object
type="application/x-shockwave-flash"
type="<%= post.contentMimeType %>"
width="<%= post.imageWidth %>"
height="<%= post.imageHeight %>"
data="<%= postContentUrl %>">
@ -22,7 +22,7 @@
<% } else if (post.contentType == 'video') { %>
<video controls>
<source src="<%= postContentUrl %>"/>
<source type="<%= post.contentMimeType %>" src="<%= postContentUrl %>"/>
Your browser doesn't support HTML5 videos.
</video>

View file

@ -16,6 +16,7 @@ class PostViewProxy extends AbstractViewProxy
$result->safety = \Szurubooru\Helpers\EnumHelper::postSafetyToString($post->getSafety());
$result->contentType = \Szurubooru\Helpers\EnumHelper::postTypeToString($post->getContentType());
$result->contentChecksum = $post->getContentChecksum();
$result->contentMimeType = $post->getContentMimeType();
$result->source = $post->getSource();
$result->imageWidth = $post->getImageWidth();
$result->imageHeight = $post->getImageHeight();

View file

@ -15,6 +15,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
'safety' => $entity->getSafety(),
'contentType' => $entity->getContentType(),
'contentChecksum' => $entity->getContentChecksum(),
'contentMimeType' => $entity->getContentMimeType(),
'source' => $entity->getSource(),
'imageWidth' => $entity->getImageWidth(),
'imageHeight' => $entity->getImageHeight(),
@ -33,6 +34,7 @@ class PostEntityConverter extends AbstractEntityConverter implements IEntityConv
$entity->setSafety(intval($array['safety']));
$entity->setContentType(intval($array['contentType']));
$entity->setContentChecksum($array['contentChecksum']);
$entity->setContentMimeType($array['contentMimeType']);
$entity->setSource($array['source']);
$entity->setImageWidth($array['imageWidth']);
$entity->setImageHeight($array['imageHeight']);

View file

@ -19,6 +19,7 @@ final class Post extends Entity
protected $safety;
protected $contentType;
protected $contentChecksum;
protected $contentMimeType;
protected $source;
protected $imageWidth;
protected $imageHeight;
@ -112,6 +113,16 @@ final class Post extends Entity
$this->contentChecksum = $contentChecksum;
}
public function getContentMimeType()
{
return $this->contentMimeType;
}
public function setContentMimeType($contentMimeType)
{
$this->contentMimeType = $contentMimeType;
}
public function getSource()
{
return $this->source;

View file

@ -131,6 +131,7 @@ class PostService
throw new \DomainException('Upload is too big.');
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromBuffer($content);
$post->setContentMimeType($mime);
if (\Szurubooru\Helpers\MimeHelper::isFlash($mime))
$post->setContentType(\Szurubooru\Entities\Post::POST_TYPE_FLASH);

View file

@ -0,0 +1,34 @@
<?php
namespace Szurubooru\Upgrades;
class Upgrade04 implements IUpgrade
{
private $postService;
private $fileService;
public function __construct(
\Szurubooru\Services\PostService $postService,
\Szurubooru\Services\FileService $fileService)
{
$this->postService = $postService;
$this->fileService = $fileService;
}
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL');
$postDao = new \Szurubooru\Dao\PostDao($databaseConnection);
$posts = $postDao->findAll();
foreach ($posts as $post)
{
if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE)
{
$fullPath = $this->fileService->getFullPath($this->postService->getPostContentPath($post));
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath);
$post->setContentMimeType($mime);
$postDao->save($post);
}
}
}
}

View file

@ -19,6 +19,7 @@ return [
$container->get(\Szurubooru\Upgrades\Upgrade01::class),
$container->get(\Szurubooru\Upgrades\Upgrade02::class),
$container->get(\Szurubooru\Upgrades\Upgrade03::class),
$container->get(\Szurubooru\Upgrades\Upgrade04::class),
];
}),