szurubooru/src/Upgrades/Upgrade04.php

43 lines
1.1 KiB
PHP
Raw Normal View History

2014-09-18 19:30:12 +02:00
<?php
namespace Szurubooru\Upgrades;
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(
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;
}
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-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() !== Post::POST_TYPE_YOUTUBE)
2014-09-18 19:30:12 +02:00
{
$fullPath = $this->fileService->getFullPath($post->getContentPath());
$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
}
}
}
}