Skip to content

Commit 0b55da2

Browse files
committed
MDL-87816: Add hooks before and after langpack update
1 parent 5f23e7e commit 0b55da2

3 files changed

Lines changed: 95 additions & 0 deletions

File tree

public/admin/tool/langimport/classes/controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ public function update_all_installed_languages() {
214214
}
215215
}
216216

217+
// Dispatch hook before updating language packs.
218+
$hook = new \tool_langimport\hook\before_langpacks_updated($neededlangs);
219+
\core\di::get(\core\hook\manager::class)->dispatch($hook);
220+
217221
try {
218222
$updated = $this->install_languagepacks($neededlangs, true);
219223
} catch (\moodle_exception $e) {
@@ -223,6 +227,11 @@ public function update_all_installed_languages() {
223227

224228
if ($updated) {
225229
$this->info[] = get_string('langupdatecomplete', 'tool_langimport');
230+
231+
// Dispatch hook before purging the string cache.
232+
$hook = new \tool_langimport\hook\after_langpacks_updated($neededlangs);
233+
\core\di::get(\core\hook\manager::class)->dispatch($hook);
234+
226235
// The strings have been changed so we need to purge their cache to ensure users see the changes.
227236
get_string_manager()->reset_caches();
228237
} else {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
16+
17+
namespace tool_langimport\hook;
18+
19+
/**
20+
* Hook dispatched after language packs have been updated, before the string cache is purged.
21+
*
22+
* This hook allows plugins to perform actions after language pack updates
23+
* are completed but before the language string cache is reset.
24+
*
25+
* @package tool_langimport
26+
* @copyright 2026 ISB Bayern
27+
* @author Dr. Peter Mayer
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
*/
30+
#[\core\attribute\label('Allows plugins to perform actions after language packs are updated, before the string cache is purged.')]
31+
#[\core\attribute\tags('language', 'langimport')]
32+
class after_langpacks_updated {
33+
/**
34+
* Constructor for the hook.
35+
*
36+
* @param array $updatedlangs Array of language codes that were updated.
37+
*/
38+
public function __construct(
39+
/** @var array Array of language codes that were updated */
40+
public readonly array $updatedlangs,
41+
) {
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
// This file is part of Moodle - http://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 <http://www.gnu.org/licenses/>.
16+
17+
namespace tool_langimport\hook;
18+
19+
/**
20+
* Hook dispatched before language packs are updated.
21+
*
22+
* This hook allows plugins to perform actions before language pack updates
23+
* are executed, such as backing up current translations or preparing for changes.
24+
*
25+
* @package tool_langimport
26+
* @copyright 2026 ISB Bayern
27+
* @author Dr. Peter Mayer
28+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29+
*/
30+
#[\core\attribute\label('Allows plugins to perform actions before language packs are updated.')]
31+
#[\core\attribute\tags('language', 'langimport')]
32+
class before_langpacks_updated {
33+
/**
34+
* Constructor for the hook.
35+
*
36+
* @param array $langstobeupated Array of language codes that will be updated.
37+
*/
38+
public function __construct(
39+
/** @var array Array of language codes that will be updated */
40+
public readonly array $langstobeupdated,
41+
) {
42+
}
43+
}

0 commit comments

Comments
 (0)