diff --git a/src/Dao/AbstractDao.php b/src/Dao/AbstractDao.php index 4a7ae452..f863b1e3 100644 --- a/src/Dao/AbstractDao.php +++ b/src/Dao/AbstractDao.php @@ -22,12 +22,6 @@ abstract class AbstractDao implements ICrudDao }); } - public function setDatabaseConnection(\Szurubooru\DatabaseConnection $databaseConnection) - { - $this->pdo = $databaseConnection->getPDO(); - $this->fpdo = new \FluentPDO($this->pdo); - } - public function getTableName() { return $this->tableName; @@ -189,6 +183,12 @@ abstract class AbstractDao implements ICrudDao return $entities; } + private function setDatabaseConnection(\Szurubooru\DatabaseConnection $databaseConnection) + { + $this->pdo = $databaseConnection->getPDO(); + $this->fpdo = new \FluentPDO($this->pdo); + } + private function decorateQueryFromFilter($query, \Szurubooru\SearchServices\Filters\IFilter $filter) { foreach ($filter->getRequirements() as $requirement) diff --git a/src/Injector.php b/src/Injector.php index 4f8b665f..d8a56e77 100644 --- a/src/Injector.php +++ b/src/Injector.php @@ -22,6 +22,11 @@ final class Injector { return self::$container->get($className); } + + public static function set($className, $object) + { + return self::$container->set($className, $object); + } } Injector::init(); diff --git a/src/Upgrades/Upgrade04.php b/src/Upgrades/Upgrade04.php index 1e76f5ed..ca879ea6 100644 --- a/src/Upgrades/Upgrade04.php +++ b/src/Upgrades/Upgrade04.php @@ -19,8 +19,6 @@ class Upgrade04 implements IUpgrade public function run(\Szurubooru\DatabaseConnection $databaseConnection) { - $this->postDao->setDatabaseConnection($databaseConnection); - $databaseConnection->getPDO()->exec('ALTER TABLE "posts" ADD COLUMN contentMimeType TEXT DEFAULT NULL'); $posts = $this->postDao->findAll(); @@ -28,7 +26,7 @@ class Upgrade04 implements IUpgrade { if ($post->getContentType() !== \Szurubooru\Entities\Post::POST_TYPE_YOUTUBE) { - $fullPath = $this->fileService->getFullPath($this->postService->getPostContentPath($post)); + $fullPath = $this->fileService->getFullPath($post->getContentPath()); $mime = \Szurubooru\Helpers\MimeHelper::getMimeTypeFromFile($fullPath); $post->setContentMimeType($mime); $this->postDao->save($post); diff --git a/tests/AbstractDatabaseTestCase.php b/tests/AbstractDatabaseTestCase.php index 2fead051..42fa02f2 100644 --- a/tests/AbstractDatabaseTestCase.php +++ b/tests/AbstractDatabaseTestCase.php @@ -12,6 +12,7 @@ abstract class AbstractDatabaseTestCase extends \Szurubooru\Tests\AbstractTestCa $config->set('database/dsn', 'sqlite::memory:'); $this->databaseConnection = new \Szurubooru\DatabaseConnection($config); + \Szurubooru\Injector::set(\Szurubooru\DatabaseConnection::class, $this->databaseConnection); $upgradeRepository = \Szurubooru\Injector::get(\Szurubooru\Upgrades\UpgradeRepository::class); $upgradeService = new \Szurubooru\Services\UpgradeService($config, $this->databaseConnection, $upgradeRepository); diff --git a/tests/AbstractTestCase.php b/tests/AbstractTestCase.php index 64b8699e..e78f38d4 100644 --- a/tests/AbstractTestCase.php +++ b/tests/AbstractTestCase.php @@ -36,6 +36,11 @@ abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase return __DIR__ . DIRECTORY_SEPARATOR . 'test_files' . DIRECTORY_SEPARATOR . $fileName; } + protected function setUp() + { + \Szurubooru\Injector::init(); + } + protected function tearDown() { $this->cleanTestDirectory();