75 $singulars = [
'tag_name'];
88 return "{$main_alias}.value AS tag";
91 return "COUNT({$main_alias}.id) AS total";
108 return "{$main_alias}.value";
125 $options[
'callback'] =
function($row) {
128 $result->total = (int) $row->total;
151 $qb->addClause($where);
153 $row = $this->db->getDataRow(
$qb);
154 return $row ? new \ElggMetadata($row) : null;
179 $this->metadata_cache->clear(
$metadata->entity_guid);
198 if (!isset($metadata->value) || !isset($metadata->entity_guid)) {
199 elgg_log(
'Metadata must have a value and entity guid',
'ERROR');
203 if (!$this->entityTable->exists($metadata->entity_guid)) {
204 elgg_log(
"Can't create metadata on a non-existing entity_guid",
'ERROR');
208 if (!is_scalar($metadata->value)) {
209 elgg_log(
'To set multiple metadata values use ElggEntity::setMetadata',
'ERROR');
214 if ($this->
update($metadata)) {
215 return $metadata->id;
219 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
220 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
223 if (!$allow_multiple) {
228 Multiple '{$metadata->name}' metadata values exist for entity [guid: {$metadata->entity_guid}]. 229 Use ElggEntity::setMetadata() 236 if ($this->
update($metadata)) {
237 return $metadata->id;
242 if (!$this->events->triggerBefore(
'create',
'metadata', $metadata)) {
257 $id = $this->db->insertData(
$qb);
263 $metadata->id = (int)
$id;
266 if (!$this->events->trigger(
'create',
'metadata', $metadata)) {
272 $this->metadata_cache->clear($metadata->entity_guid);
274 $this->events->triggerAfter(
'create',
'metadata', $metadata);
287 if (!$this->entityTable->exists($metadata->entity_guid)) {
288 elgg_log(
"Can't update metadata to a non-existing entity_guid",
'ERROR');
292 if (!$this->events->triggerBefore(
'update',
'metadata', $metadata)) {
296 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
297 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
303 ->
set(
'value_type',
$qb->param($metadata->value_type, ELGG_VALUE_STRING))
312 $this->metadata_cache->clear($metadata->entity_guid);
314 $this->events->trigger(
'update',
'metadata', $metadata);
315 $this->events->triggerAfter(
'update',
'metadata', $metadata);
332 $options[
'metastring_type'] =
'metadata';
353 ->orderBy(
'entity_guid',
'asc')
354 ->addOrderBy(
'time_created',
'asc')
355 ->addOrderBy(
'id',
'asc');
357 return $this->db->getData(
$qb,
function ($row) {
358 return new \ElggMetadata($row);
380 'metadata_name',
'metadata_names',
381 'metadata_value',
'metadata_values',
387 if (isset($options[$key]) && !
elgg_is_empty($options[$key])) {
400 $this->metadata_cache->invalidateByOptions($options);
402 $options[
'batch'] =
true;
403 $options[
'batch_size'] = 50;
404 $options[
'batch_inc_offset'] =
false;
421 return $success ===
$count;
433 if ($this->metadata_cache->isLoaded($entity_guid)) {
434 $ids = $this->metadata_cache->getSingleId($entity_guid, $name);
441 $callback =
function (\stdClass $row) {
442 return (
int) $row->id;
445 $ids = $this->db->getData(
$qb, $callback);
452 if (is_array($ids) &&
count($ids) === 1) {
453 return array_shift($ids);
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
static table($table, $alias=null)
{}
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)
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.
static intoTable($table)
{}
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
compare($x, $comparison, $y=null, $type=null, $case_sensitive=null)
Build value comparison clause.
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
static fromTable($table, $alias=null)
{}
$guids
Activates all specified installed and inactive plugins.
_elgg_services()
Get the global service provider.
$id
Generic annotation delete action.
static fromTable($table, $alias=null)
{}
Entity table database service.