mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #4348 from dhensby/pulls/3.2/fix-orphaned-passwords
FIX MemberPassword history removed with with Members
This commit is contained in:
commit
d85590ddb9
@ -59,7 +59,9 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
|
|
||||||
private static $has_one = array();
|
private static $has_one = array();
|
||||||
|
|
||||||
private static $has_many = array();
|
private static $has_many = array(
|
||||||
|
'LoggedPasswords' => 'MemberPassword',
|
||||||
|
);
|
||||||
|
|
||||||
private static $many_many = array();
|
private static $many_many = array();
|
||||||
|
|
||||||
@ -879,6 +881,26 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onAfterDelete() {
|
||||||
|
parent::onAfterDelete();
|
||||||
|
|
||||||
|
//prevent orphaned records remaining in the DB
|
||||||
|
$this->deletePasswordLogs();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the MemberPassword objects that are associated to this user
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
protected function deletePasswordLogs() {
|
||||||
|
foreach ($this->LoggedPasswords() as $password) {
|
||||||
|
$password->delete();
|
||||||
|
$password->destroy();
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If any admin groups are requested, deny the whole save operation.
|
* If any admin groups are requested, deny the whole save operation.
|
||||||
*
|
*
|
||||||
|
@ -172,6 +172,13 @@ class MemberTest extends FunctionalTest {
|
|||||||
$this->assertInstanceOf('DataObject', $passwords->current());
|
$this->assertInstanceOf('DataObject', $passwords->current());
|
||||||
$this->assertTrue($passwords->current()->checkPassword('1nitialPassword'),
|
$this->assertTrue($passwords->current()->checkPassword('1nitialPassword'),
|
||||||
"Password 1nitialPassword not found in MemberRecord");
|
"Password 1nitialPassword not found in MemberRecord");
|
||||||
|
|
||||||
|
//check we don't retain orphaned records when a member is deleted
|
||||||
|
$member->delete();
|
||||||
|
|
||||||
|
$passwords = MemberPassword::get()->filter('MemberID', $member->OldID);
|
||||||
|
|
||||||
|
$this->assertCount(0, $passwords);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user