Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Versionable] Added template for isVersioningNecessary()
- Loading branch information
1 parent
7de61da
commit ba385f6
Showing
2 changed files
with
52 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
generator/lib/behavior/versionable/templates/objectIsVersioningNecessary.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
|
|||
/** | |||
* Checks whether the current state must be recorded as a version | |||
* | |||
* @return boolean | |||
*/ | |||
public function isVersioningNecessary($con = null) | |||
{ | |||
if ($this->alreadyInSave) { | |||
return false; | |||
} | |||
|
|||
if ($this->enforceVersion) { | |||
return true; | |||
} | |||
|
|||
if (<?php echo $peerClassName ?>::isVersioningEnabled() && ($this->isNew() || $this->isModified() || $this->isDeleted())) { | |||
return true; | |||
} | |||
|
|||
<?php foreach ($fkGetters as $fkGetter) : ?> | |||
if (null !== ($object = $this->get<?php echo $fkGetter ?>($con)) && $object->isVersioningNecessary($con)) { | |||
return true; | |||
} | |||
|
|||
<?php endforeach; ?> | |||
<?php foreach ($refFkGetters as $fkGetter) : ?> | |||
// to avoid infinite loops, emulate in save | |||
$this->alreadyInSave = true; | |||
foreach ($this->get<?php echo $fkGetter ?>(null, $con) as $relatedObject) { | |||
if ($relatedObject->isVersioningNecessary($con)) { | |||
$this->alreadyInSave = false; | |||
|
|||
return true; | |||
} | |||
} | |||
$this->alreadyInSave = false; | |||
|
|||
<?php endforeach; ?> | |||
return false; | |||
} |