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

Fix bug which creates new admin public folders when more than one already exists


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 6e025cde
...@@ -1176,16 +1176,13 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase { ...@@ -1176,16 +1176,13 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
// name of the directory uses the site language rather than // name of the directory uses the site language rather than
// the language of the admin who first creates it. // the language of the admin who first creates it.
$name = get_string_from_language(get_config('lang'), 'adminpublicdirname', 'admin'); $name = get_string_from_language(get_config('lang'), 'adminpublicdirname', 'admin');
$folderid = get_field_sql(" $folders = get_records_select_array(
SELECT 'artefact',
a.id 'title = ? AND artefacttype = ? AND institution = ? AND parent IS NULL',
FROM {artefact} a array($name, 'folder', 'mahara'),
INNER JOIN {artefact_file_files} f ON a.id = f.artefact 'id', 'id', 0, 1
WHERE a.title = ? );
AND a.artefacttype = ? if (!$folders) {
AND a.institution = 'mahara'
AND a.parent IS NULL", array($name, 'folder'));
if (!$folderid) {
$description = get_string_from_language(get_config('lang'), 'adminpublicdirdescription', 'admin'); $description = get_string_from_language(get_config('lang'), 'adminpublicdirdescription', 'admin');
$data = (object) array('title' => $name, $data = (object) array('title' => $name,
'description' => $description, 'description' => $description,
...@@ -1194,25 +1191,21 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase { ...@@ -1194,25 +1191,21 @@ class ArtefactTypeFolder extends ArtefactTypeFileBase {
$f->commit(); $f->commit();
$folderid = $f->get('id'); $folderid = $f->get('id');
} }
return $folderid; return $folders[0]->id;
} }
public static function change_public_folder_name($oldlang, $newlang) { public static function change_public_folder_name($oldlang, $newlang) {
$oldname = get_string_from_language($oldlang, 'adminpublicdirname', 'admin'); $oldname = get_string_from_language($oldlang, 'adminpublicdirname', 'admin');
$folderid = get_field_sql(" $folders = get_records_select_array(
SELECT 'artefact',
a.id 'title = ? AND artefacttype = ? AND institution = ? AND parent IS NULL',
FROM {artefact} a array($oldname, 'folder', 'mahara'),
INNER JOIN {artefact_file_files} f ON a.id = f.artefact 'id', 'id', 0, 1
WHERE a.title = ? );
AND a.artefacttype = ? if (!$folders) {
AND a.institution = 'mahara'
AND a.parent IS NULL", array($oldname, 'folder'));
if (!$folderid) {
return; return;
} }
$folderid = $folders[0]->id;
$name = get_string_from_language($newlang, 'adminpublicdirname', 'admin'); $name = get_string_from_language($newlang, 'adminpublicdirname', 'admin');
$description = get_string_from_language($newlang, 'adminpublicdirdescription', 'admin'); $description = get_string_from_language($newlang, 'adminpublicdirdescription', 'admin');
if (!empty($name)) { if (!empty($name)) {
......
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