Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Standardise extension hooks #11339

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Dev/Validation/DatabaseAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DatabaseAdminExtension extends Extension
* @param bool $testMode
* @throws ReflectionException
*/
public function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void
protected function onAfterBuild(bool $quiet, bool $populate, bool $testMode): void
{
$service = RelationValidationService::singleton();

Expand Down
16 changes: 8 additions & 8 deletions src/ORM/DataExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function __construct()
* @param ValidationResult $validationResult Local validation result
* @throws ValidationException
*/
public function validate(ValidationResult $validationResult)
protected function updateValidate(ValidationResult $validationResult)
{
}

Expand Down Expand Up @@ -112,7 +112,7 @@ protected function onAfterDelete()
*
* See {@link DataObject::requireDefaultRecords()} for context.
*/
public function requireDefaultRecords()
protected function onRequireDefaultRecords()
{
}

Expand All @@ -121,7 +121,7 @@ public function requireDefaultRecords()
*
* See {@link DataObject::populateDefaults()} for context.
*/
public function populateDefaults()
protected function onAfterPopulateDefaults()
{
}

Expand All @@ -130,7 +130,7 @@ public function populateDefaults()
*
* See {@link DataObject::onAfterBuild()} for context.
*/
public function onAfterBuild()
protected function onAfterBuild()
{
}

Expand All @@ -144,7 +144,7 @@ public function onAfterBuild()
* @param Member $member
* @return bool|null
*/
public function can($member)
protected function can($member)
{
}

Expand All @@ -158,7 +158,7 @@ public function can($member)
* @param Member $member
* @return bool|null
*/
public function canEdit($member)
protected function canEdit($member)
{
}

Expand All @@ -172,7 +172,7 @@ public function canEdit($member)
* @param Member $member
* @return bool|null
*/
public function canDelete($member)
protected function canDelete($member)
{
}

Expand All @@ -186,7 +186,7 @@ public function canDelete($member)
* @param Member $member
* @return bool|null
*/
public function canCreate($member)
protected function canCreate($member)
{
}

Expand Down
9 changes: 4 additions & 5 deletions src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ public function forceChange()
public function validate()
{
$result = ValidationResult::create();
$this->extend('validate', $result);
$this->extend('updateValidate', $result);
return $result;
}

Expand Down Expand Up @@ -1311,7 +1311,6 @@ protected function onAfterDelete()
* Will traverse the defaults of the current class and all its parent classes.
* Called by the constructor when creating new records.
*
* @uses DataExtension::populateDefaults()
* @return static $this
*/
public function populateDefaults()
Expand Down Expand Up @@ -1348,7 +1347,7 @@ public function populateDefaults()
}
}

$this->extend('populateDefaults');
$this->extend('onAfterPopulateDefaults');
return $this;
}

Expand Down Expand Up @@ -3542,7 +3541,7 @@ public function flushCache($persistent = true)
}
}

$this->extend('flushCache');
$this->extend('onFlushCache');

$this->components = [];
$this->eagerLoadedData = [];
Expand Down Expand Up @@ -3800,7 +3799,7 @@ public function requireDefaultRecords()
}

// Let any extensions make their own database default data
$this->extend('requireDefaultRecords', $dummy);
$this->extend('onRequireDefaultRecords', $dummy);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/Hierarchy/Hierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static function get_extra_config($class, $extension, $args)
*
* @param ValidationResult $validationResult
*/
public function validate(ValidationResult $validationResult)
protected function updateValidate(ValidationResult $validationResult)
{
// The object is new, won't be looping.
$owner = $this->owner;
Expand Down Expand Up @@ -572,7 +572,7 @@ public function getBreadcrumbs($separator = ' » ')
* - Children (instance)
* - NumChildren (instance)
*/
public function flushCache()
protected function onFlushCache()
{
$this->owner->_cache_children = null;
Hierarchy::$cache_numChildren = [];
Expand Down
4 changes: 2 additions & 2 deletions src/Security/InheritedPermissionFlusher.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class InheritedPermissionFlusher extends DataExtension implements Flushable
*/
public static function flush()
{
singleton(__CLASS__)->flushCache();
singleton(__CLASS__)->onFlushCache();
}

/**
Expand Down Expand Up @@ -77,7 +77,7 @@ public function getServices()
/**
* Flushes all registered MemberCacheFlusher services
*/
public function flushCache()
protected function onFlushCache()
{
$ids = $this->getMemberIDList();
foreach ($this->getServices() as $service) {
Expand Down
10 changes: 5 additions & 5 deletions src/Security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public function isPasswordExpired(): bool
*/
public function beforeMemberLoggedIn()
{
$this->extend('beforeMemberLoggedIn');
$this->extend('onBeforeMemberLoggedIn');
}

/**
Expand All @@ -470,7 +470,7 @@ public function afterMemberLoggedIn()
$this->write();

// Audit logging hook
$this->extend('afterMemberLoggedIn');
$this->extend('onAfterMemberLoggedIn');
}

/**
Expand All @@ -497,7 +497,7 @@ public function regenerateTempID()
*/
public function beforeMemberLoggedOut(HTTPRequest $request = null)
{
$this->extend('beforeMemberLoggedOut', $request);
$this->extend('onBeforeMemberLoggedOut', $request);
}

/**
Expand All @@ -507,7 +507,7 @@ public function beforeMemberLoggedOut(HTTPRequest $request = null)
*/
public function afterMemberLoggedOut(HTTPRequest $request = null)
{
$this->extend('afterMemberLoggedOut', $request);
$this->extend('onAfterMemberLoggedOut', $request);
}

/**
Expand Down Expand Up @@ -1709,7 +1709,7 @@ public function registerFailedLogin()
$this->FailedLoginCount = 0;
}
}
$this->extend('registerFailedLogin');
$this->extend('onRegisterFailedLogin');
$this->write();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Security/MemberAuthenticator/LostPasswordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public function redirectToLostPassword()
/**
* Forgot password form handler method.
* Called when the user clicks on "I've lost my password".
* Extensions can use the 'forgotPassword' method to veto executing
* Extensions can use the 'onForgotPassword' method to veto executing
* the logic, by returning FALSE. In this case, the user will be redirected back
* to the form without further action. It is recommended to set a message
* in the form detailing why the action was denied.
Expand All @@ -168,7 +168,7 @@ public function forgotPassword(array $data, Form $form): HTTPResponse
$member = $this->getMemberFromData($data);

// Allow vetoing forgot password requests
$results = $this->extend('forgotPassword', $member);
$results = $this->extend('onForgotPassword', $member);
if ($results && is_array($results) && in_array(false, $results ?? [], true)) {
return $this->redirectToLostPassword();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Security/MemberAuthenticator/MemberAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ protected function recordLoginAttempt($data, HTTPRequest $request, $member, $suc
$attempt->Status = LoginAttempt::SUCCESS;

// Audit logging hook
$member->extend('authenticationSucceeded');
$member->extend('onAuthenticationSucceeded');
} else {
// Failed login - we're trying to see if a user exists with this email (disregarding wrong passwords)
$attempt->Status = LoginAttempt::FAILURE;
if ($member) {
// Audit logging hook
$attempt->MemberID = $member->ID;
$member->extend('authenticationFailed', $data, $request);
$member->extend('onAuthenticationFailed', $data, $request);
} else {
// Audit logging hook
Member::singleton()
->extend('authenticationFailedUnknownUser', $data, $request);
->extend('onAuthenticationFailedUnknownUser', $data, $request);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Security/MemberAuthenticator/MemberLoginForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* Log-in form for the "member" authentication method.
*
* Available extension points:
* - "authenticationFailed": Called when login was not successful.
* - "onAuthenticationFailed": Called when login was not successful.
* Arguments: $data containing the form submission
* - "forgotPassword": Called before forgot password logic kicks in,
* - "onForgotPassword": Called before forgot password logic kicks in,
* allowing extensions to "veto" execution by returning FALSE.
* Arguments: $member containing the detected Member record
*/
Expand Down
6 changes: 3 additions & 3 deletions tests/php/ORM/DataExtensionTest/Extension1.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class Extension1 extends DataExtension implements TestOnly
{

public function canOne($member = null)
protected function canOne($member = null)
{
return true;
}

public function canTwo($member = null)
protected function canTwo($member = null)
{
return false;
}

public function canThree($member = null)
protected function canThree($member = null)
{
}
}
6 changes: 3 additions & 3 deletions tests/php/ORM/DataExtensionTest/Extension2.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class Extension2 extends DataExtension implements TestOnly
{

public function canOne($member = null)
protected function canOne($member = null)
{
return true;
}

public function canTwo($member = null)
protected function canTwo($member = null)
{
return true;
}

public function canThree($member = null)
protected function canThree($member = null)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
class EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly
{

public function canView($member = null)
protected function canView($member = null)
{
return true;
}

public function canEdit($member = null)
protected function canEdit($member = null)
{
return true;
}

public function canDelete($member = null)
protected function canDelete($member = null)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Security/MemberTest/ViewingAllowedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ViewingAllowedExtension extends DataExtension implements TestOnly
{

public function canView($member = null)
protected function canView($member = null)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Security/MemberTest/ViewingDeniedExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class ViewingDeniedExtension extends DataExtension implements TestOnly
{

public function canView($member = null)
protected function canView($member = null)
{
return false;
}
Expand Down
Loading