Permalink
Browse files

DataObject on*() callbacks now consistently invoke on subclasses as well

Before this was only possible for some specific ones, like onBeforeWrite.
This excludes any callbacks with augment*() or update*() naming,
since these are assumed to be on extension only, with a corresponding
base method available on the class itself (e.g. "updateCMSFields()"
vs "getCMSFields()").
  • Loading branch information...
1 parent 18c9a95 commit d289016bc38abfc2b2af95fa5d34ba649f108f9f @chillu chillu committed Feb 5, 2013
Showing with 5 additions and 5 deletions.
  1. +5 −5 model/DataObject.php
View
@@ -423,12 +423,12 @@ public function duplicate($doWrite = true) {
$clone = new $className( $this->toMap(), false, $this->model );
$clone->ID = 0;
- $clone->extend('onBeforeDuplicate', $this, $doWrite);
+ $clone->invokeWithExtensions('onBeforeDuplicate', $this, $doWrite);
if($doWrite) {
$clone->write();
$this->duplicateManyManyRelations($this, $clone);
}
- $clone->extend('onAfterDuplicate', $this, $doWrite);
+ $clone->invokeWithExtensions('onAfterDuplicate', $this, $doWrite);
return $clone;
}
@@ -1065,7 +1065,7 @@ public function write($showDebug = false, $forceInsert = false, $forceWrite = fa
if($writeException) {
// Used by DODs to clean up after themselves, eg, Versioned
- $this->extend('onAfterSkippedWrite');
+ $this->invokeWithExtensions('onAfterSkippedWrite');
throw $writeException;
return false;
}
@@ -1208,7 +1208,7 @@ public function write($showDebug = false, $forceInsert = false, $forceWrite = fa
} elseif ( $showDebug ) {
echo "<b>Debug:</b> no changes for DataObject<br />";
// Used by DODs to clean up after themselves, eg, Versioned
- $this->extend('onAfterSkippedWrite');
+ $this->invokeWithExtensions('onAfterSkippedWrite');
}
// Clears the cache for this object so get_one returns the correct object.
@@ -1220,7 +1220,7 @@ public function write($showDebug = false, $forceInsert = false, $forceWrite = fa
$this->record['LastEdited'] = SS_Datetime::now()->Rfc2822();
} else {
// Used by DODs to clean up after themselves, eg, Versioned
- $this->extend('onAfterSkippedWrite');
+ $this->invokeWithExtensions('onAfterSkippedWrite');
}
// Write relations as necessary

0 comments on commit d289016

Please sign in to comment.