diff --git a/db/migrations/6.0.4_adjust_cache_types_table.php b/db/migrations/6.0.4_adjust_cache_types_table.php new file mode 100644 index 0000000000000000000000000000000000000000..dfe0b27466daa39de2e1ab428ca11beaf3815463 --- /dev/null +++ b/db/migrations/6.0.4_adjust_cache_types_table.php @@ -0,0 +1,37 @@ +<?php +return new class extends Migration +{ + private const MAPPING = [ + StudipDbCache::class => Studip\Cache\DbCache::class, + StudipFileCache::class => Studip\Cache\FileCache::class, + StudipMemcachedCache::class => Studip\Cache\MemcachedCache::class, + StudipRedisCache::class => Studip\Cache\RedisCache::class, + ]; + + public function description() + { + return 'Replaces the renamed cache classes in table "cache_types"'; + } + + protected function up() + { + foreach (self::MAPPING as $old => $new) { + self::updateCacheTypesTable($old, $new); + } + } + + protected function down() + { + foreach (self::MAPPING as $old => $new) { + self::updateCacheTypesTable($new, $old); + } + } + + private function updateCacheTypesTable(string $old, string $new): void + { + $query = "UPDATE `cache_types` + SET `class_name` = ? + WHERE `class_name` = ?"; + DBManager::get()->execute($query, [$new, $old]); + } +};