aboutsummaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorMoritz Strohm <strohm@data-quest.de>2024-05-14 07:22:47 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-05-14 07:22:47 +0000
commit40bdfaf4415ff9f46e63435fc5e61049649802f2 (patch)
treef3ae85d9edaef23db555a829571ff968c21f9af5 /db
parent636039e25ccc6c33ae758bdb3ddfca4f68327948 (diff)
made Stud.IP cache compatible with PSR-6, re #3701
Merge request studip/studip!2570
Diffstat (limited to 'db')
-rw-r--r--db/migrations/1.154_recalculate_score.php3
-rw-r--r--db/migrations/1.224_db_cache_table.php2
-rw-r--r--db/migrations/1.318_step_00353_cache.php13
-rw-r--r--db/migrations/5.5.26_tic3193_no_unlimited_courses.php5
-rw-r--r--db/migrations/6.0.3_adjust_cache_configuration.php38
5 files changed, 51 insertions, 10 deletions
diff --git a/db/migrations/1.154_recalculate_score.php b/db/migrations/1.154_recalculate_score.php
index 158582e..5568363 100644
--- a/db/migrations/1.154_recalculate_score.php
+++ b/db/migrations/1.154_recalculate_score.php
@@ -38,7 +38,7 @@ class RecalculateScore extends Migration {
private static function getScore($user_id)
{
$user_id || $user_id = $GLOBALS['user']->id;
- $cache = StudipCacheFactory::getCache();
+ $cache = \Studip\Cache\Factory::getCache();
if ($cache->read("user_score_of_".$user_id)) {
return $cache->read("user_score_of_".$user_id);
}
@@ -142,4 +142,3 @@ class RecalculateScore extends Migration {
}
}
-
diff --git a/db/migrations/1.224_db_cache_table.php b/db/migrations/1.224_db_cache_table.php
index 66227d0..9abe7e3 100644
--- a/db/migrations/1.224_db_cache_table.php
+++ b/db/migrations/1.224_db_cache_table.php
@@ -17,7 +17,7 @@ class DbCacheTable extends Migration
PRIMARY KEY (cache_key)
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC');
- StudipCacheFactory::getCache()->flush();
+ \Studip\Cache\Factory::getCache()->flush();
}
public function down()
diff --git a/db/migrations/1.318_step_00353_cache.php b/db/migrations/1.318_step_00353_cache.php
index 901db60..5959945 100644
--- a/db/migrations/1.318_step_00353_cache.php
+++ b/db/migrations/1.318_step_00353_cache.php
@@ -1,5 +1,10 @@
<?php
+use Studip\Cache\DbCache;
+use Studip\Cache\FileCache;
+use Studip\Cache\MemcachedCache;
+use Studip\Cache\RedisCache;
+
class Step00353Cache extends Migration
{
public function description()
@@ -20,10 +25,10 @@ class Step00353Cache extends Migration
) ENGINE=InnoDB ROW_FORMAT=DYNAMIC");
$types = [
- 'StudipDbCache',
- 'StudipFileCache',
- 'StudipMemcachedCache',
- 'StudipRedisCache'
+ DbCache::class,
+ FileCache::class,
+ MemcachedCache::class,
+ RedisCache::class,
];
// Insert pre-defined cache types in to database
diff --git a/db/migrations/5.5.26_tic3193_no_unlimited_courses.php b/db/migrations/5.5.26_tic3193_no_unlimited_courses.php
index ef45bce..21a80ca 100644
--- a/db/migrations/5.5.26_tic3193_no_unlimited_courses.php
+++ b/db/migrations/5.5.26_tic3193_no_unlimited_courses.php
@@ -12,15 +12,14 @@ final class Tic3193NoUnlimitedCourses extends Migration
DBManager::get()->exec("
ALTER TABLE `sem_classes` ADD `unlimited_forbidden` TINYINT UNSIGNED NOT NULL DEFAULT 0 AFTER `is_group`
");
- $cache = StudipCacheFactory::getCache();
+ $cache = \Studip\Cache\Factory::getCache();
$cache->expire('DB_SEM_CLASSES_ARRAY');
}
public function down()
{
DBManager::get()->exec("ALTER TABLE `sem_classes` DROP `unlimited_forbidden`");
- $cache = StudipCacheFactory::getCache();
+ $cache = \Studip\Cache\Factory::getCache();
$cache->expire('DB_SEM_CLASSES_ARRAY');
}
}
-
diff --git a/db/migrations/6.0.3_adjust_cache_configuration.php b/db/migrations/6.0.3_adjust_cache_configuration.php
new file mode 100644
index 0000000..2432e84
--- /dev/null
+++ b/db/migrations/6.0.3_adjust_cache_configuration.php
@@ -0,0 +1,38 @@
+<?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 system configuration';
+ }
+
+ protected function up()
+ {
+ foreach (self::MAPPING as $old => $new) {
+ self::replaceCache($old, $new);
+ }
+ }
+
+ protected function down()
+ {
+ foreach (self::MAPPING as $old => $new) {
+ self::replaceCache($new, $old);
+ }
+ }
+
+ private function replaceCache(string $old, string $new): void
+ {
+ $query = "UPDATE `config_values`
+ SET `value` = JSON_REPLACE(`value`, '$.type', ?)
+ WHERE `field` = 'SYSTEMCACHE'
+ AND JSON_CONTAINS(`value`, JSON_QUOTE(?), '$.type')";
+ DBManager::get()->execute($query, [$new, $old]);
+ }
+};