updateData() публичный Метод

Update the database.
public updateData ( string $query, boolean $get_num_rows = false, array $params = [] ) : boolean | integer
$query string The query to run.
$get_num_rows boolean Return the number of rows affected (default: false).
$params array Query params. E.g. [1, 'steve'] or [':id' => 1, ':name' => 'steve']
Результат boolean | integer
Пример #1
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;
 }
Пример #2
0
 /**
  * When an entity is updated, resets the access ID on all of its child metadata
  *
  * @param string      $event       The name of the event
  * @param string      $object_type The type of object
  * @param \ElggEntity $object      The entity itself
  *
  * @return true
  * @access private Set as private in 1.9.0
  */
 function handleUpdate($event, $object_type, $object)
 {
     if ($object instanceof \ElggEntity) {
         if (!$this->isMetadataIndependent($object->getType(), $object->getSubtype())) {
             $access_id = (int) $object->access_id;
             $guid = (int) $object->getGUID();
             $query = "update {$this->table} set access_id = {$access_id} where entity_guid = {$guid}";
             $this->db->updateData($query);
         }
     }
     return true;
 }
Пример #3
0
 /**
  * Update a registered \ElggEntity type, subtype, and class name
  *
  * @param string $type    Type
  * @param string $subtype Subtype
  * @param string $class   Class name to use when loading this entity
  *
  * @return bool
  */
 public function update($type, $subtype, $class = '')
 {
     $id = $this->getId($type, $subtype);
     if (!$id) {
         return false;
     }
     $sql = "\n\t\t\tUPDATE {$this->db->prefix}entity_subtypes\n\t\t\tSET type = :type, subtype = :subtype, class = :class\n\t\t\tWHERE id = :id\n\t\t";
     $params = [':type' => $type, ':subtype' => $subtype, ':class' => $class, ':id' => $id];
     if (!$this->db->updateData($sql, false, $params)) {
         return false;
     }
     $this->invalidateCache();
     return true;
 }
Пример #4
0
 /**
  * Removes user $guid's admin flag.
  *
  * @param int $user_guid User GUID
  * @return bool
  */
 public function removeAdmin($user_guid)
 {
     $user = get_entity($user_guid);
     if (!$user instanceof ElggUser || !$user->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('remove_admin', 'user', $user)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}\n\t\t\tSET admin = 'no'\n\t\t\tWHERE guid = :guid\n\t\t";
     $params = [':guid' => (int) $user_guid];
     _elgg_invalidate_cache_for_entity($user_guid);
     _elgg_invalidate_memcache_for_entity($user_guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }
Пример #5
0
 /**
  * Disables all entities owned and contained by a user (or another entity)
  *
  * @param int $owner_guid The owner GUID
  * @return bool
  */
 public function disableEntities($owner_guid)
 {
     $entity = get_entity($owner_guid);
     if (!$entity || !$entity->canEdit()) {
         return false;
     }
     if (!$this->events->trigger('disable', $entity->type, $entity)) {
         return false;
     }
     $query = "\n\t\t\tUPDATE {$this->table}entities\n\t\t\tSET enabled='no'\n\t\t\tWHERE owner_guid = :owner_guid\n\t\t\tOR container_guid = :owner_guid";
     $params = [':owner_guid' => (int) $owner_guid];
     _elgg_invalidate_cache_for_entity($entity->guid);
     _elgg_invalidate_memcache_for_entity($entity->guid);
     if ($this->db->updateData($query, true, $params)) {
         return true;
     }
     return false;
 }
Пример #6
0
 /**
  * {@inheritdoc}
  */
 public function updateData($query, $getNumRows = false, array $params = [])
 {
     return $this->db->updateData($query, $getNumRows, $params);
 }