68 $singulars = [
'tag_name'];
81 return "{$main_alias}.value AS tag";
84 return "COUNT({$main_alias}.id) AS total";
101 return "{$main_alias}.value";
118 $options[
'callback'] =
function($row) {
121 $result->total = (int) $row->total;
144 $qb->addClause($where);
146 $row = $this->db->getDataRow(
$qb);
147 return $row ? new \ElggMetadata($row) : null;
162 if (!$this->events->trigger(
'delete',
'metadata',
$metadata)) {
172 $metadata->getEntity()?->invalidateCache();
191 if (!isset($metadata->value) || !isset($metadata->entity_guid)) {
192 elgg_log(
'Metadata must have a value and entity guid', \Psr\Log\LogLevel::ERROR);
196 if (!$this->entityTable->exists($metadata->entity_guid)) {
197 elgg_log(
"Can't create metadata on a non-existing entity_guid", \Psr\Log\LogLevel::ERROR);
201 if (!is_scalar($metadata->value)) {
202 elgg_log(
'To set multiple metadata values use ElggEntity::setMetadata', \Psr\Log\LogLevel::ERROR);
207 if ($this->
update($metadata)) {
208 return $metadata->id;
212 if (!$allow_multiple) {
217 Multiple '{$metadata->name}' metadata values exist for entity [guid: {$metadata->entity_guid}]. 218 Use ElggEntity::setMetadata() 225 if ($this->
update($metadata)) {
226 return $metadata->id;
231 if (!$this->events->triggerBefore(
'create',
'metadata', $metadata)) {
246 $id = $this->db->insertData(
$qb);
252 $metadata->id = (int)
$id;
255 if (!$this->events->trigger(
'create',
'metadata', $metadata)) {
261 $metadata->
getEntity()?->invalidateCache();
263 $this->events->triggerAfter(
'create',
'metadata', $metadata);
276 if (!$this->entityTable->exists($metadata->entity_guid)) {
277 elgg_log(
"Can't update metadata to a non-existing entity_guid", \Psr\Log\LogLevel::ERROR);
281 if (!$this->events->triggerBefore(
'update',
'metadata', $metadata)) {
288 ->
set(
'value_type',
$qb->param($metadata->value_type, ELGG_VALUE_STRING))
297 $metadata->
getEntity()?->invalidateCache();
299 $this->events->trigger(
'update',
'metadata', $metadata);
300 $this->events->triggerAfter(
'update',
'metadata', $metadata);
317 $options[
'metastring_type'] =
'metadata';
338 ->orderBy(
'entity_guid',
'asc')
339 ->addOrderBy(
'time_created',
'asc')
340 ->addOrderBy(
'id',
'asc');
342 return $this->db->getData(
$qb,
function ($row) {
343 return new \ElggMetadata($row);
365 'metadata_name',
'metadata_names',
366 'metadata_value',
'metadata_values',
372 if (isset($options[$key]) && !
elgg_is_empty($options[$key])) {
385 if (empty($options[
'guid'])) {
386 $this->access_cache->clear();
387 $this->metadata_cache->clear();
389 $this->entityTable->invalidateCache($options[
'guid']);
392 $options[
'batch'] =
true;
393 $options[
'batch_size'] = 50;
394 $options[
'batch_inc_offset'] =
false;
411 return $success ===
$count;
423 $cached_metadata = $this->metadata_cache->load($entity_guid);
424 if ($cached_metadata !== null) {
426 foreach ($cached_metadata as $md) {
427 if ($md->name !== $name) {
439 $callback =
function (\stdClass $row) {
440 return (
int) $row->id;
443 $ids = $this->db->getData(
$qb, $callback);
450 if (is_array($ids) &&
count($ids) === 1) {
451 return array_shift($ids);
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
Exception thrown if an argument is not of the expected type.
getEntity()
Get the entity this describes.
static find(array $options=[])
Build and execute a new query from an array of legacy options.
if(!$user||!$user->canDelete()) $name
if(!$user instanceof\ElggUser) $time_created
const ELGG_VALUE_INTEGER
Value types.
Database abstraction query builder.
trait TimeUsing
Adds methods for setting the current time (for testing)
static intoTable(string $table)
Returns a QueryBuilder for inserting data in a given table.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
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
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
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.
Exception that represents error in the program logic.
Extends QueryBuilder with ORDER BY clauses.
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
$guids
Activates all specified installed and inactive plugins.
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
$id
Generic annotation delete action.
Entity table database service.