Computing preference updates

* Added descriptions to make it less confusing when "0 means no limit"
* Fixed bug in preset admin form that could break the submitter's preferences rather than update the preset

(DBOINCP-99)
This commit is contained in:
Tristan Olive 2014-03-25 10:42:17 -04:00
parent 95ac7d1a63
commit fb7b961312
2 changed files with 9 additions and 5 deletions

View File

@ -88,7 +88,11 @@ function boincwork_admin_prefs_presets_page($preset = 'standard') {
function boincwork_admin_prefs_presets_form(&$form_state, $preset = 'standard') { function boincwork_admin_prefs_presets_form(&$form_state, $preset = 'standard') {
// Load a copy of the general prefs form // Load a copy of the general prefs form
$form = drupal_retrieve_form('boincwork_generalprefs_form', $form_state, NULL, $preset); $form = boincwork_generalprefs_form($form_state, NULL, $preset);
if ($key = array_search('boincwork_generalprefs_form_submit', $form['#submit'])) {
unset($form['#submit'][$key]);
}
$form['#submit'][] = 'boincwork_admin_prefs_presets_form_submit';
// Just keep the necessary items // Just keep the necessary items
$form['processor'] = $form['prefs']['advanced']['processor']; $form['processor'] = $form['prefs']['advanced']['processor'];
@ -205,7 +209,7 @@ function boincwork_admin_prefs_presets_form_submit($form, &$form_state) {
$prefs['dont_verify_images'] = ($values['network']['dont_verify_images']) ? 1 : 0; $prefs['dont_verify_images'] = ($values['network']['dont_verify_images']) ? 1 : 0;
// Throw the preset attribute on there so we know which preset to save // Throw the preset attribute on there so we know which preset to save
$prefs['ATTRIBUTES']['preset'] = $preset; $prefs['@attributes']['preset'] = $preset;
// Update the configuration // Update the configuration
boincwork_save_preset_prefs($prefs, $preset); boincwork_save_preset_prefs($prefs, $preset);
@ -229,7 +233,7 @@ function boincwork_save_preset_prefs($updated_prefs, $preset = 'standard') {
} }
foreach ($all_presets['preset'] as $key => $old_preset) { foreach ($all_presets['preset'] as $key => $old_preset) {
// Find the preset being updated and... update it // Find the preset being updated and... update it
if (isset($old_preset['ATTRIBUTES']['name']) AND $old_preset['ATTRIBUTES']['name'] == $preset) { if (isset($old_preset['@attributes']['name']) AND $old_preset['@attributes']['name'] == $preset) {
$all_presets['preset'][$key] = $updated_prefs + $old_preset; $all_presets['preset'][$key] = $updated_prefs + $old_preset;
} }
} }

View File

@ -295,7 +295,7 @@ function boincwork_generalprefs_form(&$form_state, $venue, $prefs_preset = null,
'#field_suffix' => t('processors'), '#field_suffix' => t('processors'),
'#default_value' => $default['max_cpus'], '#default_value' => $default['max_cpus'],
'#size' => 1, '#size' => 1,
'#description' => ' ' '#description' => t('Set to 0 for no limit'),
); );
$form['prefs']['advanced']['processor']['max_ncpus_pct'] = array( $form['prefs']['advanced']['processor']['max_ncpus_pct'] = array(
'#title' => t('On multiprocessors, use at most'), '#title' => t('On multiprocessors, use at most'),
@ -328,7 +328,7 @@ function boincwork_generalprefs_form(&$form_state, $venue, $prefs_preset = null,
'#field_suffix' => t('GB'), '#field_suffix' => t('GB'),
'#default_value' => $default['disk_max_used_gb'], '#default_value' => $default['disk_max_used_gb'],
'#size' => 1, '#size' => 1,
'#description' => ' ' '#description' => t('Set to 0 for no limit'),
); );
$form['prefs']['advanced']['storage']['disk_min_free_gb'] = array( $form['prefs']['advanced']['storage']['disk_min_free_gb'] = array(
'#title' => t('Disk: leave free at least'), '#title' => t('Disk: leave free at least'),