86 $singulars = [
'tag_name'];
99 return "{$main_alias}.value AS tag";
102 return "COUNT({$main_alias}.id) AS total";
119 return "{$main_alias}.value";
136 $options[
'callback'] =
function($row) {
139 $result->total = (int) $row->total;
156 public function get(
$id) {
162 $qb->addClause($where);
164 $row = $this->db->getDataRow(
$qb);
166 return new \ElggMetadata($row);
194 $this->metadata_cache->clear(
$metadata->entity_guid);
213 if (!isset($metadata->value) || !isset($metadata->entity_guid)) {
214 elgg_log(
"Metadata must have a value and entity guid",
'ERROR');
218 if (!$this->entityTable->exists($metadata->entity_guid)) {
219 elgg_log(
"Can't create metadata on a non-existing entity_guid",
'ERROR');
223 if (!is_scalar($metadata->value)) {
224 elgg_log(
"To set multiple metadata values use ElggEntity::setMetadata",
'ERROR');
229 if ($this->
update($metadata)) {
230 return $metadata->id;
234 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
235 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
238 if (!$allow_multiple) {
243 Multiple '{$metadata->name}' metadata values exist for entity [guid: {$metadata->entity_guid}]. 244 Use ElggEntity::setMetadata() 251 if ($this->
update($metadata)) {
252 return $metadata->id;
257 if (!$this->events->triggerBefore(
'create',
'metadata', $metadata)) {
272 $id = $this->db->insertData(
$qb);
278 $metadata->id = (int)
$id;
281 if ($this->events->trigger(
'create',
'metadata', $metadata)) {
282 $this->metadata_cache->clear($metadata->entity_guid);
284 $this->events->triggerAfter(
'create',
'metadata', $metadata);
303 if (!$this->entityTable->exists($metadata->entity_guid)) {
304 elgg_log(
"Can't update metadata to a non-existing entity_guid",
'ERROR');
308 if (!$this->events->triggerBefore(
'update',
'metadata', $metadata)) {
312 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
313 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
319 ->
set(
'value_type',
$qb->param($metadata->value_type, ELGG_VALUE_STRING))
328 $this->metadata_cache->clear($metadata->entity_guid);
330 $this->events->trigger(
'update',
'metadata', $metadata);
331 $this->events->triggerAfter(
'update',
'metadata', $metadata);
349 $options[
'metastring_type'] =
'metadata';
371 ->orderBy(
'entity_guid',
'asc')
372 ->addOrderBy(
'time_created',
'asc')
373 ->addOrderBy(
'id',
'asc');
375 return $this->db->getData(
$qb,
function ($row) {
376 return new \ElggMetadata($row);
397 'metadata_name',
'metadata_names',
398 'metadata_value',
'metadata_values',
404 if (isset($options[$key]) && !
elgg_is_empty($options[$key])) {
417 $this->metadata_cache->invalidateByOptions($options);
419 $options[
'batch'] =
true;
420 $options[
'batch_size'] = 50;
421 $options[
'batch_inc_offset'] =
false;
438 return $success ==
$count;
458 $callback =
function (\stdClass $row) {
459 return (
int) $row->id;
462 $ids = $this->db->getData(
$qb, $callback);
469 if (is_array($ids) &&
count($ids) === 1) {
470 return array_shift($ids);
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)
{}
const ELGG_VALUE_INTEGER
Value types.
Database abstraction query builder.
trait TimeUsing
Adds methods for setting the current time (for testing)
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.
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
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.