mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
BUGFIX Fixed MemberTableField->addtogroup() to fetch existing Member records by ID or $unique_identifier_field instead of relying on the (now removed) "auto-merging" in Member->onBeforeWrite() (see r100705) (from r100716)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/branches/2.4@100719 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
3f6a4dedfd
commit
9466e07335
@ -159,23 +159,40 @@ class MemberTableField extends ComplexTableField {
|
||||
*/
|
||||
function addtogroup() {
|
||||
$data = $_REQUEST;
|
||||
unset($data['ID']);
|
||||
$ctfID = isset($data['ctf']) ? $data['ctf']['ID'] : null;
|
||||
$groupID = (isset($data['ctf']['ID'])) ? $data['ctf']['ID'] : null;
|
||||
|
||||
if(!is_numeric($ctfID)) {
|
||||
if(!is_numeric($groupID)) {
|
||||
FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
|
||||
return;
|
||||
}
|
||||
|
||||
// Get existing record either by ID or unique identifier.
|
||||
$identifierField = Member::get_unique_identifier_field();
|
||||
$className = self::$data_class;
|
||||
$record = new $className();
|
||||
$record = null;
|
||||
if(isset($data['ID']) && $data['ID']) {
|
||||
$record = DataObject::get_by_id($className, $data['ID']);
|
||||
} elseif(isset($data[$identifierField])) {
|
||||
$record = DataObject::get_one(
|
||||
$className,
|
||||
sprintf('"%s" = \'%s\'', $identifierField, $data[$identifierField])
|
||||
);
|
||||
}
|
||||
|
||||
// Fall back to creating a new record
|
||||
if(!$record) $record = new $className();
|
||||
|
||||
// Update an existing record, or populate a new one.
|
||||
// If values on an existing (autocompleted) record have been changed,
|
||||
// they will overwrite current data.
|
||||
$record->update($data);
|
||||
|
||||
// Validate record, mainly password restrictions.
|
||||
// Note: Doesn't use Member_Validator
|
||||
$valid = $record->validate();
|
||||
|
||||
if($valid->valid()) {
|
||||
$record->write();
|
||||
$record->Groups()->add($ctfID);
|
||||
$record->Groups()->add($groupID);
|
||||
|
||||
$this->sourceItems();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user