2014-09-18 19:30:12 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Upgrades;
|
|
|
|
|
|
|
|
class Upgrade04 implements IUpgrade
|
|
|
|
{
|
2014-09-21 09:35:43 +02:00
|
|
|
private $postDao;
|
2014-09-18 19:30:12 +02:00
|
|
|
private $postService;
|
|
|
|
private $fileService;
|
|
|
|
|
|
|
|
public function __construct(
|
2014-09-21 09:35:43 +02:00
|
|
|
\Szurubooru\Dao\PostDao $postDao,
|
2014-09-18 19:30:12 +02:00
|
|
|
\Szurubooru\Services\PostService $postService,
|
2014-09-21 09:35:43 +02:00
|
|
|
\Szurubooru\Services\FileService $fileService)
|
2014-09-18 19:30:12 +02:00
|
|
|
{
|
2014-09-21 09:35:43 +02:00
|
|
|
$this->postDao = $postDao;
|
2014-09-18 19:30:12 +02:00
|
|
|
$this->postService = $postService;
|
|
|
|
$this->fileService = $fileService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run(\Szurubooru\DatabaseConnection $databaseConnection)
|
|
|
|
{
|
2014-09-28 16:26:44 +02:00
|
|
|
$databaseConnection->getPDO()->exec('ALTER TABLE posts ADD COLUMN contentMimeType VARCHAR(64) DEFAULT NULL');
|
2014-09-20 12:45:56 +02:00
|
|
|
|
2014-09-21 09:35:43 +02:00
|
|
|
$posts = $this->postDao->findAll();
|
2014-09-18 19:30:12 +02:00
|
|
|
foreach ($posts as $post)
|
|
|
|
{
|
|
|
|
if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE)
|
|
|
|
{
|
2014-09-27 10:06:22 +02:00
|
|
|
$fullPath = $this->fileService->getFullPath($post->getContentPath());
|
2014-09-18 19:30:12 +02:00
|
|
|
$mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath);
|
|
|
|
$post->setContentMimeType($mime);
|
2014-09-21 09:35:43 +02:00
|
|
|
$this->postDao->save($post);
|
2014-09-18 19:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|