From bab90941c9faea31651bb8b562ddec6b5a82292c Mon Sep 17 00:00:00 2001 From: marcus Date: Wed, 19 Nov 2008 21:16:49 +0000 Subject: 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 --- engine/lib/entities.php | 107 ++++++++++++++++++++++--------------------- engine/lib/export.php | 8 +++- engine/lib/extender.php | 18 +++++++- engine/lib/group.php | 13 ++++++ engine/lib/objects.php | 14 +++++- engine/lib/relationships.php | 13 ++++++ engine/lib/sites.php | 14 ++++++ engine/lib/users.php | 15 +++++- 8 files changed, 147 insertions(+), 55 deletions(-) (limited to 'engine') 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 @@ -122,6 +122,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 * @@ -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 @@ -120,6 +120,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 * 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', + )); + } } /** -- cgit v1.2.3