本文整理汇总了PHP中ElggMemcache类的典型用法代码示例。如果您正苦于以下问题:PHP ElggMemcache类的具体用法?PHP ElggMemcache怎么用?PHP ElggMemcache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ElggMemcache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rowToElggStar
/**
* Create an Elgg* object from a given entity row.
*
* Handles loading all tables into the correct class.
*
* @param \stdClass $row The row of the entry in the entities table.
*
* @return \ElggEntity|false
* @see get_entity_as_row()
* @see add_subtype()
* @see get_entity()
* @access private
*
* @throws \ClassException|\InstallationException
*/
function rowToElggStar($row)
{
if (!$row instanceof \stdClass) {
return $row;
}
if (!isset($row->guid) || !isset($row->subtype)) {
return $row;
}
$new_entity = false;
// Create a memcache cache if we can
static $newentity_cache;
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new \ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$new_entity = $newentity_cache->load($row->guid);
}
if ($new_entity) {
return $new_entity;
}
// load class for entity if one is registered
$classname = get_subtype_class_from_id($row->subtype);
if ($classname != "") {
if (class_exists($classname)) {
$new_entity = new $classname($row);
if (!$new_entity instanceof \ElggEntity) {
$msg = $classname . " is not a " . '\\ElggEntity' . ".";
throw new \ClassException($msg);
}
} else {
error_log("Class '" . $classname . "' was not found, missing plugin?");
}
}
if (!$new_entity) {
//@todo Make this into a function
switch ($row->type) {
case 'object':
$new_entity = new \ElggObject($row);
break;
case 'user':
$new_entity = new \ElggUser($row);
break;
case 'group':
$new_entity = new \ElggGroup($row);
break;
case 'site':
$new_entity = new \ElggSite($row);
break;
default:
$msg = "Entity type " . $row->type . " is not supported.";
throw new \InstallationException($msg);
}
}
// Cache entity if we have a cache available
if ($newentity_cache && $new_entity) {
$newentity_cache->save($new_entity->guid, $new_entity);
}
return $new_entity;
}
示例2: elasticsearch_entity_row_to_std
/**
* Create a standard object from a given entity row.
*
* @param stdClass $row The row of the entry in the entities table.
*
* @return ElggEntity|false
* @link http://docs.elgg.org/DataModel/Entities
* @see get_entity_as_row()
* @see add_subtype()
* @see get_entity()
* @access private
*
* @throws ClassException|InstallationException
*/
function elasticsearch_entity_row_to_std($row)
{
if (!$row instanceof stdClass) {
return $row;
}
if (!isset($row->guid) || !isset($row->subtype)) {
return $row;
}
$new_entity = false;
// Create a memcache cache if we can
static $newentity_cache;
if (!$newentity_cache && is_memcache_available()) {
$newentity_cache = new ElggMemcache('new_entity_cache');
}
if ($newentity_cache) {
$new_entity = $newentity_cache->load($row->guid);
}
if ($new_entity) {
return $new_entity;
}
try {
// load class for entity if one is registered
$classname = get_subtype_class_from_id($row->subtype);
if ($classname != "") {
if (class_exists($classname)) {
$new_entity = new $classname($row);
if (!$new_entity instanceof ElggEntity) {
$msg = elgg_echo('ClassException:ClassnameNotClass', array($classname, 'ElggEntity'));
throw new ClassException($msg);
}
}
}
if (!$new_entity) {
switch ($row->type) {
case 'object':
$new_entity = new ElggObject($row);
break;
case 'user':
$new_entity = new ElggUser($row);
break;
case 'group':
$new_entity = new ElggGroup($row);
break;
case 'site':
$new_entity = new ElggSite($row);
break;
default:
$msg = elgg_echo('InstallationException:TypeNotSupported', array($row->type));
throw new InstallationException($msg);
}
}
} catch (IncompleteEntityException $e) {
return false;
}
return $new_entity;
}
示例3: _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);
}
}
示例4: 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;
}
示例5: 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());
}
}
}
示例6: delete_entity
/**
* Delete an entity.
*
* Removes an entity and its metadata, annotations, relationships, river entries,
* and private data.
*
* Optionally can remove entities contained and owned by $guid.
*
* @tip Use ElggEntity::delete() instead.
*
* @warning If deleting recursively, this bypasses ownership of items contained by
* the entity. That means that if the container_guid = $guid, the item will be deleted
* regardless of who owns it.
*
* @param int $guid The guid of the entity to delete
* @param bool $recursive If true (default) then all entities which are
* owned or contained by $guid will also be deleted.
*
* @return bool
* @access private
*/
function delete_entity($guid, $recursive = true)
{
global $CONFIG, $ENTITY_CACHE;
$guid = (int) $guid;
if ($entity = get_entity($guid)) {
if (elgg_trigger_event('delete', $entity->type, $entity)) {
if ($entity->canEdit()) {
// delete cache
if (isset($ENTITY_CACHE[$guid])) {
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);
$sub_entities = get_data("SELECT * from {$CONFIG->dbprefix}entities\n\t\t\t\t\t\tWHERE container_guid={$guid}\n\t\t\t\t\t\t\tor owner_guid={$guid}\n\t\t\t\t\t\t\tor site_guid={$guid}", 'entity_row_to_elggstar');
if ($sub_entities) {
foreach ($sub_entities as $e) {
// check for equality so that an entity that is its own
// owner or container does not cause infinite loop
if ($e->guid != $guid) {
$e->delete(true);
}
}
}
access_show_hidden_entities($entity_disable_override);
$__RECURSIVE_DELETE_TOKEN = null;
elgg_set_ignore_access($ia);
}
// Now delete the entity itself
$entity->deleteMetadata();
$entity->deleteOwnedMetadata();
$entity->deleteAnnotations();
$entity->deleteOwnedAnnotations();
$entity->deleteRelationships();
elgg_delete_river(array('subject_guid' => $guid));
elgg_delete_river(array('object_guid' => $guid));
remove_all_private_settings($guid);
$res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
if ($res) {
$sub_table = "";
// Where appropriate delete the sub table
switch ($entity->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) {
delete_data("DELETE from {$sub_table} where guid={$guid}");
}
}
return $res;
}
}
}
return false;
//.........这里部分代码省略.........
示例7: delete_entity
/**
* Delete an entity.
*
* Removes an entity and its metadata, annotations, relationships, river entries,
* and private data.
*
* Optionally can remove entities contained and owned by $guid.
*
* @tip Use ElggEntity::delete() instead.
*
* @warning If deleting recursively, this bypasses ownership of items contained by
* the entity. That means that if the container_guid = $guid, the item will be deleted
* regardless of who owns it.
*
* @param int $guid The guid of the entity to delete
* @param bool $recursive If true (default) then all entities which are
* owned or contained by $guid will also be deleted.
*
* @return bool
* @access private
*/
function delete_entity($guid, $recursive = true)
{
global $CONFIG, $ENTITY_CACHE;
$guid = (int) $guid;
if ($entity = get_entity($guid)) {
if (elgg_trigger_event('delete', $entity->type, $entity)) {
if ($entity->canEdit()) {
// delete cache
if (isset($ENTITY_CACHE[$guid])) {
_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("limit" => 0, "order_by" => false, "site_guids" => false);
foreach (array("site_guid", "container_guid", "owner_guid") as $column) {
$options['wheres'] = array("(({$column} = {$guid}) AND guid != {$guid})");
$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);
}
// Now delete the entity itself
$entity->deleteMetadata();
$entity->deleteOwnedMetadata();
$entity->deleteAnnotations();
$entity->deleteOwnedAnnotations();
$entity->deleteRelationships();
elgg_delete_river(array('subject_guid' => $guid));
elgg_delete_river(array('object_guid' => $guid));
remove_all_private_settings($guid);
$res = delete_data("DELETE from {$CONFIG->dbprefix}entities where guid={$guid}");
if ($res) {
$sub_table = "";
// Where appropriate delete the sub table
switch ($entity->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) {
delete_data("DELETE from {$sub_table} where guid={$guid}");
}
}
return (bool) $res;
}
}
//.........这里部分代码省略.........
示例8: 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;
}
示例9: 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;
}
示例10: get_metadata_byname
/**
* Return the metadata values that match your query.
*
* @param string $meta_name
* @return mixed either a value, an array of ElggMetadata or false.
*/
function get_metadata_byname($entity_guid, $meta_name)
{
global $CONFIG;
$meta_name = get_metastring_id($meta_name);
if (empty($meta_name)) {
return false;
}
$entity_guid = (int) $entity_guid;
$access = get_access_sql_suffix("e");
$md_access = get_access_sql_suffix("m");
// If memcache is available then cache this (cache only by name for now since this is the most common query)
$meta = null;
static $metabyname_memcache;
if (!$metabyname_memcache && is_memcache_available()) {
$metabyname_memcache = new ElggMemcache('metabyname_memcache');
}
if ($metabyname_memcache) {
$meta = $metabyname_memcache->load("{$entity_guid}:{$meta_name}");
}
if ($meta) {
return $meta;
}
$result = get_data("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.entity_guid JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid={$entity_guid} and m.name_id='{$meta_name}' and {$access} and {$md_access}", "row_to_elggmetadata");
if (!$result) {
return false;
}
// Cache if memcache available
if ($metabyname_memcache) {
if (count($result) == 1) {
$r = $result[0];
} else {
$r = $result;
}
$metabyname_memcache->setDefaultExpiry(3600);
// This is a bit of a hack - we shorten the expiry on object metadata so that it'll be gone in an hour. This means that deletions and more importantly updates will filter through eventually.
$metabyname_memcache->save("{$entity_guid}:{$meta_name}", $r);
}
if (count($result) == 1) {
return $result[0];
}
return $result;
}
示例11: 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');
}
}
示例12: remove_all_private_settings
/**
* Deletes all private settings for an entity.
*
* @param int $entity_guid The Entity GUID
*
* @return bool
* @see get_private_setting()
* @see get_all_private_settings()
* @see set_private_setting()
* @see remove_private_settings()
* @link http://docs.elgg.org/DataModel/Entities/PrivateSettings
*/
function remove_all_private_settings($entity_guid)
{
global $PRIVATE_SETTINGS_CACHE;
static $private_setting_memcache;
$dbprefix = elgg_get_config("dbprefix");
$entity_guid = (int) $entity_guid;
// check if you have access to the entity
if (!get_entity_as_row($entity_guid)) {
return false;
}
if (!isset($private_setting_memcache) && is_memcache_available()) {
$private_setting_memcache = new ElggMemcache("private_settings");
}
$query = "DELETE FROM {$dbprefix}private_settings";
$query .= " WHERE entity_guid = {$entity_guid}";
$result = delete_data($query);
if ($result !== false) {
// unset local cache
if (isset($PRIVATE_SETTINGS_CACHE[$entity_guid])) {
unset($PRIVATE_SETTINGS_CACHE[$entity_guid]);
}
// unset memcache
if ($private_setting_memcache) {
// invalidate the settings in Memcache
$private_setting_memcache->delete($entity_guid);
}
}
return $result !== false;
}
示例13: unsetAllSettings
/**
* Removes all settings for this plugin.
*
* @todo Should be a better way to do this without dropping to raw SQL.
* @todo If we could namespace the plugin settings this would be cleaner.
* @return bool
*/
public function unsetAllSettings()
{
$db_prefix = get_config('dbprefix');
$ps_prefix = elgg_namespace_plugin_private_setting('internal', '');
$q = "DELETE FROM {$db_prefix}private_settings\n\t\t\tWHERE entity_guid = {$this->guid}\n\t\t\tAND name NOT LIKE '{$ps_prefix}%'\n\t\t\tAND name <> 'path'";
$result = delete_data($q);
// check memcache
if ($result !== false && is_memcache_available()) {
$private_setting_cache = new ElggMemcache("private_settings");
// remove settings from memcache
$private_setting_cache->delete($this->guid);
}
// unvalidate cache to reset to default behaviour
elgg_invalidate_simplecache();
return $result;
}
示例14: elgg_get_site_entity
<?php
$site = elgg_get_site_entity();
$key = "css_splash_" . $site->guid;
if (is_memcache_available()) {
$cache = new ElggMemcache("rijkshuisstijl");
$css = $cache->load($key);
if ($css) {
echo $css;
return;
}
}
$parser = new Less_Parser();
$parser->parseFile(RIJKSHUISSTIJL_LESS . "/splash.less", "/mod/rijkshuisstijl/src/assets/");
$colors = elgg_get_plugin_setting("colors", "rijkshuisstijl");
if ($colors) {
$colors = unserialize($colors);
foreach ($colors as $number => $value) {
$parser->parse("@belastingdienst--{$number}: {$value};");
}
}
$css = $parser->getCss();
echo $css;
if (is_memcache_available()) {
$cache->save($key, $css, 0);
}
示例15: 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');
}
}