Skip to content

Commit ea41197

Browse files
committed
Merge branch 'MDLSITE-6243_storage-upgrade'
2 parents 6a84a34 + e271f6c commit ea41197

39 files changed

+1967
-1872
lines changed

admin/newlanguage.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
require_login(SITEID, false);
3131
require_capability('local/amos:manage', context_system::instance());
3232

33+
$cache = cache::make('local_amos', 'listlanguages');
34+
$cache->delete('langs');
35+
3336
$PAGE->set_pagelayout('standard');
3437
$PAGE->set_url('/local/amos/admin/newlanguage.php');
3538
$PAGE->set_title('AMOS ' . get_string('newlanguage', 'local_amos'));
@@ -38,7 +41,7 @@
3841
$form = new local_amos_newlanguage_form();
3942

4043
if ($data = $form->get_data()) {
41-
$component = new mlang_component('langconfig', $data->langcode, mlang_version::by_code(mlang_version::MOODLE_40));
44+
$component = new mlang_component('langconfig', $data->langcode, mlang_version::latest_version());
4245
$data->langname = mlang_string::fix_syntax($data->langname);
4346
$data->langnameint = mlang_string::fix_syntax($data->langnameint);
4447
$component->add_string(new mlang_string('thislanguage', $data->langname));

classes/external/update_strings_file.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static function update_strings_file($userinfo, $message, $components) {
9999
$componentlanguage = $component['language'];
100100

101101
$componentversion = \mlang_version::by_dir($component['moodlebranch']);
102-
if (is_null($componentversion) or $componentversion->code < \mlang_version::MOODLE_20) {
102+
if (is_null($componentversion) || $componentversion->code <= 19) {
103103
throw new \invalid_parameter_exception('Unsupported Moodle branch');
104104
}
105105

@@ -162,7 +162,7 @@ public static function update_strings_file($userinfo, $message, $components) {
162162

163163
// Populate the list of staged components for later auto-merge.
164164
$componentnames = array();
165-
foreach ($stage->get_iterator() as $component) {
165+
foreach ($stage as $component) {
166166
$componentnames[] = $component->name;
167167
}
168168

@@ -171,12 +171,9 @@ public static function update_strings_file($userinfo, $message, $components) {
171171
// The following will throw exception if the commit fails.
172172
$stage->commit($message, array('source' => 'import', 'userinfo' => $userinfo), true);
173173

174-
// The import might have introduce a new component, clear the caches.
175-
\mlang_tools::list_components(false);
176-
177174
// Auto-merge updated components.
178175
foreach ($componentnames as $componentname) {
179-
\mlang_tools::auto_merge($componentname);
176+
\mlang_tools::backport_translations($componentname);
180177
}
181178

182179
// Done! Thank you for calling this web service.

classes/privacy/provider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ protected static function export_user_data_contributions(int $userid) {
301301

302302
$strings = [];
303303

304-
foreach ($stage->get_iterator() as $component) {
305-
foreach ($component->get_iterator() as $string) {
304+
foreach ($stage as $component) {
305+
foreach ($component as $string) {
306306
$strings[] = [
307307
'branch' => $string->component->version->code,
308308
'lang' => $string->component->lang,
@@ -392,8 +392,8 @@ protected static function export_user_data_stashes(int $userid) {
392392

393393
$strings = [];
394394

395-
foreach ($stage->get_iterator() as $component) {
396-
foreach ($component->get_iterator() as $string) {
395+
foreach ($stage as $component) {
396+
foreach ($component as $string) {
397397
$strings[] = [
398398
'branch' => $string->component->version->code,
399399
'lang' => $string->component->lang,

cli/automerge.php renamed to cli/backport.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?php
2-
3-
// This file is part of Moodle - http://moodle.org/
2+
// This file is part of Moodle - https://moodle.org/
43
//
54
// Moodle is free software: you can redistribute it and/or modify
65
// it under the terms of the GNU General Public License as published by
@@ -16,17 +15,16 @@
1615
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1716

1817
/**
19-
* Automerge components
18+
* CLI utility to backport all translations for all components on all branches.
2019
*
2120
* @package local_amos
22-
* @subpackage cli
23-
* @copyright 2013 David Mudrak <[email protected]>
24-
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21+
* @copyright 2020 David Mudrák <[email protected]>
22+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2523
*/
2624

2725
define('CLI_SCRIPT', true);
2826

29-
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . '/config.php');
27+
require(__DIR__ . '/../../../config.php');
3028
require_once($CFG->dirroot . '/local/amos/mlanglib.php');
3129
require_once($CFG->dirroot . '/local/amos/cli/utilslib.php');
3230
require_once($CFG->libdir.'/clilib.php');
@@ -56,27 +54,17 @@
5654

5755
$logger = new amos_cli_logger();
5856

59-
$logger->log('automerge', 'Loading list of components ...', amos_cli_logger::LEVEL_DEBUG);
60-
61-
$sql = "SELECT DISTINCT component
62-
FROM {amos_snapshot}
63-
WHERE lang = :lang";
64-
65-
$params = ['lang' => 'en'];
66-
67-
if (!empty($options['component'])) {
68-
$sql .= " AND component = :component";
69-
$params['component'] = $options['component'];
70-
}
71-
72-
$components = $DB->get_fieldset_sql($sql, $params);
57+
$logger->log('backport', 'Loading list of components ...', amos_cli_logger::LEVEL_DEBUG);
7358

59+
$components = array_keys(mlang_tools::list_components());
7460
$count = count($components);
7561
$i = 1;
62+
7663
foreach ($components as $component) {
77-
$logger->log('automerge', $i.'/'.$count.' automerging '.$component.' ...');
78-
mlang_tools::auto_merge($component);
64+
$logger->log('backport', sprintf('%d%% %d/%d backporting %s translations ...',
65+
floor($i / $count * 100), $i, $count, $component));
66+
mlang_tools::backport_translations($component);
7967
$i++;
8068
}
8169

82-
$logger->log('automerge', 'Done!');
70+
$logger->log('backport', 'Done!');

cli/clean-texts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
$tree = mlang_tools::components_tree();
4040
foreach ($tree as $vercode => $languages) {
41-
if ($vercode <= mlang_version::MOODLE_19) {
41+
if ($vercode <= 19) {
4242
continue;
4343
}
4444
$version = mlang_version::by_code($vercode);

cli/contrib-bulk.php

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* CLI script allowing to perform bulk operations over AMOS contributions.
19+
*
20+
* @package local_amos
21+
* @copyright 2020 David Mudrák <[email protected]>
22+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
define('CLI_SCRIPT', true);
26+
27+
require(__DIR__ . '/../../../config.php');
28+
require_once($CFG->libdir . '/clilib.php');
29+
require_once($CFG->dirroot . '/local/amos/locallib.php');
30+
31+
$usage = "Perform bulk operations over AMOS contributed translations.
32+
33+
Usage:
34+
# php contrib-bulk.php --user=<userid> --approve
35+
36+
Options:
37+
--author=<userid> User ID of the contributor.
38+
--approve Approve all the pending contributions by the user.
39+
40+
";
41+
42+
define('AMOS_BOT_USERID', 2);
43+
44+
[$options, $unrecognised] = cli_get_params([
45+
'help' => false,
46+
'author' => null,
47+
'approve' => false,
48+
], [
49+
'h' => 'help',
50+
'e' => 'execute',
51+
]);
52+
53+
if ($unrecognised) {
54+
$unrecognised = implode(PHP_EOL . ' ', $unrecognised);
55+
cli_error(get_string('cliunknowoption', 'core_admin', $unrecognised));
56+
}
57+
58+
if ($options['help']) {
59+
cli_writeln($usage);
60+
exit(2);
61+
}
62+
63+
if (empty($options['author'])) {
64+
cli_error('Missing mandatory argument: author', 2);
65+
}
66+
67+
$sql = "SELECT c.id, c.lang, c.subject, c.stashid, c.status, c.timecreated,
68+
s.components, s.strings, " .
69+
user_picture::fields('a', null, 'authorid', 'author') . "
70+
FROM {amos_contributions} c
71+
JOIN {amos_stashes} s ON (c.stashid = s.id)
72+
JOIN {user} a ON c.authorid = a.id
73+
WHERE c.status < :rejected
74+
AND a.id = :authorid
75+
ORDER BY c.timemodified";
76+
77+
$contributions = $DB->get_records_sql($sql, [
78+
'rejected' => local_amos_contribution::STATE_REJECTED,
79+
'authorid' => $options['author'],
80+
]);
81+
82+
$stage = new mlang_stage();
83+
84+
foreach ($contributions as $contribution) {
85+
echo sprintf("#%d\t%s\t%s\t%d\n", $contribution->id, $contribution->subject, $contribution->components, $contribution->strings);
86+
87+
if ($options['approve']) {
88+
$stash = mlang_stash::instance_from_id($contribution->stashid);
89+
$stash->apply($stage);
90+
91+
$stage->commit('Bulk approval - contribution #' . $contribution->id, [
92+
'source' => 'bot',
93+
'userinfo' => 'AMOS-bot <[email protected]>'
94+
]);
95+
96+
$update = [
97+
'id' => $contribution->id,
98+
'timemodified' => time(),
99+
'assignee' => AMOS_BOT_USERID,
100+
'status' => local_amos_contribution::STATE_ACCEPTED,
101+
];
102+
103+
$DB->update_record('amos_contributions', $update);
104+
}
105+
}

0 commit comments

Comments
 (0)