Commit da768090 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

The name of the admin public files directory is always in the site language;...

The name of the admin public files directory is always in the site language; change the name whenever the site language is changed
parent 3084cac8
......@@ -167,11 +167,17 @@ function siteoptions_submit(Pieform $form, $values) {
$fields = array('sitename','lang','theme','pathtofile', 'pathtoclam',
'defaultaccountlifetime', 'defaultaccountinactiveexpire', 'defaultaccountinactivewarn',
'allowpublicviews','artefactviewinactivitytime', 'searchplugin');
$oldlanguage = get_config('lang');
foreach ($fields as $field) {
if (!set_config($field, $values[$field])) {
siteoptions_fail($form, $field);
}
}
if ($oldlanguage != $values['lang']) {
safe_require('artefact', 'file');
ArtefactTypeFolder::change_public_folder_name($oldlanguage, $values['lang']);
}
// submitted sessionlifetime is in minutes; db entry session_timeout is in seconds
if (!set_config('session_timeout', $values['sessionlifetime'] * 60)) {
siteoptions_fail($form, 'sessionlifetime');
......
......@@ -773,7 +773,10 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
}
public static function admin_public_folder_id() {
$name = get_string('adminpublicdirname', 'admin');
// There is one public files directory and many admins, so the
// name of the directory uses the site language rather than
// the language of the admin who first creates it.
$name = get_string_from_language(get_config('lang'), 'adminpublicdirname', 'admin');
$folderid = get_field_sql('
SELECT
a.id
......@@ -786,7 +789,8 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
if (!$folderid) {
global $USER;
if (get_field('usr', 'admin', 'id', $USER->id)) {
$description = get_string('adminpublicdirdescription', 'admin');
$description = get_string_from_language(get_config('lang'),
'adminpublicdirdescription', 'admin');
$data = (object) array('title' => $name,
'description' => $description,
'owner' => $USER->id,
......@@ -801,6 +805,32 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
return $folderid;
}
public static function change_public_folder_name($oldlang, $newlang) {
$oldname = get_string_from_language($oldlang, 'adminpublicdirname', 'admin');
$folderid = get_field_sql('
SELECT
a.id
FROM {artefact} a
INNER JOIN {artefact_file_files} f ON a.id = f.artefact
WHERE a.title = ?
AND a.artefacttype = ?
AND f.adminfiles = 1
AND a.parent IS NULL', array($oldname, 'folder'));
if (!$folderid) {
return;
}
$name = get_string_from_language($newlang, 'adminpublicdirname', 'admin');
$description = get_string_from_language($newlang, 'adminpublicdirdescription', 'admin');
if (!empty($name)) {
$artefact = artefact_instance_from_id($folderid);
$artefact->set('title', $name);
$artefact->set('description', $description);
$artefact->commit();
}
}
public static function get_folder_by_name($name, $parentfolderid=null, $userid=null) {
if (empty($userid)) {
global $USER;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment