aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-19 21:16:49 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-11-19 21:16:49 +0000
commitbab90941c9faea31651bb8b562ddec6b5a82292c (patch)
treeeaeb02df929678fa1192ad4a22e14c5f733c7ab6
parentf8b8e83d2210d3d6601e61b291df38a078a95093 (diff)
downloadelgg-bab90941c9faea31651bb8b562ddec6b5a82292c.tar.gz
elgg-bab90941c9faea31651bb8b562ddec6b5a82292c.tar.bz2
Fixes #568: Exportable code now inclusive not exclusive.
* Added extra function Exportable interface * OpenDD export modified * PHP & JSON export views modified * Default export view will still show all data if you are logged in as admin (since this view is used by the guidtool) git-svn-id: https://code.elgg.org/elgg/trunk@2467 36083f99-b078-4883-b0ff-0f9b5a30f544
-rw-r--r--engine/lib/entities.php107
-rw-r--r--engine/lib/export.php8
-rw-r--r--engine/lib/extender.php18
-rw-r--r--engine/lib/group.php13
-rw-r--r--engine/lib/objects.php14
-rw-r--r--engine/lib/relationships.php13
-rw-r--r--engine/lib/sites.php14
-rw-r--r--engine/lib/users.php15
-rw-r--r--views/default/export/entity.php3
-rw-r--r--views/json/export/entity.php5
-rw-r--r--views/json/export/metadata.php5
-rw-r--r--views/json/export/relationship.php6
-rw-r--r--views/php/export/entity.php9
-rw-r--r--views/php/export/metadata.php9
-rw-r--r--views/php/export/relationship.php9
15 files changed, 184 insertions, 64 deletions
diff --git a/engine/lib/entities.php b/engine/lib/entities.php
index cd867193d..91314a882 100644
--- a/engine/lib/entities.php
+++ b/engine/lib/entities.php
@@ -709,14 +709,27 @@
$res = delete_entity($this->get('guid'));
return $res;
}
-
+
// EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
/**
- * Export this class into a stdClass containing all necessary fields.
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array(
+ 'guid',
+ 'type',
+ 'subtype',
+ 'time_created',
+ 'container_guid',
+ 'owner_guid',
+ );
+ }
+
+ /**
+ * Export this class into an array of ODD Elements containing all necessary fields.
* Override if you wish to return more information than can be found in $this->attributes (shouldn't happen)
- *
- * @return stdClass
*/
public function export()
{
@@ -734,61 +747,53 @@
$tmp[] = $odd;
+ $exportable_values = $this->getExportableValues();
+
// Now add its attributes
foreach ($this->attributes as $k => $v)
{
$meta = NULL;
- switch ($k)
- {
- case 'guid' : // Dont use guid
- case 'subtype' : // The subtype
- case 'type' : // Don't use type
- case 'access_id' : // Don't use access - if can export then its public for you, then importer decides what access to give this object.
- case 'time_updated' : // Don't use date in export
-
- case 'tables_split' : // We don't want to export the internal counter variables.
- case 'tables_loaded' : // Or this one
+ if (in_array( $k, $exportable_values)) {
+ switch ($k)
+ {
+ case 'guid' : // Dont use guid in OpenDD
+ case 'type' : // Type and subtype already taken care of
+ case 'subtype' :
+ break;
- case 'code' :
- case 'enabled' : // Useless to an importer
+ case 'time_created' : // Created = published
+ $odd->setAttribute('published', date("r", $v));
+ break;
- case 'email' :
- case 'salt' :
- case 'password' : // Definitely don't want these three
- break;
-
- case 'time_created' : // Created = published
- $odd->setAttribute('published', date("r", $v));
- break;
-
- case 'site_guid' : // Container
- $k = 'site_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
-
- case 'container_guid' : // Container
- $k = 'container_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
-
- case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata
- $k = 'owner_uuid';
- $v = guid_to_uuid($v);
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- break;
+ case 'site_guid' : // Container
+ $k = 'site_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'container_guid' : // Container
+ $k = 'container_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ case 'owner_guid' : // Convert owner guid to uuid, this will be stored in metadata
+ $k = 'owner_uuid';
+ $v = guid_to_uuid($v);
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ break;
+
+ default :
+ $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
+ }
- default :
- $meta = new ODDMetaData($uuid . "attr/$k/", $uuid, $k, $v);
- }
-
- // set the time of any metadata created
- if ($meta)
- {
- $meta->setAttribute('published', date("r",$this->time_created));
- $tmp[] = $meta;
+ // set the time of any metadata created
+ if ($meta)
+ {
+ $meta->setAttribute('published', date("r",$this->time_created));
+ $tmp[] = $meta;
+ }
}
}
diff --git a/engine/lib/export.php b/engine/lib/export.php
index e819264f6..6e37d3b45 100644
--- a/engine/lib/export.php
+++ b/engine/lib/export.php
@@ -20,11 +20,17 @@
interface Exportable
{
/**
- * This must take the contents of the object and convert it to exportable class(es).
+ * This must take the contents of the object and convert it to exportable ODD
* @return object or array of objects.
*/
public function export();
+ /**
+ * Return a list of all fields that can be exported.
+ * This should be used as the basis for the values returned by export()
+ */
+ public function getExportableValues();
+
}
/**
diff --git a/engine/lib/extender.php b/engine/lib/extender.php
index 206d98be4..b7c354c99 100644
--- a/engine/lib/extender.php
+++ b/engine/lib/extender.php
@@ -123,6 +123,22 @@
// EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
/**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array(
+ 'id',
+ 'entity_guid',
+ 'name',
+ 'value',
+ 'value_type',
+ 'owner_guid',
+ 'type',
+ );
+ }
+
+ /**
* Export this object
*
* @return array
@@ -131,7 +147,7 @@
{
$uuid = get_uuid_from_object($this);
- $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $type, guid_to_uuid($this->owner_guid));
+ $meta = new ODDMetadata($uuid, guid_to_uuid($this->entity_guid), $this->attributes['name'], $this->attributes['value'], $this->attributes['type'], guid_to_uuid($this->owner_guid));
$meta->setAttribute('published', date("r", $this->time_created));
return $meta;
diff --git a/engine/lib/group.php b/engine/lib/group.php
index 0a218b6f1..31c0460b6 100644
--- a/engine/lib/group.php
+++ b/engine/lib/group.php
@@ -311,6 +311,19 @@
// Now save specific stuff
return create_group_entity($this->get('guid'), $this->get('name'), $this->get('description'));
}
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'description',
+ ));
+ }
}
/**
diff --git a/engine/lib/objects.php b/engine/lib/objects.php
index 0bbcf1bb9..b9643bc87 100644
--- a/engine/lib/objects.php
+++ b/engine/lib/objects.php
@@ -202,7 +202,19 @@
* @return unknown
*/
//public function getCollections($subtype="", $limit = 10, $offset = 0) { get_object_collections($this->getGUID(), $subtype, $limit, $offset); }
-
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array_merge(parent::getExportableValues(), array(
+ 'title',
+ 'description',
+ ));
+ }
}
/**
diff --git a/engine/lib/relationships.php b/engine/lib/relationships.php
index 61234695d..c98ce3a9a 100644
--- a/engine/lib/relationships.php
+++ b/engine/lib/relationships.php
@@ -121,6 +121,19 @@
// EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
/**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array(
+ 'id',
+ 'guid_one',
+ 'relationship',
+ 'guid_two'
+ );
+ }
+
+ /**
* Export this relationship
*
* @return array
diff --git a/engine/lib/sites.php b/engine/lib/sites.php
index f7d3407ae..4c8a57ec4 100644
--- a/engine/lib/sites.php
+++ b/engine/lib/sites.php
@@ -215,6 +215,20 @@
*/
public function getCollections($subtype="", $limit = 10, $offset = 0) { get_site_collections($this->getGUID(), $subtype, $limit, $offset); }
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'description',
+ 'url',
+ ));
+ }
+
}
/**
diff --git a/engine/lib/users.php b/engine/lib/users.php
index d32dc5c0a..ee47bf078 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -296,7 +296,20 @@
return $this->owner_guid;
}
-
+
+ // EXPORTABLE INTERFACE ////////////////////////////////////////////////////////////
+
+ /**
+ * Return an array of fields which can be exported.
+ */
+ public function getExportableValues()
+ {
+ return array_merge(parent::getExportableValues(), array(
+ 'name',
+ 'username',
+ 'language',
+ ));
+ }
}
/**
diff --git a/views/default/export/entity.php b/views/default/export/entity.php
index 38d2d0902..0e6e26025 100644
--- a/views/default/export/entity.php
+++ b/views/default/export/entity.php
@@ -18,16 +18,19 @@
$annotations = get_annotations($entity->guid);
$relationships = get_entity_relationships($entity->guid);
+ $exportable_values = $entity->getExportableValues();
?>
<div>
<?php
foreach ($entity as $k => $v)
{
+ if ((in_array($k, $exportable_values)) || (isadminloggedin())) {
?>
<div>
<p><b><?php echo $k; ?>: </b><?php echo $v; ?></p>
</div>
<?php
+ }
}
?>
</div>
diff --git a/views/json/export/entity.php b/views/json/export/entity.php
index 83524cbd8..700784ca3 100644
--- a/views/json/export/entity.php
+++ b/views/json/export/entity.php
@@ -14,9 +14,10 @@
$entity = $vars['entity'];
$export = new stdClass;
+ $exportable_values = $entity->getExportableValues();
- foreach ($entity as $k => $v)
- $export->$k = $v;
+ foreach ($exportable_values as $v)
+ $export->$v = $entity->$v;
echo json_encode($export);
?> \ No newline at end of file
diff --git a/views/json/export/metadata.php b/views/json/export/metadata.php
index 0495e37b2..e56a0a7a1 100644
--- a/views/json/export/metadata.php
+++ b/views/json/export/metadata.php
@@ -14,9 +14,10 @@
$m = $vars['metadata'];
$export = new stdClass;
+ $exportable_values = $entity->getExportableValues();
- foreach ($m as $k => $v)
- $export->$k = $v;
+ foreach ($exportable_values as $v)
+ $export->$v = $m->$v;
echo json_encode($export);
?> \ No newline at end of file
diff --git a/views/json/export/relationship.php b/views/json/export/relationship.php
index 22acbba92..004ce9864 100644
--- a/views/json/export/relationship.php
+++ b/views/json/export/relationship.php
@@ -14,9 +14,11 @@
$r = $vars['relationship'];
$export = new stdClass;
+
+ $exportable_values = $entity->getExportableValues();
- foreach ($r as $k => $v)
- $export->$k = $v;
+ foreach ($exportable_values as $v)
+ $export->$v = $r->$v;
echo json_encode($export);
?> \ No newline at end of file
diff --git a/views/php/export/entity.php b/views/php/export/entity.php
index fbde3ef0d..d167a1df3 100644
--- a/views/php/export/entity.php
+++ b/views/php/export/entity.php
@@ -12,5 +12,12 @@
*/
$entity = $vars['entity'];
- echo serialize($entity);
+
+ $export = new stdClass;
+ $exportable_values = $entity->getExportableValues();
+
+ foreach ($exportable_values as $v)
+ $export->$v = $entity->$v;
+
+ echo serialize($export);
?> \ No newline at end of file
diff --git a/views/php/export/metadata.php b/views/php/export/metadata.php
index 1af6f065d..d7939bb82 100644
--- a/views/php/export/metadata.php
+++ b/views/php/export/metadata.php
@@ -12,5 +12,12 @@
*/
$m = $vars['metadata'];
- echo serialize($m);
+
+ $export = new stdClass;
+ $exportable_values = $m->getExportableValues();
+
+ foreach ($exportable_values as $v)
+ $export->$v = $m->$v;
+
+ echo serialize($export);
?> \ No newline at end of file
diff --git a/views/php/export/relationship.php b/views/php/export/relationship.php
index e66719f7c..58456c51c 100644
--- a/views/php/export/relationship.php
+++ b/views/php/export/relationship.php
@@ -12,5 +12,12 @@
*/
$r = $vars['relationship'];
- echo serialize($r);
+
+ $export = new stdClass;
+ $exportable_values = $r->getExportableValues();
+
+ foreach ($exportable_values as $v)
+ $export->$v = $r->$v;
+
+ echo serialize($export);
?> \ No newline at end of file