Commit c30b06b0 authored by Nigel McNie's avatar Nigel McNie
Browse files

Fix a few bugs in profile icon handling, especially when deleting profile icons:

* Make sure all of the database work happens before deleting the image from disk, and do it in a transaction. This means that if the database reworking fails, the image won't be deleted accidentally.
* Make sure to clear the profileicon out of being in the view_artefact table
* Set a new default icon if the existing default is being deleted. This behaviour will change later, see bug #1774.
parent 0bab9ae6
......@@ -237,16 +237,34 @@ function settings_submit_delete(Pieform $form, $values) {
$icons = join(',', array_map('intval', $icons));
if ($icons) {
db_begin();
delete_records_select('view_artefact', "artefact IN ($icons)");
delete_records_select('artefact', "
artefacttype = 'profileicon' AND
owner = ? AND
id IN($icons)", array($USER->id));
// Remove all of the images
// Make sure a default is still set if possible. This behaviour will
// change later, see bug #1774
if (in_array($USER->get('profileicon'), explode(',', $icons))) {
if ($ids = get_records_select_array('artefact', "owner = ? AND artefacttype = 'profileicon'", array($USER->get('id')), '', 'id')) {
$USER->profileicon = $ids[0]->id;
}
else {
$USER->profileicon = null;
}
}
db_commit();
// Now all the database manipulation has happened successfully, remove
// all of the images
foreach (explode(',', $icons) as $icon) {
$USER->quota_remove(filesize(get_config('dataroot') . 'artefact/internal/profileicons/originals/' . ($icon % 256) . '/' . $icon));
$USER->commit();
delete_image('artefact/internal/profileicons', $icon);
}
$SESSION->add_ok_msg(get_string('profileiconsdeletedsuccessfully', 'artefact.internal'));
}
else {
......
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