Skip to content

Commit

Permalink
MDL-31763 mod_data: Fixed array iteration reference issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed May 10, 2012
1 parent 83c9d44 commit c56d266
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions mod/data/lang/en/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
$string['cannotaccesspresentsother'] = 'You are not allowed to access presets from other users';
$string['cannotadd'] = 'Can not add entries!';
$string['cannotdeletepreset'] = 'Error deleting a preset!';
$string['cannotoverwritepreset'] = 'Error overwriting preset';
$string['cannotunziptopreset'] = 'Cannot unzip to the preset directory';
$string['columns'] = 'columns';
$string['comment'] = 'Comment';
Expand Down
16 changes: 11 additions & 5 deletions mod/data/preset.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@
$preset->description .= html_writer::link($delurl, $delicon);
}
}
// This is required because its currently bound to the last element in the array.
// If someone were to inadvently use it again and this call were not here
unset($preset);

$form_importexisting = new data_existing_preset_form(null, array('presets'=>$presets));
$form_importexisting->set_data(array('d' => $data->id));
Expand Down Expand Up @@ -145,12 +148,15 @@
foreach ($presets as $preset) {
if ($preset->name == $formdata->name) {
$selectedpreset = $preset;
break;
}
}
if (data_user_can_delete_preset($context, $selectedpreset)) {
data_delete_site_preset($formdata->name);
} else {
print_error('cannotdeletepreset', 'data');
if (isset($selectedpreset->name)) {
if (data_user_can_delete_preset($context, $selectedpreset)) {
data_delete_site_preset($formdata->name);
} else {
print_error('cannotoverwritepreset', 'data');
}
}
}

Expand Down Expand Up @@ -199,7 +205,7 @@
$selectedpreset = $preset;
}
}
if (!data_user_can_delete_preset($context, $selectedpreset)) {
if (!isset($selectedpreset->shortname) || !data_user_can_delete_preset($context, $selectedpreset)) {
print_error('invalidrequest');
}

Expand Down

0 comments on commit c56d266

Please sign in to comment.