79 $singulars = [
'tag_name'];
92 return "{$main_alias}.value AS tag";
95 return "COUNT({$main_alias}.id) AS total";
112 return "{$main_alias}.value";
129 $options[
'callback'] =
function($row) {
132 $result->total = (int) $row->total;
155 $qb->addClause($where);
157 $row = $this->db->getDataRow(
$qb);
158 return $row ? new \ElggMetadata($row) : null;
183 $this->metadata_cache->clear(
$metadata->entity_guid);
202 if (!isset($metadata->value) || !isset($metadata->entity_guid)) {
203 elgg_log(
'Metadata must have a value and entity guid',
'ERROR');
207 if (!$this->entityTable->exists($metadata->entity_guid)) {
208 elgg_log(
"Can't create metadata on a non-existing entity_guid",
'ERROR');
212 if (!is_scalar($metadata->value)) {
213 elgg_log(
'To set multiple metadata values use ElggEntity::setMetadata',
'ERROR');
218 if ($this->
update($metadata)) {
219 return $metadata->id;
223 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
224 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
227 if (!$allow_multiple) {
232 Multiple '{$metadata->name}' metadata values exist for entity [guid: {$metadata->entity_guid}]. 233 Use ElggEntity::setMetadata() 240 if ($this->
update($metadata)) {
241 return $metadata->id;
246 if (!$this->events->triggerBefore(
'create',
'metadata', $metadata)) {
261 $id = $this->db->insertData(
$qb);
267 $metadata->id = (int)
$id;
270 if (!$this->events->trigger(
'create',
'metadata', $metadata)) {
276 $this->metadata_cache->clear($metadata->entity_guid);
278 $this->events->triggerAfter(
'create',
'metadata', $metadata);
291 if (!$this->entityTable->exists($metadata->entity_guid)) {
292 elgg_log(
"Can't update metadata to a non-existing entity_guid",
'ERROR');
296 if (!$this->events->triggerBefore(
'update',
'metadata', $metadata)) {
300 if (
strlen($metadata->value) > self::MYSQL_TEXT_BYTE_LIMIT) {
301 elgg_log(
"Metadata '{$metadata->name}' is above the MySQL TEXT size limit and may be truncated.",
'WARNING');
307 ->
set(
'value_type',
$qb->param($metadata->value_type, ELGG_VALUE_STRING))
316 $this->metadata_cache->clear($metadata->entity_guid);
318 $this->events->trigger(
'update',
'metadata', $metadata);
319 $this->events->triggerAfter(
'update',
'metadata', $metadata);
336 $options[
'metastring_type'] =
'metadata';
357 ->orderBy(
'entity_guid',
'asc')
358 ->addOrderBy(
'time_created',
'asc')
359 ->addOrderBy(
'id',
'asc');
361 return $this->db->getData(
$qb,
function ($row) {
362 return new \ElggMetadata($row);
384 'metadata_name',
'metadata_names',
385 'metadata_value',
'metadata_values',
391 if (isset($options[$key]) && !
elgg_is_empty($options[$key])) {
404 $this->metadata_cache->invalidateByOptions($options);
406 $options[
'batch'] =
true;
407 $options[
'batch_size'] = 50;
408 $options[
'batch_inc_offset'] =
false;
425 return $success ===
$count;
437 if ($this->metadata_cache->isLoaded($entity_guid)) {
438 $ids = $this->metadata_cache->getSingleId($entity_guid, $name);
445 $callback =
function (\stdClass $row) {
446 return (
int) $row->id;
449 $ids = $this->db->getData(
$qb, $callback);
456 if (is_array($ids) &&
count($ids) === 1) {
457 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
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.
_elgg_services()
Get the global service provider.
$id
Generic annotation delete action.
Entity table database service.