本文整理汇总了PHP中ElggMemcache::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP ElggMemcache::delete方法的具体用法?PHP ElggMemcache::delete怎么用?PHP ElggMemcache::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ElggMemcache
的用法示例。
在下文中一共展示了ElggMemcache::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _elgg_invalidate_memcache_for_entity
/**
* Invalidate an entity in memcache
*
* @param int $entity_guid The GUID of the entity to invalidate
*
* @return void
* @access private
*/
function _elgg_invalidate_memcache_for_entity($entity_guid)
{
static $newentity_cache;
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new \ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$newentity_cache->delete($entity_guid);
}
}
示例2: izap_update_metadata
/**
*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;
}
示例3: set
public function set($name, $value)
{
if (is_array($value)) {
if (empty($value)) {
$value = null;
} else {
$value = json_encode($value);
}
}
if (parent::set($name, $value)) {
$this->settings_cache[$name] = $value;
// 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($this->getGUID());
}
}
}
示例4: remove_user_admin
/**
* Removes user $guid's admin flag.
*
* @param int $user_guid User GUID
*
* @return bool
*/
function remove_user_admin($user_guid)
{
global $CONFIG;
$user = get_entity((int) $user_guid);
if ($user && $user instanceof ElggUser && $user->canEdit()) {
if (elgg_trigger_event('remove_admin', 'user', $user)) {
// invalidate memcache for this user
static $newentity_cache;
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$newentity_cache->delete($user_guid);
}
$r = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='no' where guid={$user_guid}");
invalidate_cache_for_entity($user_guid);
return $r;
}
return FALSE;
}
return FALSE;
}
示例5: delete_orphaned_metastrings
/**
* Delete any orphaned entries in metastrings. This is run by the garbage collector.
*
*/
function delete_orphaned_metastrings()
{
global $CONFIG;
// If memcache is enabled then we need to flush it of deleted values
if (is_memcache_available()) {
$select_query = "\n\t\t\tSELECT * \n\t\t\tfrom {$CONFIG->dbprefix}metastrings where \n\t\t\t( \n\t\t\t\t(id not in (select name_id from {$CONFIG->dbprefix}metadata)) AND \n\t\t\t\t(id not in (select value_id from {$CONFIG->dbprefix}metadata)) AND \n\t\t\t\t(id not in (select name_id from {$CONFIG->dbprefix}annotations)) AND \n\t\t\t\t(id not in (select value_id from {$CONFIG->dbprefix}annotations)) \n\t\t\t)";
$dead = get_data($select_query);
if ($dead) {
static $metastrings_memcache;
if (!$metastrings_memcache) {
$metastrings_memcache = new ElggMemcache('metastrings_memcache');
}
foreach ($dead as $d) {
$metastrings_memcache->delete($d->string);
}
}
}
$query = "\n\t\t\tDELETE \n\t\t\tfrom {$CONFIG->dbprefix}metastrings where \n\t\t\t( \n\t\t\t\t(id not in (select name_id from {$CONFIG->dbprefix}metadata)) AND \n\t\t\t\t(id not in (select value_id from {$CONFIG->dbprefix}metadata)) AND \n\t\t\t\t(id not in (select name_id from {$CONFIG->dbprefix}annotations)) AND \n\t\t\t\t(id not in (select value_id from {$CONFIG->dbprefix}annotations)) \n\t\t\t)";
return delete_data($query);
}
示例6: update_entity
/**
* 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) {
$new_entity = $newentity_cache->delete($guid);
}
// Handle cases where there was no error BUT no rows were updated!
if ($ret === false) {
return false;
}
return true;
}
}
}
示例7: unban_user
/**
* Unban a user.
*
* @param int $user_guid Unban a user.
*/
function unban_user($user_guid)
{
global $CONFIG;
$user_guid = (int) $user_guid;
$user = get_entity($user_guid);
if ($user && $user->canEdit() && $user instanceof ElggUser) {
if (trigger_elgg_event('unban', 'user', $user)) {
create_metadata($user_guid, 'ban_reason', '', '', 0, ACCESS_PUBLIC);
// invalidate memcache for this user
static $newentity_cache;
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$newentity_cache->delete($user_guid);
}
return update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid={$user_guid}");
}
}
return false;
}
示例8: datalist_set
/**
* Sets the value for a system-wide piece of data (overwriting a previous value if it exists)
*
* @param string $name The name of the datalist
* @param string $value The new value
* @return true
*/
function datalist_set($name, $value)
{
global $CONFIG, $DATALIST_CACHE;
$name = sanitise_string($name);
$value = sanitise_string($value);
// If memcache is available then invalidate the cached copy
static $datalist_memcache;
if (!$datalist_memcache && is_memcache_available()) {
$datalist_memcache = new ElggMemcache('datalist_memcache');
}
if ($datalist_memcache) {
$datalist_memcache->delete($name);
}
//delete_data("delete from {$CONFIG->dbprefix}datalists where name = '{$name}'");
insert_data("INSERT into {$CONFIG->dbprefix}datalists set name = '{$name}', value = '{$value}' ON DUPLICATE KEY UPDATE value='{$value}'");
$DATALIST_CACHE[$name] = $value;
return true;
}
示例9: subsite_manager_plugin_action_hook
/**
* The settings of a plugin have changed, check if we need to reset the cron cache file (only on subsites)
*
* @param string $hook
* @param string $action => the action being called
* @param unknown_type $return_value
* @param unknown_type $params
*/
function subsite_manager_plugin_action_hook($hook, $action, $return_value, $params)
{
// are we on a Subsite, so we can handle cron reset
if (subsite_manager_on_subsite() && $action == "plugins/settings/save") {
$site = elgg_get_site_entity();
// handling of the cron cache reset is done by the event function
subsite_manager_remove_cron_cache($site->getGUID());
}
// clear plugin order cache
if (is_memcache_available()) {
$memcache = new ElggMemcache('subsite_manager');
$memcache->delete('plugin_order');
}
}
示例10: delete
/**
* Deletes the entity.
*
* Removes the entity and its metadata, annotations, relationships,
* river entries, and private data.
*
* Optionally can remove entities contained and owned by this entity.
*
* @warning If deleting recursively, this bypasses ownership of items contained by
* the entity. That means that if the container_guid = $this->guid, the item will
* be deleted regardless of who owns it.
*
* @param bool $recursive If true (default) then all entities which are
* owned or contained by $this will also be deleted.
*
* @return bool
*/
public function delete($recursive = true)
{
global $CONFIG;
$guid = $this->guid;
if (!$guid) {
return false;
}
if (!elgg_trigger_event('delete', $this->type, $this)) {
return false;
}
if (!$this->canEdit()) {
return false;
}
_elgg_invalidate_cache_for_entity($guid);
// 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);
}
// Delete contained owned and otherwise releated objects (depth first)
if ($recursive) {
// Temporary token overriding access controls
// @todo Do this better.
static $__RECURSIVE_DELETE_TOKEN;
// Make it slightly harder to guess
$__RECURSIVE_DELETE_TOKEN = md5(elgg_get_logged_in_user_guid());
$entity_disable_override = access_get_show_hidden_status();
access_show_hidden_entities(true);
$ia = elgg_set_ignore_access(true);
// @todo there was logic in the original code that ignored
// entities with owner or container guids of themselves.
// this should probably be prevented in \ElggEntity instead of checked for here
$options = array('wheres' => array("((container_guid = {$guid} OR owner_guid = {$guid} OR site_guid = {$guid})" . " AND guid != {$guid})"), 'limit' => 0);
$batch = new \ElggBatch('elgg_get_entities', $options);
$batch->setIncrementOffset(false);
foreach ($batch as $e) {
$e->delete(true);
}
access_show_hidden_entities($entity_disable_override);
$__RECURSIVE_DELETE_TOKEN = null;
elgg_set_ignore_access($ia);
}
$entity_disable_override = access_get_show_hidden_status();
access_show_hidden_entities(true);
$ia = elgg_set_ignore_access(true);
// Now delete the entity itself
$this->deleteMetadata();
$this->deleteOwnedMetadata();
$this->deleteAnnotations();
$this->deleteOwnedAnnotations();
$this->deleteRelationships();
access_show_hidden_entities($entity_disable_override);
elgg_set_ignore_access($ia);
elgg_delete_river(array('subject_guid' => $guid));
elgg_delete_river(array('object_guid' => $guid));
elgg_delete_river(array('target_guid' => $guid));
remove_all_private_settings($guid);
$res = $this->getDatabase()->deleteData("DELETE FROM {$CONFIG->dbprefix}entities WHERE guid = {$guid}");
if ($res) {
$sub_table = "";
// Where appropriate delete the sub table
switch ($this->type) {
case 'object':
$sub_table = $CONFIG->dbprefix . 'objects_entity';
break;
case 'user':
$sub_table = $CONFIG->dbprefix . 'users_entity';
break;
case 'group':
$sub_table = $CONFIG->dbprefix . 'groups_entity';
break;
case 'site':
$sub_table = $CONFIG->dbprefix . 'sites_entity';
break;
}
if ($sub_table) {
$this->getDatabase()->deleteData("DELETE FROM {$sub_table} WHERE guid = {$guid}");
}
}
return (bool) $res;
//.........这里部分代码省略.........
示例11: datalist_set
/**
* Set the value for a datalist element.
*
* @param string $name The name of the datalist
* @param string $value The new value
*
* @return bool
* @access private
*/
function datalist_set($name, $value)
{
global $CONFIG, $DATALIST_CACHE;
// cannot store anything longer than 255 characters in db, so catch before we set
if (elgg_strlen($name) > 255) {
elgg_log("The name length for configuration variables cannot be greater than 255", "ERROR");
return false;
}
$sanitised_name = sanitise_string($name);
$sanitised_value = sanitise_string($value);
// If memcache is available then invalidate the cached copy
static $datalist_memcache;
if (!$datalist_memcache && is_memcache_available()) {
$datalist_memcache = new ElggMemcache('datalist_memcache');
}
if ($datalist_memcache) {
$datalist_memcache->delete($name);
}
$success = insert_data("INSERT into {$CONFIG->dbprefix}datalists" . " set name = '{$sanitised_name}', value = '{$sanitised_value}'" . " ON DUPLICATE KEY UPDATE value='{$sanitised_value}'");
if ($success !== FALSE) {
$DATALIST_CACHE[$name] = $value;
return true;
} else {
return false;
}
}
示例12: subsite_manager_move_entity_to_site
//.........这里部分代码省略.........
$query .= " SET access_id = {$group_acl}";
$query .= " WHERE entity_guid = {$entity->getGUID()}";
$query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager change entity({$entity->getGUID()}) annotation access: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// move river
$query = "UPDATE {$dbprefix}river";
$query .= " SET site_guid = {$target_site->getGUID()}";
$query .= " WHERE subject_guid = {$entity->getGUID()}";
$query .= " OR object_guid = {$entity->getGUID()}";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager move entity({$entity->getGUID()}) river: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// change river access
$query = "UPDATE {$dbprefix}river";
$query .= " SET access_id = {$group_acl}";
$query .= " WHERE (subject_guid = {$entity->getGUID()}";
$query .= " OR object_guid = {$entity->getGUID()})";
$query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager change entity({$entity->getGUID()}) river access: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// move metadata
$query = "UPDATE {$dbprefix}metadata";
$query .= " SET site_guid = {$target_site->getGUID()}";
$query .= " WHERE entity_guid = {$entity->getGUID()}";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager move entity({$entity->getGUID()}) metadata: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// change metadata access
$query = "UPDATE {$dbprefix}metadata";
$query .= " SET access_id = {$group_acl}";
$query .= " WHERE entity_guid = {$entity->getGUID()}";
$query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager change entity({$entity->getGUID()}) metadata access: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// move entity
$query = "UPDATE {$dbprefix}entities";
$query .= " SET site_guid = {$target_site->getGUID()}";
$query .= " WHERE guid = {$entity->getGUID()}";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager move entity({$entity->getGUID()}) entity: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// change entity access
$query = "UPDATE {$dbprefix}entities";
$query .= " SET access_id = {$group_acl}";
$query .= " WHERE guid = {$entity->getGUID()}";
$query .= " AND access_id IN (" . implode(", ", $affected_access) . ")";
try {
update_data($query);
} catch (Exception $e) {
elgg_log("Subsite manager change entity({$entity->getGUID()}) entity access: " . $e->getMessage(), "ERROR");
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return false;
}
// cache cleanup
_elgg_invalidate_cache_for_entity($entity->getGUID());
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$newentity_cache->delete($entity->getGUID());
}
elgg_set_ignore_access($ia);
access_show_hidden_entities($hidden);
return true;
}
示例13: delete_metadata
/**
* Delete an item of metadata, where the current user has access.
*
* @param $id int The item of metadata to delete.
*/
function delete_metadata($id)
{
global $CONFIG;
$id = (int) $id;
$metadata = get_metadata($id);
// Tidy up if memcache is enabled.
static $metabyname_memcache;
if (!$metabyname_memcache && is_memcache_available()) {
$metabyname_memcache = new ElggMemcache('metabyname_memcache');
}
if ($metabyname_memcache) {
$metabyname_memcache->delete("{$metadata->entity_guid}:{$metadata->name_id}");
}
if ($metadata->canEdit()) {
return delete_data("DELETE from {$CONFIG->dbprefix}metadata where id={$id}");
}
}
示例14: update
/**
* 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;
}
示例15: garbagecollector_orphaned_metastrings
/**
* Delete any orphaned entries in metastrings.
*
* @return void
*/
function garbagecollector_orphaned_metastrings()
{
$dbprefix = elgg_get_config('dbprefix');
// Garbage collect metastrings
echo elgg_echo('garbagecollector:gc:metastrings');
// If memcache is enabled then we need to flush it of deleted values
if (is_memcache_available()) {
$select_query = "\n\t\tSELECT * FROM {$dbprefix}metastrings WHERE\n\t\t(\n\t\t\t(id NOT IN (SELECT name_id FROM {$dbprefix}metadata)) AND\n\t\t\t(id NOT IN (SELECT value_id FROM {$dbprefix}metadata)) AND\n\t\t\t(id NOT IN (SELECT name_id FROM {$dbprefix}annotations)) AND\n\t\t\t(id NOT IN (SELECT value_id FROM {$dbprefix}annotations))\n\t\t)";
$dead = get_data($select_query);
if ($dead) {
static $metastrings_memcache;
if (!$metastrings_memcache) {
$metastrings_memcache = new \ElggMemcache('metastrings_memcache');
}
foreach ($dead as $d) {
$metastrings_memcache->delete($d->string);
}
}
}
$query = "\n\t\tDELETE FROM {$dbprefix}metastrings WHERE\n\t\t(\n\t\t\t(id NOT IN (SELECT name_id FROM {$dbprefix}metadata)) AND\n\t\t\t(id NOT IN (SELECT value_id FROM {$dbprefix}metadata)) AND\n\t\t\t(id NOT IN (SELECT name_id FROM {$dbprefix}annotations)) AND\n\t\t\t(id NOT IN (SELECT value_id FROM {$dbprefix}annotations))\n\t\t)";
$result = delete_data($query);
if ($result !== false) {
echo elgg_echo('garbagecollector:ok');
} else {
echo elgg_echo('garbagecollector:error');
}
}