70 $singulars = [
'tag_name'];
83 return "{$main_alias}.value AS tag";
86 return "COUNT({$main_alias}.id) AS total";
103 return "{$main_alias}.value";
120 $options[
'callback'] =
function($row) {
123 $result->total = (int) $row->total;
146 $qb->addClause($where);
148 $row = $this->db->getDataRow(
$qb);
149 return $row ? new \ElggMetadata($row) : null;
164 if (!$this->events->trigger(
'delete',
'metadata',
$metadata)) {
174 $this->metadata_cache->delete(
$metadata->entity_guid);
193 if (!isset($metadata->value) || !isset($metadata->entity_guid)) {
194 elgg_log(
'Metadata must have a value and entity guid', \Psr\Log\LogLevel::ERROR);
198 if (!$this->entityTable->exists($metadata->entity_guid)) {
199 elgg_log(
"Can't create metadata on a non-existing entity_guid", \Psr\Log\LogLevel::ERROR);
203 if (!is_scalar($metadata->value)) {
204 elgg_log(
'To set multiple metadata values use ElggEntity::setMetadata', \Psr\Log\LogLevel::ERROR);
209 if ($this->
update($metadata)) {
210 return $metadata->id;
214 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
215 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.", \Psr\Log\LogLevel::WARNING);
218 if (!$allow_multiple) {
223 Multiple '{$metadata->name}' metadata values exist for entity [guid: {$metadata->entity_guid}]. 224 Use ElggEntity::setMetadata() 231 if ($this->
update($metadata)) {
232 return $metadata->id;
237 if (!$this->events->triggerBefore(
'create',
'metadata', $metadata)) {
252 $id = $this->db->insertData(
$qb);
258 $metadata->id = (int)
$id;
261 if (!$this->events->trigger(
'create',
'metadata', $metadata)) {
267 $this->metadata_cache->
delete($metadata->entity_guid);
269 $this->events->triggerAfter(
'create',
'metadata', $metadata);
282 if (!$this->entityTable->exists($metadata->entity_guid)) {
283 elgg_log(
"Can't update metadata to a non-existing entity_guid", \Psr\Log\LogLevel::ERROR);
287 if (!$this->events->triggerBefore(
'update',
'metadata', $metadata)) {
291 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
292 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.", \Psr\Log\LogLevel::WARNING);
298 ->
set(
'value_type',
$qb->param($metadata->value_type, ELGG_VALUE_STRING))
307 $this->metadata_cache->delete($metadata->entity_guid);
309 $this->events->trigger(
'update',
'metadata', $metadata);
310 $this->events->triggerAfter(
'update',
'metadata', $metadata);
327 $options[
'metastring_type'] =
'metadata';
348 ->orderBy(
'entity_guid',
'asc')
349 ->addOrderBy(
'time_created',
'asc')
350 ->addOrderBy(
'id',
'asc');
352 return $this->db->getData(
$qb,
function ($row) {
353 return new \ElggMetadata($row);
375 'metadata_name',
'metadata_names',
376 'metadata_value',
'metadata_values',
382 if (isset($options[$key]) && !
elgg_is_empty($options[$key])) {
395 if (empty($options[
'guid'])) {
396 $this->access_cache->clear();
397 $this->metadata_cache->clear();
399 $this->entityTable->invalidateCache($options[
'guid']);
402 $options[
'batch'] =
true;
403 $options[
'batch_size'] = 50;
404 $options[
'batch_inc_offset'] =
false;
421 return $success ===
$count;
433 $cached_metadata = $this->metadata_cache->load($entity_guid);
434 if ($cached_metadata !== null) {
436 foreach ($cached_metadata as $md) {
437 if ($md->name !== $name) {
449 $callback =
function (\stdClass $row) {
450 return (
int) $row->id;
453 $ids = $this->db->getData(
$qb, $callback);
460 if (is_array($ids) &&
count($ids) === 1) {
461 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.
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
delete(bool $recursive=true, bool $persistent=null)
Deletes the entity.
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.