Пример #1
0
 public function testAcceptRecognizedTypes()
 {
     $this->assertSame('text', detect_extender_valuetype(123, 'text'));
     $this->assertSame('integer', detect_extender_valuetype(123, 'invalid'));
     $this->assertSame('integer', detect_extender_valuetype('hello', 'integer'));
     $this->assertSame('text', detect_extender_valuetype('hello', 'invalid'));
 }
 /**
  * Set an attribute
  *
  * @param string $name
  * @param mixed $value
  * @param string $value_type
  * @return boolean
  */
 protected function set($name, $value, $value_type = "")
 {
     $this->attributes[$name] = $value;
     if ($name == 'value') {
         $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);
     }
     return true;
 }
/**
*function to update the metadata
*same as the update_metadata, only made metadata editable
*/
function izap_update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
    $id = (int) $id;
    if (!($md = elgg_get_metadata_from_id($id))) {
        return false;
    }
    // If memcached then we invalidate the cache for this entry
    static $metabyname_memcache;
    if (!$metabyname_memcache && is_memcache_available()) {
        $metabyname_memcache = new ElggMemcache('metabyname_memcache');
    }
    if ($metabyname_memcache) {
        $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
    }
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    // Support boolean types (as integers)
    if (is_bool($value)) {
        if ($value) {
            $value = 1;
        } else {
            $value = 0;
        }
    }
    // Add the metastring
    $value = elgg_get_metastring_id($value);
    if (!$value) {
        return false;
    }
    $name = elgg_get_metastring_id($name);
    if (!$name) {
        return false;
    }
    // If ok then add it
    $db_prefix = elgg_get_config('dbprefix');
    $result = update_data("UPDATE {$db_prefix}metadata set value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid} where id={$id} and name_id='{$name}'");
    if ($result !== false) {
        $obj = elgg_get_metadata_from_id($id);
        if (elgg_trigger_event('update', 'metadata', $obj)) {
            return true;
        } else {
            elgg_delete_metadata(array('metadata_id' => $id));
        }
    }
    return $result;
}
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function update($id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     if (!isset($this->rows[$id])) {
         return false;
     }
     $row = $this->rows[$id];
     $row->name = $name;
     $row->value = $value;
     $row->value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
     $row->owner_guid = $owner_guid;
     $row->access_id = $access_id;
     $this->rows[$id] = $row;
     $this->addQuerySpecs($row);
     return parent::update($id, $name, $value, $value_type, $owner_guid, $access_id);
 }
/**
 * 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
 * @param int    $owner_guid Owner guid
 * @param int    $access_id  Access ID
 *
 * @return bool
 */
function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $id = (int) $id;
    if (!($md = elgg_get_metadata_from_id($id))) {
        return false;
    }
    if (!$md->canEdit()) {
        return false;
    }
    // If memcached then we invalidate the cache for this entry
    static $metabyname_memcache;
    if (!$metabyname_memcache && is_memcache_available()) {
        $metabyname_memcache = new ElggMemcache('metabyname_memcache');
    }
    if ($metabyname_memcache) {
        // @todo fix memcache (name_id is not a property of ElggMetadata)
        $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
    }
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    // Support boolean types (as integers)
    if (is_bool($value)) {
        $value = (int) $value;
    }
    $value_id = elgg_get_metastring_id($value);
    if (!$value_id) {
        return false;
    }
    $name_id = elgg_get_metastring_id($name);
    if (!$name_id) {
        return false;
    }
    // If ok then add it
    $query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
    $result = update_data($query);
    if ($result !== false) {
        _elgg_get_metadata_cache()->save($md->entity_guid, $name, $value);
        // @todo this event tells you the metadata has been updated, but does not
        // let you do anything about it. What is needed is a plugin hook before
        // the update that passes old and new values.
        $obj = elgg_get_metadata_from_id($id);
        elgg_trigger_event('update', 'metadata', $obj);
    }
    return $result;
}
Пример #6
0
/**
 * Update an annotation.
 *
 * @param int    $annotation_id Annotation ID
 * @param string $name          Name of annotation
 * @param string $value         Value of annotation
 * @param string $value_type    Type of value
 * @param int    $owner_guid    Owner of annotation
 * @param int    $access_id     Access level of annotation
 *
 * @return bool
 */
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $annotation_id = (int) $annotation_id;
    $annotation = elgg_get_annotation_from_id($annotation_id);
    if (!$annotation) {
        return false;
    }
    if (!$annotation->canEdit()) {
        return false;
    }
    $name = trim($name);
    $value_type = detect_extender_valuetype($value, $value_type);
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    $value_id = elgg_get_metastring_id($value);
    if (!$value_id) {
        return false;
    }
    $name_id = elgg_get_metastring_id($name);
    if (!$name_id) {
        return false;
    }
    $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\tWHERE id = {$annotation_id}");
    if ($result !== false) {
        // @todo add plugin hook that sends old and new annotation information before db access
        $obj = elgg_get_annotation_from_id($annotation_id);
        elgg_trigger_event('update', 'annotation', $obj);
    }
    return $result;
}
Пример #7
0
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = $this->get($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = _elgg_services()->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $value_id = elgg_get_metastring_id($value);
     if (!$value_id) {
         return false;
     }
     $name_id = elgg_get_metastring_id($name);
     if (!$name_id) {
         return false;
     }
     $result = _elgg_services()->db->updateData("UPDATE {$this->CONFIG->dbprefix}annotations\n\t\t\tSET name_id = {$name_id}, value_id = {$value_id}, value_type = '{$value_type}',\n\t\t\taccess_id = {$access_id}, owner_guid = {$owner_guid}\n\t\t\tWHERE id = {$annotation_id}");
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = $this->get($annotation_id);
         _elgg_services()->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
Пример #8
0
 /**
  * Set the value of the extender
  * 
  * @param mixed  $value      The value being set
  * @param string $value_type The type of the : 'integer' or 'text'
  * @return void
  * @since 1.9
  */
 public function setValue($value, $value_type = '')
 {
     $this->attributes['value'] = $value;
     $this->attributes['value_type'] = detect_extender_valuetype($value, $value_type);
 }
Пример #9
0
/**
 * Update an annotation.
 *
 * @param int $annotation_id
 * @param string $name
 * @param string $value
 * @param string $value_type
 * @param int $owner_guid
 * @param int $access_id
 */
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $annotation_id = (int) $annotation_id;
    $name = trim($name);
    $value = trim($value);
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = get_loggedin_userid();
    }
    $access_id = (int) $access_id;
    $access = get_access_sql_suffix();
    // Add the metastring
    $value = add_metastring($value);
    if (!$value) {
        return false;
    }
    $name = add_metastring($name);
    if (!$name) {
        return false;
    }
    // If ok then add it
    $result = update_data("UPDATE {$CONFIG->dbprefix}annotations set value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid} where id={$annotation_id} and name_id='{$name}' and {$access}");
    if ($result !== false) {
        $obj = get_annotation($annotation_id);
        if (trigger_elgg_event('update', 'annotation', $obj)) {
            return true;
        } else {
            delete_annotation($annotation_id);
        }
    }
    return $result;
}
Пример #10
0
 /**
  * Update an annotation.
  *
  * @param int    $annotation_id Annotation ID
  * @param string $name          Name of annotation
  * @param string $value         Value of annotation
  * @param string $value_type    Type of value
  * @param int    $owner_guid    Owner of annotation
  * @param int    $access_id     Access level of annotation
  *
  * @return bool
  */
 function update($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $annotation_id = (int) $annotation_id;
     $annotation = $this->get($annotation_id);
     if (!$annotation) {
         return false;
     }
     if (!$annotation->canEdit()) {
         return false;
     }
     $name = trim($name);
     $value_type = detect_extender_valuetype($value, $value_type);
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     $sql = "UPDATE {$this->db->prefix}annotations\n\t\t\t(name, value, value_type, access_id, owner_guid)\n\t\t\tVALUES\n\t\t\t(:name, :value, :value_type, :access_id, :owner_guid)\n\t\t\tWHERE id = :annotation_id";
     $result = $this->db->updateData($sql, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':annotation_id' => $annotation_id]);
     if ($result !== false) {
         // @todo add plugin hook that sends old and new annotation information before db access
         $obj = $this->get($annotation_id);
         $this->events->trigger('update', 'annotation', $obj);
     }
     return $result;
 }
Пример #11
0
/**
 * Update an annotation.
 *
 * @param int    $annotation_id Annotation ID
 * @param string $name          Name of annotation
 * @param string $value         Value of annotation
 * @param string $value_type    Type of value
 * @param int    $owner_guid    Owner of annotation
 * @param int    $access_id     Access level of annotation
 *
 * @return bool
 */
function update_annotation($annotation_id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $annotation_id = (int) $annotation_id;
    $name = trim($name);
    $value = trim($value);
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    $access = get_access_sql_suffix();
    // Add the metastring
    $value = add_metastring($value);
    if (!$value) {
        return false;
    }
    $name = add_metastring($name);
    if (!$name) {
        return false;
    }
    // If ok then add it
    $result = update_data("UPDATE {$CONFIG->dbprefix}annotations\n\t\tset name_id='{$name}', value_id='{$value}', value_type='{$value_type}', access_id={$access_id}, owner_guid={$owner_guid}\n\t\twhere id={$annotation_id} and {$access}");
    if ($result !== false) {
        $obj = elgg_get_annotation_from_id($annotation_id);
        if (elgg_trigger_event('update', 'annotation', $obj)) {
            return true;
        } else {
            // @todo add plugin hook that sends old and new annotation information before db access
            elgg_delete_annotation_by_id($annotation_id);
        }
    }
    return $result;
}
Пример #12
0
/**
 * 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
 * @param int    $owner_guid Owner guid
 * @param int    $access_id  Access ID
 *
 * @return bool
 */
function update_metadata($id, $name, $value, $value_type, $owner_guid, $access_id)
{
    global $CONFIG;
    $id = (int) $id;
    if (!($md = elgg_get_metadata_from_id($id))) {
        return false;
    }
    if (!$md->canEdit()) {
        return false;
    }
    // If memcached then we invalidate the cache for this entry
    static $metabyname_memcache;
    if (!$metabyname_memcache && is_memcache_available()) {
        $metabyname_memcache = new ElggMemcache('metabyname_memcache');
    }
    if ($metabyname_memcache) {
        $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
    }
    $value_type = detect_extender_valuetype($value, sanitise_string(trim($value_type)));
    $owner_guid = (int) $owner_guid;
    if ($owner_guid == 0) {
        $owner_guid = elgg_get_logged_in_user_guid();
    }
    $access_id = (int) $access_id;
    $access = get_access_sql_suffix();
    // Support boolean types (as integers)
    if (is_bool($value)) {
        if ($value) {
            $value = 1;
        } else {
            $value = 0;
        }
    }
    // Add the metastring
    $value = add_metastring($value);
    if (!$value) {
        return false;
    }
    $name = add_metastring($name);
    if (!$name) {
        return false;
    }
    // If ok then add it
    $query = "UPDATE {$CONFIG->dbprefix}metadata" . " set name_id='{$name}', value_id='{$value}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
    $result = update_data($query);
    if ($result !== false) {
        $obj = elgg_get_metadata_from_id($id);
        if (elgg_trigger_event('update', 'metadata', $obj)) {
            return true;
        } else {
            elgg_delete_metadata_by_id($id);
        }
    }
    return $result;
}
Пример #13
0
 /**
  * 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
  * @param int    $owner_guid Owner guid
  * @param int    $access_id  Access ID
  *
  * @return bool
  */
 function update($id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $id = (int) $id;
     if (!($md = $this->get($id))) {
         return false;
     }
     if (!$md->canEdit()) {
         return false;
     }
     // If memcached then we invalidate the cache for this entry
     static $metabyname_memcache;
     if (!$metabyname_memcache && is_memcache_available()) {
         $metabyname_memcache = new \ElggMemcache('metabyname_memcache');
     }
     if ($metabyname_memcache) {
         // @todo fix memcache (name_id is not a property of \ElggMetadata)
         $metabyname_memcache->delete("{$md->entity_guid}:{$md->name_id}");
     }
     $value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     // Support boolean types (as integers)
     if (is_bool($value)) {
         $value = (int) $value;
     }
     $value_id = $this->metastringsTable->getId($value);
     if (!$value_id) {
         return false;
     }
     $name_id = $this->metastringsTable->getId($name);
     if (!$name_id) {
         return false;
     }
     // If ok then add it
     $query = "UPDATE {$this->table}" . " set name_id='{$name_id}', value_id='{$value_id}', value_type='{$value_type}', access_id={$access_id}," . " owner_guid={$owner_guid} where id={$id}";
     $result = $this->db->updateData($query);
     if ($result !== false) {
         $this->cache->save($md->entity_guid, $name, $value);
         // @todo this event tells you the metadata has been updated, but does not
         // let you do anything about it. What is needed is a plugin hook before
         // the update that passes old and new values.
         $obj = $this->get($id);
         $this->events->trigger('update', 'metadata', $obj);
     }
     return $result;
 }
Пример #14
0
 /**
  * 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
  * @param int    $owner_guid Owner guid
  * @param int    $access_id  Access ID
  *
  * @return bool
  */
 function update($id, $name, $value, $value_type, $owner_guid, $access_id)
 {
     $id = (int) $id;
     if (!($md = $this->get($id))) {
         return false;
     }
     if (!$md->canEdit()) {
         return false;
     }
     $value_type = detect_extender_valuetype($value, $this->db->sanitizeString(trim($value_type)));
     $owner_guid = (int) $owner_guid;
     if ($owner_guid == 0) {
         $owner_guid = $this->session->getLoggedInUserGuid();
     }
     $access_id = (int) $access_id;
     // Support boolean types (as integers)
     if (is_bool($value)) {
         $value = (int) $value;
     }
     // If ok then add it
     $query = "UPDATE {$this->table}\n\t\t\tSET name = :name,\n\t\t\t    value = :value,\n\t\t\t\tvalue_type = :value_type,\n\t\t\t\taccess_id = :access_id,\n\t\t\t    owner_guid = :owner_guid\n\t\t\tWHERE id = :id";
     $result = $this->db->updateData($query, false, [':name' => $name, ':value' => $value, ':value_type' => $value_type, ':access_id' => $access_id, ':owner_guid' => $owner_guid, ':id' => $id]);
     if ($result !== false) {
         $this->cache->clear($md->entity_guid);
         // @todo this event tells you the metadata has been updated, but does not
         // let you do anything about it. What is needed is a plugin hook before
         // the update that passes old and new values.
         $obj = $this->get($id);
         $this->events->trigger('update', 'metadata', $obj);
     }
     return $result;
 }