Skip to content

Commit 101d865

Browse files
authored
Merge pull request #1542 from tspink/fix-parent-calls
Only generate calls to parent hooks, if the class being generated has a base class
2 parents 0f96b1c + c2dbbbc commit 101d865

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Propel/Generator/Builder/Om/ObjectBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,14 @@ protected function addHookMethods(&$script)
675675
$hooks[$hook.$action] = false === strpos($script, "function $hook.$action(");
676676
}
677677
}
678+
679+
if (null !== $this->getBehaviorContent('parentClass') ||
680+
null !== ClassTools::classname($this->getBaseClass())) {
681+
$hooks['hasBaseClass'] = true;
682+
} else {
683+
$hooks['hasBaseClass'] = false;
684+
}
685+
678686
$script .= $this->renderTemplate('baseObjectMethodHook', $hooks);
679687
}
680688

src/Propel/Generator/Builder/Om/templates/baseObjectMethodHook.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
*/
88
public function preSave(ConnectionInterface $con = null)
99
{
10+
<?php if ($hasBaseClass): ?>
1011
if (is_callable('parent::preSave')) {
1112
return parent::preSave($con);
1213
}
14+
<?php endif?>
1315
return true;
1416
}
1517

@@ -21,9 +23,11 @@ public function preSave(ConnectionInterface $con = null)
2123
*/
2224
public function postSave(ConnectionInterface $con = null)
2325
{
26+
<?php if ($hasBaseClass): ?>
2427
if (is_callable('parent::postSave')) {
2528
parent::postSave($con);
2629
}
30+
<?php endif?>
2731
}
2832

2933
<?php endif?>
@@ -35,9 +39,11 @@ public function postSave(ConnectionInterface $con = null)
3539
*/
3640
public function preInsert(ConnectionInterface $con = null)
3741
{
42+
<?php if ($hasBaseClass): ?>
3843
if (is_callable('parent::preInsert')) {
3944
return parent::preInsert($con);
4045
}
46+
<?php endif?>
4147
return true;
4248
}
4349

@@ -49,9 +55,11 @@ public function preInsert(ConnectionInterface $con = null)
4955
*/
5056
public function postInsert(ConnectionInterface $con = null)
5157
{
58+
<?php if ($hasBaseClass): ?>
5259
if (is_callable('parent::postInsert')) {
5360
parent::postInsert($con);
5461
}
62+
<?php endif?>
5563
}
5664

5765
<?php endif?>
@@ -63,9 +71,11 @@ public function postInsert(ConnectionInterface $con = null)
6371
*/
6472
public function preUpdate(ConnectionInterface $con = null)
6573
{
74+
<?php if ($hasBaseClass): ?>
6675
if (is_callable('parent::preUpdate')) {
6776
return parent::preUpdate($con);
6877
}
78+
<?php endif?>
6979
return true;
7080
}
7181

@@ -77,9 +87,11 @@ public function preUpdate(ConnectionInterface $con = null)
7787
*/
7888
public function postUpdate(ConnectionInterface $con = null)
7989
{
90+
<?php if ($hasBaseClass): ?>
8091
if (is_callable('parent::postUpdate')) {
8192
parent::postUpdate($con);
8293
}
94+
<?php endif?>
8395
}
8496

8597
<?php endif?>
@@ -91,9 +103,11 @@ public function postUpdate(ConnectionInterface $con = null)
91103
*/
92104
public function preDelete(ConnectionInterface $con = null)
93105
{
106+
<?php if ($hasBaseClass): ?>
94107
if (is_callable('parent::preDelete')) {
95108
return parent::preDelete($con);
96109
}
110+
<?php endif?>
97111
return true;
98112
}
99113

@@ -105,9 +119,11 @@ public function preDelete(ConnectionInterface $con = null)
105119
*/
106120
public function postDelete(ConnectionInterface $con = null)
107121
{
122+
<?php if ($hasBaseClass): ?>
108123
if (is_callable('parent::postDelete')) {
109124
parent::postDelete($con);
110125
}
126+
<?php endif?>
111127
}
112128

113-
<?php endif?>
129+
<?php endif?>

0 commit comments

Comments
 (0)