szurubooru/src/Upgrades/Upgrade04.php

35 lines
980 B
PHP
Raw Normal View History

2014-09-18 19:30:12 +02:00
<?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);
}
}
}
}