Skip to content

Commit

Permalink
Merge pull request #10380 from hypeJunction/merge_1.12_2.2
Browse files Browse the repository at this point in the history
Merge 1.12 2.2
  • Loading branch information
hypeJunction committed Oct 7, 2016
2 parents 4c1a8e9 + 7c06693 commit be3415d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 15 deletions.
16 changes: 15 additions & 1 deletion actions/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,22 @@
// plugin that has disabled the user
try {
login($new_user);
// set forward url
$session = elgg_get_session();
if ($session->has('last_forward_from')) {
$forward_url = $session->get('last_forward_from');
$forward_source = 'last_forward_from';
} else {
// forward to main index page
$forward_url = '';
$forward_source = null;
}
$params = array('user' => $new_user, 'source' => $forward_source);
$forward_url = elgg_trigger_plugin_hook('login:forward', 'user', $params, $forward_url);
forward($forward_url);
} catch (LoginException $e) {
// do nothing
register_error($e->getMessage());
forward(REFERER);
}
}

Expand Down
6 changes: 5 additions & 1 deletion docs/guides/page-owner.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ Page ownership
==============

One recurring task of any plugin will be to determine the page ownership in order to decide which actions are allowed or not. Elgg has a number of functions related to page ownership and also offers plugin developers flexibility by letting the plugin handle page ownership requests as well.
Determining the owner of a page can be determined with ``elgg_get_page_owner_guid()``, which will return the GUID of the owner. Alternatively, ``elgg_get_page_owner_entity()`` will retrieve the whole page owner entity.
If the page already knows who the page owner is, but the system doesn't, the page can set the page owner by passing the GUID to ``elgg_set_page_owner_guid($guid)``.

Determining the owner of a page can be determined with ``elgg_get_page_owner_guid()``, which will return the GUID of the owner. Alternatively, ``elgg_get_page_owner_entity()`` will retrieve the whole page owner entity. If the page already knows who the page owner is, but the system doesn't, the it be can set by passing the GUID to ``elgg_set_page_owner_guid($guid)``.
.. note::

The page owner entity can be any ``ElggEntity``. If you wish to only apply some setting in case of a user or a group make sure you check that you have the correct entity.

Custom page owner handlers
--------------------------
Expand Down
9 changes: 5 additions & 4 deletions engine/classes/Elgg/Database/RelationshipsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ public function delete($id, $call_event = true) {
* @param int $guid_one GUID of the subject entity of the relationship
* @param string $relationship Type of the relationship
* @param int $guid_two GUID of the target entity of the relationship
* @param bool $return_id Return the ID instead of bool?
*
* @return bool
* @return bool|int
* @throws \InvalidArgumentException
*/
public function add($guid_one, $relationship, $guid_two) {
public function add($guid_one, $relationship, $guid_two, $return_id = false) {
if (strlen($relationship) > \ElggRelationship::RELATIONSHIP_LIMIT) {
$msg = "relationship name cannot be longer than " . \ElggRelationship::RELATIONSHIP_LIMIT;
throw new \InvalidArgumentException($msg);
Expand All @@ -124,7 +125,7 @@ public function add($guid_one, $relationship, $guid_two) {
if ($this->check($guid_one, $relationship, $guid_two)) {
return false;
}

$sql = "
INSERT INTO {$this->db->getTablePrefix()}entity_relationships
(guid_one, relationship, guid_two, time_created)
Expand All @@ -151,7 +152,7 @@ public function add($guid_one, $relationship, $guid_two) {
return false;
}

return true;
return $return_id ? $obj->id : true;
}

/**
Expand Down
9 changes: 8 additions & 1 deletion engine/classes/ElggRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public function __construct($row = null) {
foreach ((array)$row as $key => $value) {
$this->attributes[$key] = $value;
}

$this->attributes['id'] = (int)$this->attributes['id'];
}

/**
Expand Down Expand Up @@ -127,7 +129,12 @@ public function save() {
delete_relationship($this->id);
}

$this->id = add_entity_relationship($this->guid_one, $this->relationship, $this->guid_two);
$this->id = _elgg_services()->relationshipsTable->add(
$this->guid_one,
$this->relationship,
$this->guid_two,
true
);
if (!$this->id) {
throw new \IOException("Unable to save new " . get_class());
}
Expand Down
9 changes: 2 additions & 7 deletions engine/lib/pageowner.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function elgg_get_page_owner_guid($guid = 0) {
/**
* Gets the owner entity for the current page.
*
* @return \ElggUser|\ElggGroup|false The current page owner or false if none.
* @return \ElggEntity|false The current page owner or false if none.
*
* @since 1.8.0
*/
Expand All @@ -59,12 +59,7 @@ function elgg_get_page_owner_entity() {
return false;
}

$owner = get_entity($guid);
if ($owner instanceof ElggUser || $owner instanceof ElggGroup) {
return $owner;
}

return false;
return get_entity($guid);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion engine/tests/ElggRelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ public function testRelationshipSave() {
$this->assertTrue(add_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid));
$r = check_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity2->guid);
$this->assertIsA($r, 'ElggRelationship');
$old_id = $r->id;

// note - string because that's how it's returned when getting a new object
$r->guid_two = (string) $this->entity3->guid;
$this->assertTrue($r->save());
$new_id = $r->save();
$this->assertIsA($new_id, 'int');
$this->assertNotEqual($new_id, $old_id);

$test_r = check_entity_relationship($this->entity1->guid, 'test_relationship', $this->entity3->guid);
$this->assertIsA($test_r, 'ElggRelationship');
Expand Down

0 comments on commit be3415d

Please sign in to comment.