Skip to content

Commit

Permalink
deprecate(core): the use of the update_metadata function is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalsem committed Oct 19, 2017
1 parent 2ec9e7c commit fb97d13
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions docs/guides/upgrading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ Deprecated APIs
---------------

* ``ban_user``: Use ``ElggUser->ban()``
* ``update_metadata``: Use ``ElggMetadata->save()``
* ``elgg_get_entities_from_attributes``: Use ``elgg_get_entities_from_metadata()``
* ``elgg_get_user_validation_status``: Use ``ElggUser->isValidated()``
* ``make_user_admin``: Use ``ElggUser->makeAdmin()``
Expand Down
19 changes: 9 additions & 10 deletions engine/classes/ElggMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,17 @@ public function canEdit($user_guid = 0) {
*/
public function save() {
if ($this->id > 0) {
return update_metadata($this->id, $this->name, $this->value,
$this->value_type);
} else {
// using create_metadata() for deprecation notices in 2.x
$this->id = create_metadata($this->entity_guid, $this->name, $this->value,
$this->value_type);
return _elgg_services()->metadataTable->update($this->id, $this->name, $this->value, $this->value_type);
}

// using create_metadata() for deprecation notices in 2.x
$this->id = create_metadata($this->entity_guid, $this->name, $this->value,
$this->value_type);

if (!$this->id) {
throw new \IOException("Unable to save new " . get_class());
}
return $this->id;
if (!$this->id) {
throw new \IOException("Unable to save new " . get_class());
}
return $this->id;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions engine/lib/deprecated-3.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,3 +349,21 @@ function set_last_login($user_guid) {

$user->setLastLogin();
}

/**
* Update a specific piece of metadata.
*
* @param int $id ID of the metadata to update
* @param string $name Metadata name
* @param string $value Metadata value
* @param string $value_type Value type
*
* @return bool
*
* @deprecated Use \ElggMetadata->save()
*/
function update_metadata($id, $name, $value, $value_type) {
elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use \ElggMetadata->save()', '3.0');

return _elgg_services()->metadataTable->update($id, $name, $value, $value_type);
}
14 changes: 0 additions & 14 deletions engine/lib/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,6 @@ function create_metadata($entity_guid, $name, $value, $value_type = '', $ignored
$value_type, $allow_multiple);
}

/**
* Update a specific piece of metadata.
*
* @param int $id ID of the metadata to update
* @param string $name Metadata name
* @param string $value Metadata value
* @param string $value_type Value type
*
* @return bool
*/
function update_metadata($id, $name, $value, $value_type) {
return _elgg_services()->metadataTable->update($id, $name, $value, $value_type);
}

/**
* Returns metadata. Accepts all elgg_get_entities() options for entity
* restraints.
Expand Down

0 comments on commit fb97d13

Please sign in to comment.