/** * Change the river iten's acces_id to album acces_id * * @param Array $river_itens * @return void */ function tidypics_adjust_river_access_id(array $river_itens = NULL) { if (!$river_itens or !count($river_itens)) { return; } foreach ($river_itens as $item) { $object = $item->getObjectEntity(); $access_id = $object->access_id; if ($item->access_id != $access_id) { update_river_access_by_object($object->guid, $access_id); } } }
function approve_content(\ElggObject $object) { $object->deleteMetadata(QUARANTINED); $access_id = $object->{ORIGINAL_ACCESS_ID}; // delete it so our update handler doesn't re-set it $object->deleteMetadata(ORIGINAL_ACCESS_ID); if ($access_id !== null) { $object->access_id = (int) $access_id; $handle = State::$handle_updates; State::$handle_updates = false; $object->save(); State::$handle_updates = $handle; } else { $access_id = $object->access_id; } // just in case plugins look at river.access_id update_river_access_by_object($object->guid, $access_id); }
/** * Update the entity in the database. * * @return bool Whether the update was successful. * * @throws InvalidParameterException */ protected function update() { _elgg_services()->boot->invalidateCache($this->guid); if (!$this->canEdit()) { return false; } // give old update event a chance to stop the update if (!_elgg_services()->events->trigger('update', $this->type, $this)) { 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 = $this->getCurrentTime()->getTimestamp(); if ($access_id == ACCESS_DEFAULT) { throw new \InvalidParameterException('ACCESS_DEFAULT is not a valid access level. See its documentation in elgglib.php'); } $ret = _elgg_services()->entityTable->updateRow($guid, (object) ['owner_guid' => $owner_guid, 'container_guid' => $container_guid, 'access_id' => $access_id, 'time_created' => $time_created, 'time_updated' => $time, '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 ($ret !== false) { $this->attributes['time_updated'] = $time; } $this->orig_attributes = []; // Handle cases where there was no error BUT no rows were updated! return $ret !== false; }
/** * Update an entity in the database. * * There are 4 basic entity types: site, user, object, and group. * All entities are split between two tables: the entities table and their type table. * * @warning Plugin authors should never call this directly. Use ->save() instead. * * @param int $guid The guid of the entity to update * @param int $owner_guid The new owner guid * @param int $access_id The new access id * @param int $container_guid The new container guid * @param int $time_created The time creation timestamp * * @return bool * @link http://docs.elgg.org/DataModel/Entities * @access private */ function update_entity($guid, $owner_guid, $access_id, $container_guid = null, $time_created = null) { global $CONFIG, $ENTITY_CACHE; $guid = (int) $guid; $owner_guid = (int) $owner_guid; $access_id = (int) $access_id; $container_guid = (int) $container_guid; if (is_null($container_guid)) { $container_guid = $owner_guid; } $time = time(); $entity = get_entity($guid); if ($time_created == null) { $time_created = $entity->time_created; } else { $time_created = (int) $time_created; } if ($entity && $entity->canEdit()) { if (elgg_trigger_event('update', $entity->type, $entity)) { $ret = update_data("UPDATE {$CONFIG->dbprefix}entities\n\t\t\t\tset owner_guid='{$owner_guid}', access_id='{$access_id}',\n\t\t\t\tcontainer_guid='{$container_guid}', time_created='{$time_created}',\n\t\t\t\ttime_updated='{$time}' WHERE guid={$guid}"); if ($entity 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); } // Handle cases where there was no error BUT no rows were updated! if ($ret === false) { return false; } return true; } } }
/** * 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; }
/** * Update the entity in the database. * * @return bool Whether the update was successful. */ protected function update() { cache_entity($this); global $CONFIG; $guid = (int) $this->get('guid'); $owner_guid = (int) $this->get('owner_guid'); $access_id = (int) $this->get('access_id'); $container_guid = (int) $this->get('container_guid'); $time_created = (int) $this->get('time_created'); $time = time(); if (!$this->canEdit() || !elgg_trigger_event('update', $this->type, $this)) { return false; } $ret = update_data("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); } // Handle cases where there was no error BUT no rows were updated! return $ret !== false; }
/** * 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; }