|
| 1 | +<?php |
| 2 | +// This file is part of Moodle - https://moodle.org/ |
| 3 | +// |
| 4 | +// Moodle is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// Moodle is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with Moodle. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +/** |
| 18 | + * Upgrade steps for tool_monitoring. |
| 19 | + * |
| 20 | + * @package tool_monitoring |
| 21 | + * @copyright 2025 MootDACH DevCamp |
| 22 | + * Daniel Fainberg <d.fainberg@tu-berlin.de> |
| 23 | + * Martin Gauk <martin.gauk@tu-berlin.de> |
| 24 | + * Sebastian Rupp <sr@artcodix.com> |
| 25 | + * Malte Schmitz <mal.schmitz@uni-luebeck.de> |
| 26 | + * Melanie Treitinger <melanie.treitinger@ruhr-uni-bochum.de> |
| 27 | + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 28 | + */ |
| 29 | + |
| 30 | +defined('MOODLE_INTERNAL') || die(); |
| 31 | + |
| 32 | +use tool_monitoring\registered_metric; |
| 33 | + |
| 34 | +/** |
| 35 | + * Upgrade code for the monitoring tool. |
| 36 | + * |
| 37 | + * @param int $oldversion |
| 38 | + * @return bool |
| 39 | + * @throws ddl_exception |
| 40 | + * @throws dml_exception |
| 41 | + */ |
| 42 | +function xmldb_tool_monitoring_upgrade(int $oldversion): bool { |
| 43 | + global $DB; |
| 44 | + |
| 45 | + if ($oldversion < 2026041000) { |
| 46 | + $transaction = $DB->start_delegated_transaction(); |
| 47 | + |
| 48 | + // The tag itemtype must match an existing DB table name. Older versions used "metrics", |
| 49 | + // but the actual records live in "tool_monitoring_metrics", so migrate both area and instances. |
| 50 | + $DB->set_field( |
| 51 | + 'tag_area', |
| 52 | + 'itemtype', |
| 53 | + registered_metric::TABLE, |
| 54 | + ['component' => 'tool_monitoring', 'itemtype' => 'metrics'] |
| 55 | + ); |
| 56 | + $DB->set_field( |
| 57 | + 'tag_instance', |
| 58 | + 'itemtype', |
| 59 | + registered_metric::TABLE, |
| 60 | + ['component' => 'tool_monitoring', 'itemtype' => 'metrics'] |
| 61 | + ); |
| 62 | + |
| 63 | + $transaction->allow_commit(); |
| 64 | + |
| 65 | + upgrade_plugin_savepoint(true, 2026041000, 'tool', 'monitoring'); |
| 66 | + } |
| 67 | + |
| 68 | + return true; |
| 69 | +} |
0 commit comments