redirect($redirect); break; case 'deletecategory': $id = required_param('id', PARAM_INT); if (confirm_sesskey()) { profile_delete_category($id); } redirect($redirect, get_string('deleted')); break; case 'deletefield': $id = required_param('id', PARAM_INT); $confirm = optional_param('confirm', 0, PARAM_BOOL); // If no userdata for profile than don't show confirmation. $datacount = $DB->count_records('user_info_data', array('fieldid' => $id)); if ((data_submitted() and $confirm or $datacount === 0) and confirm_sesskey()) { profile_delete_field($id); redirect($redirect, get_string('deleted')); } // Ask for confirmation, as there is user data available for field. $fieldname = $DB->get_field('user_info_field', 'name', array('id' => $id)); $optionsyes = array('id' => $id, 'confirm' => 1, 'action' => 'deletefield', 'sesskey' => sesskey()); $strheading = get_string('profiledeletefield', 'admin', $fieldname); $PAGE->navbar->add($strheading); echo $OUTPUT->header(); echo $OUTPUT->heading($strheading); $formcontinue = new single_button(new moodle_url($redirect, $optionsyes), get_string('yes'), 'post'); $formcancel = new single_button(new moodle_url($redirect), get_string('no'), 'get'); echo $OUTPUT->confirm(get_string('profileconfirmfielddeletion', 'admin', $datacount), $formcontinue, $formcancel); echo $OUTPUT->footer(); die; break;
/** * Test sync-ing an ELIS User Profile field to a DELETED Moodle User Profile field */ public function test_syncpmuserfieldtodeletedmoodleprofilefield() { global $CFG, $DB; require_once $CFG->dirroot . '/user/profile/definelib.php'; $this->load_csv_data(); // Set PM Custom User field(s) to Sync to Moodle. $ctxlvl = CONTEXT_ELIS_USER; $fields = field::get_for_context_level($ctxlvl); foreach ($fields as $field) { $fieldobj = new field($field); if (!isset($fieldobj->owners['moodle_profile'])) { $fieldobj->owners['moodle_profile'] = new stdClass(); } $owner = new field_owner($fieldobj->owners['moodle_profile']); $owner->exclude = pm_moodle_profile::sync_from_moodle; $owner->save(); $fieldobj->save(); } // Read a record. $src = new user(103, null, array(), false, array()); $src->reset_custom_field_list(); // Modify the data. $src->firstname = 'Testuser'; $src->lastname = 'One'; $src->field_sometext = 'boo'; $src->field_sometextfrompm = 'bla'; $src->save(); // Delete some custom Moodle Profile field(s) to cause old error (pre ELIS-4499). $fields = field::get_for_context_level($ctxlvl); foreach ($fields as $field) { $fieldobj = new field($field); if ($moodlefield = $DB->get_record('user_info_field', array('shortname' => $fieldobj->shortname))) { profile_delete_field($moodlefield->id); } } // Run the library sync - throws errors not exceptions :(. $CFG->mnet_localhost_id = 1; // ??? $mu = cm_get_moodleuser(103); try { $result = pm_moodle_user_to_pm($mu); $this->assertTrue($result); } catch (Exception $ex) { $this->assertTrue(false, $ex->message); } }