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)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@100716 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
9c75acb113
commit
4eed1360c4
@ -160,23 +160,40 @@ class MemberTableField extends ComplexTableField {
|
|||||||
*/
|
*/
|
||||||
function addtogroup() {
|
function addtogroup() {
|
||||||
$data = $_REQUEST;
|
$data = $_REQUEST;
|
||||||
unset($data['ID']);
|
$groupID = (isset($data['ctf']['ID'])) ? $data['ctf']['ID'] : null;
|
||||||
$ctfID = isset($data['ctf']) ? $data['ctf']['ID'] : null;
|
|
||||||
|
|
||||||
if(!is_numeric($ctfID)) {
|
if(!is_numeric($groupID)) {
|
||||||
FormResponse::status_messsage(_t('MemberTableField.ADDINGFIELD', 'Adding failed'), 'bad');
|
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;
|
$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);
|
$record->update($data);
|
||||||
|
|
||||||
|
// Validate record, mainly password restrictions.
|
||||||
|
// Note: Doesn't use Member_Validator
|
||||||
$valid = $record->validate();
|
$valid = $record->validate();
|
||||||
|
|
||||||
if($valid->valid()) {
|
if($valid->valid()) {
|
||||||
$record->write();
|
$record->write();
|
||||||
$record->Groups()->add($ctfID);
|
$record->Groups()->add($groupID);
|
||||||
|
|
||||||
$this->sourceItems();
|
$this->sourceItems();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user