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);
}
// Check for duplicates
// note: escape $relationship after this call, we don't want to double-escape
if ($this->check($guid_one, $relationship, $guid_two)) {
return false;
}
$sql = "\n\t\t\tINSERT INTO {$this->db->prefix}entity_relationships\n\t\t\t (guid_one, relationship, guid_two, time_created)\n\t\t\tVALUES (:guid1, :relationship, :guid2, :time)\n\t\t\t\tON DUPLICATE KEY UPDATE time_created = :time\n\t\t";
$params = [':guid1' => (int) $guid_one, ':guid2' => (int) $guid_two, ':relationship' => $relationship, ':time' => $this->getCurrentTime()->getTimestamp()];
$id = $this->db->insertData($sql, $params);
if (!$id) {
return false;
}
$obj = $this->get($id);
$result = $this->events->trigger('create', 'relationship', $obj);
if (!$result) {
$this->delete($id, false);
return false;
}
return $return_id ? $obj->id : true;
}