public function addQuerySpecs(stdClass $row)
{
$this->clearQuerySpecs($row);
// Return this metadata object when _elgg_get_metastring_based_objects() is called
$e_access_sql = _elgg_get_access_where_sql(array('table_alias' => 'e'));
$md_access_sql = _elgg_get_access_where_sql(array('table_alias' => 'n_table', 'guid_column' => 'entity_guid'));
$dbprefix = elgg_get_config('dbprefix');
$sql = "SELECT DISTINCT n_table.*\n\t\t\tFROM {$dbprefix}metadata n_table\n\t\t\t\tJOIN {$dbprefix}entities e ON n_table.entity_guid = e.guid\n\t\t\t\tWHERE (n_table.id IN ({$row->id}) AND {$md_access_sql}) AND {$e_access_sql}\n\t\t\t\tORDER BY n_table.time_created ASC, n_table.id ASC, n_table.id";
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'results' => function () use($row) {
if (isset($this->rows[$row->id])) {
return [$this->rows[$row->id]];
}
return [];
}]);
$sql = "INSERT INTO {$dbprefix}metadata\n\t\t\t\t(entity_guid, name, value, value_type, owner_guid, time_created, access_id)\n\t\t\t\tVALUES (:entity_guid, :name, :value, :value_type, :owner_guid, :time_created, :access_id)";
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':entity_guid' => $row->entity_guid, ':name' => $row->name, ':value' => $row->value, ':value_type' => $row->value_type, ':owner_guid' => $row->owner_guid, ':time_created' => $row->time_created, ':access_id' => $row->access_id], 'insert_id' => $row->id]);
$sql = "UPDATE {$dbprefix}metadata\n\t\t\tSET name = :name,\n\t\t\t value = :value,\n\t\t\t\tvalue_type = :value_type,\n\t\t\t\taccess_id = :access_id,\n\t\t\t owner_guid = :owner_guid\n\t\t\tWHERE id = :id";
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':name' => $row->name, ':value' => $row->value, ':value_type' => $row->value_type, ':owner_guid' => $row->owner_guid, ':access_id' => $row->access_id, ':id' => $row->id], 'results' => function () use($row) {
if (isset($this->rows[$row->id])) {
return [$row->id];
}
return [];
}]);
// Enable/disable metadata
$sql = "UPDATE {$dbprefix}metadata SET enabled = :enabled where id = :id";
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':id' => $row->id, ':enabled' => 'yes'], 'results' => function () use($row) {
if (isset($this->rows[$row->id])) {
$this->rows[$row->id]->enabled = 'yes';
return [$row->id];
}
return [];
}]);
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':id' => $row->id, ':enabled' => 'no'], 'results' => function () use($row) {
if (isset($this->rows[$row->id])) {
$this->rows[$row->id]->enabled = 'no';
return [$row->id];
}
return [];
}]);
// Delete
$sql = "DELETE FROM {$dbprefix}metadata WHERE id = :id";
$this->query_specs[$row->id][] = $this->db->addQuerySpec(['sql' => $sql, 'params' => [':id' => $row->id], 'results' => function () use($row) {
if (isset($this->rows[$row->id])) {
unset($this->rows[$row->id]);
$this->clearQuerySpecs($row);
return [$row->id];
}
return [];
}]);
}