Permalink
Browse files

fix(entities): update attribute when assuming container_guid value

ElggEntity::create() assumes that container_guid equals to owner_guid when container_guid
is set to 0, but does so in introduced variables without propagating the changes in
attributes array. This results in discrepancies between ElggEntity::getContainerGUID()
and the value written to the database

Fixes #8981
  • Loading branch information...
hypeJunction committed Dec 8, 2015
1 parent ba268bf commit a21dd95ed76a4b6629c69fd7e000aabd2e7cce99
Showing with 20 additions and 0 deletions.
  1. +1 −0 engine/classes/ElggEntity.php
  2. +19 −0 engine/tests/ElggEntityTest.php
@@ -1643,6 +1643,7 @@ protected function create() {
$container_guid = $this->attributes['container_guid'];
if ($container_guid == 0) {
$container_guid = $owner_guid;
$this->attributes['container_guid'] = $container_guid;
}
$container_guid = (int)$container_guid;
@@ -355,4 +355,23 @@ public function testCanAnnotateDoesntCallSpecificThenGenericHookForEmptyString()
$object->delete();
}
public function testCreateWithContainerGuidEqualsZero() {
$user = new \ElggUser();
$user->save();
$object = new \ElggObject();
$object->owner_guid = $user->guid;
$object->container_guid = 0;
// If container_guid attribute is not updated with owner_guid attribute
// ElggEntity::getContainerEntity() would return false
// thus terminating save()
$this->assertTrue($object->save());
$this->assertEqual($user->guid, $object->getContainerGUID());
$user->delete();
}
}

0 comments on commit a21dd95

Please sign in to comment.