aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/metadata.php
diff options
context:
space:
mode:
authoricewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-20 15:49:23 +0000
committericewing <icewing@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-03-20 15:49:23 +0000
commit226da79d7763a17d4a2bcd4d9b699e14c9103b9c (patch)
tree77695bdf9ab5cbf56b51c9d1ede5ff89f1581e3b /engine/lib/metadata.php
parentf00c9393e830c156cdff7322eab3b26eb3dcbe1a (diff)
downloadelgg-226da79d7763a17d4a2bcd4d9b699e14c9103b9c.tar.gz
elgg-226da79d7763a17d4a2bcd4d9b699e14c9103b9c.tar.bz2
Marcus Povey <marcus@dushka.co.uk>
* Metadata now using metastrings * Entities will now throw an exception when creation is attempted with no owner git-svn-id: https://code.elgg.org/elgg/trunk@260 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/metadata.php')
-rw-r--r--engine/lib/metadata.php24
1 files changed, 15 insertions, 9 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php
index 1111fb551..4d29bb7bc 100644
--- a/engine/lib/metadata.php
+++ b/engine/lib/metadata.php
@@ -156,7 +156,7 @@
$id = (int)$id;
$access = get_access_list();
- return row_to_elggmetadata(get_data_row("SELECT m.*, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id where m.id=$id and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))"));
+ return row_to_elggmetadata(get_data_row("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.id=$id and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))"));
}
/**
@@ -186,7 +186,7 @@
$id = false;
- $existing = get_data_row("SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = $entity_guid and name='$name' limit 1");
+ $existing = get_data_row("SELECT * from {$CONFIG->dbprefix}metadata WHERE entity_guid = $entity_guid and name_id=" . add_metastring($name) . " limit 1");
if ($existing)
{
$id = $existing->id;
@@ -196,12 +196,15 @@
}
else
{
- // Add the metastring
+ // Add the metastrings
$value = add_metastring($value);
if (!$value) return false;
+ $name = add_metastring($name);
+ if (!$name) return false;
+
// If ok then add it
- $id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (entity_guid, name, value_id, value_type, owner_guid, time_created, access_id) VALUES ($entity_guid, '$name','$value','$value_type', $owner_guid, $time, $access_id)");
+ $id = insert_data("INSERT into {$CONFIG->dbprefix}metadata (entity_guid, name_id, value_id, value_type, owner_guid, time_created, access_id) VALUES ($entity_guid, '$name','$value','$value_type', $owner_guid, $time, $access_id)");
}
return $id;
@@ -238,8 +241,11 @@
$value = add_metastring($value);
if (!$value) return false;
+ $name = add_metastring($name);
+ if (!$name) return false;
+
// If ok then add it
- return update_data("UPDATE {$CONFIG->dbprefix}metadata set value_id='$value', value_type='$value_type', access_id=$access_id, owner_guid=$owner_guid where id=$id and name='$name' and (access_id in {$access} or (access_id = 0 and owner_guid = {$_SESSION['id']}))");
+ return update_data("UPDATE {$CONFIG->dbprefix}metadata set value_id='$value', value_type='$value_type', access_id=$access_id, owner_guid=$owner_guid where id=$id and name_id='$name' and (access_id in {$access} or (access_id = 0 and owner_guid = {$_SESSION['id']}))");
}
@@ -268,11 +274,11 @@
{
global $CONFIG;
- $meta_name = sanitise_string($meta_name);
+ $meta_name = get_metastring_id($meta_name);
$entity_guid = (int)$entity_guid;
$access = get_access_list();
- return row_to_elggmetadata(get_data_row("SELECT m.*, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id where m.entity_guid=$entity_guid and m.name='$meta_name' and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))"));
+ return row_to_elggmetadata(get_data_row("SELECT m.*, n.string as name, v.string as value from {$CONFIG->dbprefix}metadata m JOIN {$CONFIG->dbprefix}metastrings v on m.value_id = v.id JOIN {$CONFIG->dbprefix}metastrings n on m.name_id = n.id where m.entity_guid=$entity_guid and m.name_id='$meta_name' and (m.access_id in {$access} or (m.access_id = 0 and m.owner_guid = {$_SESSION['id']}))"));
}
/**
@@ -290,7 +296,7 @@
{
global $CONFIG;
- $meta_name = sanitise_string($meta_name);
+ $meta_name = get_metastring_id($meta_name);
$meta_value = get_metastring_id($meta_value);
$entity_type = sanitise_string($entity_type);
@@ -308,7 +314,7 @@
if ($entity_subtype)
$where[] = "e.subtype=$entity_subtype";
if ($meta_name!="")
- $where[] = "m.name='$meta_name'";
+ $where[] = "m.name_id='$meta_name'";
if ($meta_value!="")
$where[] = "m.value_id='$meta_value'";