94 if ($class_name && !class_exists($class_name)) {
95 $this->
getLogger()->error(
"Class '{$class_name}' was not found");
99 if (empty($class_name)) {
101 'object' => \ElggObject::class,
102 'user' => \ElggUser::class,
103 'group' => \ElggGroup::class,
104 'site' => \ElggSite::class,
106 if (isset($map[$type])) {
107 $class_name = $map[
$type];
111 $parents = class_parents($class_name);
112 if ($parents ===
false || !isset($parents[\ElggEntity::class])) {
113 $this->
getLogger()->error(
"{$class_name} must extend " . \ElggEntity::class);
140 $where->guids =
$guid;
144 $select->select(
"{$select->getTableAlias()}.*");
145 $select->addClause($where);
147 return $this->db->getDataRow($select) ?: null;
167 'container_guid' => $insert->param($row->container_guid,
ELGG_VALUE_GUID),
168 'access_id' => $insert->param($row->access_id,
ELGG_VALUE_ID),
174 return $this->db->insertData($insert);
187 $update->set(
'owner_guid', $update->param($row->owner_guid,
ELGG_VALUE_GUID))
188 ->
set(
'container_guid', $update->param($row->container_guid,
ELGG_VALUE_GUID))
189 ->
set(
'access_id', $update->param($row->access_id,
ELGG_VALUE_ID))
194 return $this->db->updateData($update);
207 if (!isset($row->type) || !isset($row->subtype)) {
216 return new $class_name($row);
249 $entity = $this->entity_cache->load($guid);
251 (!isset($type) ||
$entity->type === $type) &&
252 (!isset($subtype) ||
$entity->subtype === $subtype)
257 $row = $this->
getRow($guid);
262 if (isset($type) && $row->type !== $type) {
266 if (isset($subtype) && $row->subtype !== $subtype) {
290 public function exists(
int $guid): bool {
293 return !empty($this->
getRow($guid));
317 $preload = array_filter(
$results,
function ($e) {
318 return $e instanceof \ElggEntity;
321 $this->metadata_cache->populateFromEntities($preload);
323 $props_to_preload = [];
325 $props_to_preload[] =
'owner_guid';
329 $props_to_preload[] =
'container_guid';
332 if (!empty($props_to_preload)) {
333 _elgg_services()->entityPreloader->preload($preload, $props_to_preload);
354 ->where($update->compare(
'guid',
'=', $entity->guid,
ELGG_VALUE_GUID));
356 $this->db->updateData($update);
379 ->where($update->compare(
'guid',
'=', $entity->guid,
ELGG_VALUE_GUID));
381 $this->db->updateData($update);
395 if (empty($guid) || $guid === $this->session_manager->getLoggedInUserGuid()) {
396 return $this->session_manager->getLoggedInUser();
401 return $this->
get(
$guid,
'user');
407 $message = $this->translator->translate(
'UserFetchFailureException', [$guid]);
428 return $this->db->updateData(
$qb);
443 return $this->db->updateData(
$qb);
458 return $this->db->updateData(
$qb);
470 if (!$entity->guid) {
476 return $this->events->triggerSequence(
'delete', $entity->type, $entity,
function(\
ElggEntity $entity) use ($recursive) {
483 $this->deleted_guids[] = $entity->guid;
494 return (
bool) $this->db->deleteData(
$qb);
507 if (!$entity->guid) {
511 if (!$this->config->trash_enabled) {
512 return $this->
delete(
$entity, $recursive);
520 return $this->events->triggerSequence(
'trash', $entity->type, $entity,
function(\
ElggEntity $entity) use ($recursive) {
521 $unban_after =
false;
522 if ($entity instanceof \
ElggUser && !$entity->isBanned()) {
528 $this->trashed_guids[] = $entity->guid;
537 if (!empty($deleter_guid)) {
538 $entity->addRelationship($deleter_guid,
'deleted_by');
545 $trashed = $this->db->updateData(
$qb);
586 'batch_inc_offset' =>
false,
591 if (in_array($e->guid, $this->deleted_guids)) {
597 if (!$e->delete(
true,
true)) {
629 'batch_inc_offset' =>
false,
634 if (in_array($e->guid, $this->trashed_guids)) {
640 if (!$e->delete(
true,
false)) {
644 $e->addRelationship($entity->guid,
'deleted_with');
660 $entity->deleteOwnedAccessCollections();
661 $entity->deleteAccessCollectionMemberships();
664 _elgg_services()->relationshipsTable->removeAll($entity->guid,
'',
false,
'',
false);
665 _elgg_services()->relationshipsTable->removeAll($entity->guid,
'',
true,
'',
false);
666 $entity->deleteOwnedAnnotations();
667 $entity->deleteAnnotations();
668 $entity->deleteMetadata();
669 _elgg_services()->delayedEmailQueueTable->deleteAllRecipientRows($entity->guid);
672 $dir = new \Elgg\EntityDirLocator($entity->guid);
enable(\ElggEntity $entity)
Enables entity.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
const ELGG_DISABLE_SYSTEM_LOG
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
invalidateCache()
Invalidate cache for entity.
disable(\ElggEntity $entity)
Disables entity.
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Exception thrown if a value does not adhere to a defined valid data domain.
Database abstraction query builder.
fetch(QueryBuilder $query, array $options=[])
Returns an array of entities with optional filtering.
trait TimeUsing
Adds methods for setting the current time (for testing)
deleteRelatedEntities(\ElggEntity $entity)
Deletes entities owned or contained by the entity being deletes.
static intoTable(string $table)
Returns a QueryBuilder for inserting data in a given table.
getUserForPermissionsCheck(int $guid=null)
Get a user by GUID even if the entity is hidden or disabled.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
$config
Advanced site settings, debugging section.
getCurrentTime($modifier= '')
Get the (cloned) time.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
trait Loggable
Enables adding a logger.
const ELGG_IGNORE_ACCESS
elgg_call() flags
invalidateCache(int $guid)
Invalidate cache for entity.
getEntityClass(string $type, string $subtype)
Returns class name registered as a constructor for a given type and subtype The classname is also val...
trashRelatedEntities(\ElggEntity $entity)
Trash entities owned or contained by the entity being trashed.
const ELGG_SHOW_DISABLED_ENTITIES
removeAllRelatedRiverItems()
Removes all river items related to this entity.
elgg_get_entities(array $options=[])
Fetches/counts entities or performs a calculation on their properties.
Builds queries for filtering entities by their properties in the entities table.
rowToElggStar(\stdClass $row)
Create an Elgg* object from a given entity row.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
Exception indicating a user could not be looked up for a permissions check.
Volatile cache for entities.
updateTimeDeleted(\ElggEntity $entity, int $deleted=null)
Update the time_deleted column in the entities table for $entity.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
static fromTable(string $table)
Returns a QueryBuilder for deleting data from a given table.
updateLastAction(\ElggEntity $entity, int $posted=null)
Update the last_action column in the entities table for $entity.
isDeleted()
Is the entity marked as deleted.
restore(\ElggEntity $entity)
Restore entity.
trash(\ElggEntity $entity, bool $recursive=true)
Trash an entity (not quite delete but close)
const ELGG_SHOW_DELETED_ENTITIES
__construct(protected Config $config, protected Database $db, protected EntityCache $entity_cache, protected MetadataCache $metadata_cache, protected EventsService $events, protected SessionManagerService $session_manager, protected Translator $translator)
Constructor.
const ELGG_VALUE_TIMESTAMP
elgg_delete_directory(string $directory, bool $leave_base_directory=false)
Delete a directory and all its contents.
exists(int $guid)
Does an entity exist?
getLogger()
Returns logger.
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.
updateRow(int $guid,\stdClass $row)
Update entity table row.
updateTimeDeleted(int $deleted=null)
Update the time_deleted column in the entities table.
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
deleteEntityProperties(\ElggEntity $entity)
Clear data from secondary tables.
_elgg_services()
Get the global service provider.
getRow(int $guid, int $user_guid=null)
Returns a database row from the entities table.
$attributes
Elgg AJAX loader.
setEntityClass(string $type, string $subtype, string $class= '')
Sets class constructor name for entities with given type and subtype.
insertRow(\stdClass $row, array $attributes=[])
Adds a new row to the entity table.
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
Entity table database service.
$guid
Reset an ElggUpgrade.