Esempio n. 1
0
 /**
  * Update the entity in the database.
  *
  * @return bool Whether the update was successful.
  *
  * @throws InvalidParameterException
  */
 protected function update()
 {
     global $CONFIG;
     // See #5600. This ensures canEdit() checks the BD persisted entity so it sees the
     // persisted owner_guid, container_guid, etc.
     _elgg_disable_caching_for_entity($this->guid);
     $persisted_entity = get_entity($this->guid);
     if (!$persisted_entity) {
         // Why worry about this case? If access control was off when the user fetched this object but
         // was turned back on again. Better to just bail than to turn access control off again.
         return false;
     }
     $allow_edit = $persisted_entity->canEdit();
     unset($persisted_entity);
     if ($allow_edit) {
         // give old update event a chance to stop the update
         $allow_edit = _elgg_services()->events->trigger('update', $this->type, $this);
     }
     _elgg_enable_caching_for_entity($this->guid);
     if (!$allow_edit) {
         return false;
     }
     // See #6225. We copy these after the update event in case a handler changed one of them.
     $guid = (int) $this->guid;
     $owner_guid = (int) $this->owner_guid;
     $access_id = (int) $this->access_id;
     $container_guid = (int) $this->container_guid;
     $time_created = (int) $this->time_created;
     $time = time();
     if ($access_id == ACCESS_DEFAULT) {
         throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
     }
     $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities\n\t\t\tset owner_guid='{$owner_guid}', access_id='{$access_id}',\n\t\t\tcontainer_guid='{$container_guid}', time_created='{$time_created}',\n\t\t\ttime_updated='{$time}' WHERE guid={$guid}");
     elgg_trigger_after_event('update', $this->type, $this);
     // TODO(evan): Move this to \ElggObject?
     if ($this instanceof \ElggObject) {
         update_river_access_by_object($guid, $access_id);
     }
     // If memcache is available then delete this entry from the cache
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new \ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $newentity_cache->delete($guid);
     }
     if ($ret !== false) {
         $this->attributes['time_updated'] = $time;
     }
     _elgg_cache_entity($this);
     $this->orig_attributes = [];
     // Handle cases where there was no error BUT no rows were updated!
     return $ret !== false;
 }
Esempio n. 2
0
 /**
  * Override the save function.
  *
  * @return bool
  */
 public function save()
 {
     // Save generic stuff
     if (!parent::save()) {
         return false;
     }
     // Now save specific stuff
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Esempio n. 3
0
 /**
  * Saves object-specific attributes.
  *
  * @internal Object attributes are saved in the objects_entity table.
  *
  * @return bool
  */
 public function save()
 {
     // Save ElggEntity attributes
     if (!parent::save()) {
         return false;
     }
     // Save ElggObject-specific attributes
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_object_entity($this->get('guid'), $this->get('title'), $this->get('description'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Esempio n. 4
0
 /**
  * Update the entity in the database.
  *
  * @return bool Whether the update was successful.
  *
  * @throws InvalidParameterException
  */
 protected function update()
 {
     global $CONFIG;
     $guid = (int) $this->guid;
     $owner_guid = (int) $this->owner_guid;
     $access_id = (int) $this->access_id;
     $container_guid = (int) $this->container_guid;
     $time_created = (int) $this->time_created;
     $time = time();
     if ($access_id == ACCESS_DEFAULT) {
         throw new InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php');
     }
     // See #5600. This ensures the canEdit() check will use a fresh entity from the DB so it sees the
     // persisted owner_guid, container_guid, etc.
     _elgg_disable_caching_for_entity($this->guid);
     $allow_edit = $this->canEdit() && elgg_trigger_event('update', $this->type, $this);
     _elgg_enable_caching_for_entity($this->guid);
     if (!$allow_edit) {
         return false;
     }
     $ret = $this->getDatabase()->updateData("UPDATE {$CONFIG->dbprefix}entities\n\t\t\tset owner_guid='{$owner_guid}', access_id='{$access_id}',\n\t\t\tcontainer_guid='{$container_guid}', time_created='{$time_created}',\n\t\t\ttime_updated='{$time}' WHERE guid={$guid}");
     // TODO(evan): Move this to ElggObject?
     if ($this instanceof ElggObject) {
         update_river_access_by_object($guid, $access_id);
     }
     // If memcache is available then delete this entry from the cache
     static $newentity_cache;
     if (!$newentity_cache && is_memcache_available()) {
         $newentity_cache = new ElggMemcache('new_entity_cache');
     }
     if ($newentity_cache) {
         $newentity_cache->delete($guid);
     }
     if ($ret !== false) {
         $this->attributes['time_updated'] = $time;
     }
     _elgg_cache_entity($this);
     // Handle cases where there was no error BUT no rows were updated!
     return $ret !== false;
 }
Esempio n. 5
0
 /**
  * Saves this user to the database.
  *
  * @return bool
  */
 public function save()
 {
     // Save generic stuff
     if (!parent::save()) {
         return false;
     }
     // Now save specific stuff
     _elgg_disable_caching_for_entity($this->guid);
     $ret = create_user_entity($this->get('guid'), $this->get('name'), $this->get('username'), $this->get('password'), $this->get('salt'), $this->get('email'), $this->get('language'), $this->get('code'));
     _elgg_enable_caching_for_entity($this->guid);
     return $ret;
 }
Esempio n. 6
0
 /**
  * Save an entity.
  *
  * @return bool|int
  * @throws IOException
  */
 public function save()
 {
     $guid = $this->getGUID();
     if ($guid > 0) {
         // See #5600. This ensures the lower level can_edit_entity() check will use a
         // fresh entity from the DB so it sees the persisted owner_guid
         _elgg_disable_caching_for_entity($guid);
         $ret = update_entity($guid, $this->get('owner_guid'), $this->get('access_id'), $this->get('container_guid'), $this->get('time_created'));
         _elgg_enable_caching_for_entity($guid);
         _elgg_cache_entity($this);
         return $ret;
     } else {
         // Create a new entity (nb: using attribute array directly
         // 'cos set function does something special!)
         $this->attributes['guid'] = create_entity($this->attributes['type'], $this->attributes['subtype'], $this->attributes['owner_guid'], $this->attributes['access_id'], $this->attributes['site_guid'], $this->attributes['container_guid']);
         if (!$this->attributes['guid']) {
             throw new IOException(elgg_echo('IOException:BaseEntitySaveFailed'));
         }
         // Save any unsaved metadata
         // @todo How to capture extra information (access id etc)
         if (sizeof($this->temp_metadata) > 0) {
             foreach ($this->temp_metadata as $name => $value) {
                 $this->{$name} = $value;
                 unset($this->temp_metadata[$name]);
             }
         }
         // Save any unsaved annotations.
         if (sizeof($this->temp_annotations) > 0) {
             foreach ($this->temp_annotations as $name => $value) {
                 $this->annotate($name, $value);
                 unset($this->temp_annotations[$name]);
             }
         }
         // Save any unsaved private settings.
         if (sizeof($this->temp_private_settings) > 0) {
             foreach ($this->temp_private_settings as $name => $value) {
                 $this->setPrivateSetting($name, $value);
                 unset($this->temp_private_settings[$name]);
             }
         }
         // set the subtype to id now rather than a string
         $this->attributes['subtype'] = get_subtype_id($this->attributes['type'], $this->attributes['subtype']);
         _elgg_cache_entity($this);
         return $this->attributes['guid'];
     }
 }