aboutsummaryrefslogtreecommitdiff
path: root/db/migrations/5.5.37_cleanup_wiki_startpage_parent.php
blob: 74c188a831cd56360e78a476cdd2e833de3a9034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
/**
 * @see https://gitlab.studip.de/studip/studip/-/issues/5946
 */
class CleanupWikiStartpageParent extends Migration
{
    public function up(): void
    {
        $query = "SELECT `range_id`, `value`
                  FROM `config_values`
                  WHERE `field` = 'WIKI_STARTPAGE_ID'";
        $pages = DBManager::get()->fetchAll($query);

        $query = "UPDATE `wiki_pages`
                  SET `parent_id` = NULL
                  WHERE `page_id` = ? AND `range_id` = ?";
        $statement = DBManager::get()->prepare($query);
        foreach ($pages as [$range_id, $page_id]) {
            $statement->execute([$page_id, $range_id]);
        }
    }
}