2014-09-18 19:30:12 +02:00
|
|
|
<?php
|
|
|
|
namespace Szurubooru\Upgrades;
|
2014-10-08 14:47:47 +02:00
|
|
|
use Szurubooru\Dao\PostDao;
|
|
|
|
use Szurubooru\DatabaseConnection;
|
|
|
|
use Szurubooru\Entities\Post;
|
|
|
|
use Szurubooru\Helpers\MimeHelper;
|
|
|
|
use Szurubooru\Services\FileService;
|
|
|
|
use Szurubooru\Services\PostService;
|
2014-09-18 19:30:12 +02:00
|
|
|
|
|
|
|
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-10-08 14:47:47 +02:00
|
|
|
PostDao $postDao,
|
|
|
|
PostService $postService,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-10-08 14:47:47 +02:00
|
|
|
public function run(DatabaseConnection $databaseConnection)
|
2014-09-18 19:30:12 +02:00
|
|
|
{
|
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)
|
|
|
|
{
|
2014-10-08 14:47:47 +02:00
|
|
|
if ($post->getContentType() !== Post::POST_TYPE_YOUTUBE)
|
2014-09-18 19:30:12 +02:00
|
|
|
{
|
2014-09-27 10:06:22 +02:00
|
|
|
$fullPath = $this->fileService->getFullPath($post->getContentPath());
|
2014-10-08 14:47:47 +02:00
|
|
|
$mime = MimeHelper::getMimeTypeFromFile($fullPath);
|
2014-09-18 19:30:12 +02:00
|
|
|
$post->setContentMimeType($mime);
|
2014-09-21 09:35:43 +02:00
|
|
|
$this->postDao->save($post);
|
2014-09-18 19:30:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|