Skip to content

Commit

Permalink
Import unserialize/serialize fix for PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
eddmann committed Jan 12, 2021
1 parent f154fe7 commit 87fb492
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
20 changes: 15 additions & 5 deletions generator/lib/builder/om/PHP5ObjectBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3818,26 +3818,36 @@ protected function addRefFKSet(&$script, $refFK)
*
* @param PropelCollection \${$inputCollection} A Propel collection.
* @param PropelPDO \$con Optional connection object
* @return ".$this->getObjectClassname()." The current object (for fluent API support)
* @return " . $this->getObjectClassname() . " The current object (for fluent API support)
*/
public function set{$relatedName}(PropelCollection \${$inputCollection}, PropelPDO \$con = null)
{
\${$inputCollection}ToDelete = \$this->get{$relatedName}(new Criteria(), \$con)->diff(\${$inputCollection});
";

\$this->{$inputCollection}ScheduledForDeletion = unserialize(serialize(\${$inputCollection}ToDelete));
if ($refFK->isAtLeastOneLocalPrimaryKey()) {
$script .= "
//since at least one column in the foreign key is at the same time a PK
//we can not just set a PK to NULL in the lines below. We have to store
//a backup of all values, so we are able to manipulate these items based on the onDelete value later.
\$this->{$inputCollection}ScheduledForDeletion = clone \${$inputCollection}ToDelete;
";
} else {
$script .= "
\$this->{$inputCollection}ScheduledForDeletion = \${$inputCollection}ToDelete;
";
}

$script .= "
foreach (\${$inputCollection}ToDelete as \${$inputCollectionEntry}Removed) {
\${$inputCollectionEntry}Removed->set{$relCol}(null);
}
\$this->{$collName} = null;
foreach (\${$inputCollection} as \${$inputCollectionEntry}) {
\$this->add{$relatedObjectClassName}(\${$inputCollectionEntry});
}
\$this->{$collName} = \${$inputCollection};
\$this->{$collName}Partial = false;
return \$this;
}
";
Expand Down
18 changes: 18 additions & 0 deletions generator/lib/model/ForeignKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,24 @@ public function isLocalPrimaryKey()
!array_diff($localPKCols, $localCols));
}

/**
* Whether at least one local column is also a primary key.
*
* @return boolean True if there is at least one column that is a primary key
*/
public function isAtLeastOneLocalPrimaryKey()
{
$localCols = $this->getLocalColumnObjects();

foreach ($localCols as $localCol) {
if ($this->getTable()->getColumn($localCol->getName())->isPrimaryKey()) {
return true;
}
}

return false;
}

/**
* Set whether this foreign key should have its creation sql generated.
* @param boolean $v Value to assign to skipSql.
Expand Down

0 comments on commit 87fb492

Please sign in to comment.