szurubooru/src/Upgrades/Upgrade04.php

42 lines
1.1 KiB
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;
private $thumbnailService;
2014-09-18 19:30:12 +02:00
public function __construct(
\Szurubooru\Services\PostService $postService,
\Szurubooru\Services\FileService $fileService,
\Szurubooru\Services\ThumbnailService $thumbnailService)
2014-09-18 19:30:12 +02:00
{
$this->postService = $postService;
$this->fileService = $fileService;
$this->thumbnailService = $thumbnailService;
2014-09-18 19:30:12 +02:00
}
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
{
$databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL');
$postDao = new \Szurubooru\Dao\PostDao(
$databaseConnection,
$this->fileService,
$this->thumbnailService);
2014-09-18 19:30:12 +02:00
$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);
}
}
}
}