]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #2403 - adds unregister_entity_type()
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 14 Oct 2010 10:52:56 +0000 (10:52 +0000)
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>
Thu, 14 Oct 2010 10:52:56 +0000 (10:52 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@7077 36083f99-b078-4883-b0ff-0f9b5a30f544

engine/lib/entities.php

index 534b61e19effe577a22f377e895c8c287f2ff6ce..e788018e0bcb7e1a5ea76298e6e4730c3d55f88d 100644 (file)
@@ -2114,8 +2114,8 @@ function register_entity_type($type, $subtype) {
        global $CONFIG;
 
        $type = strtolower($type);
-       if (!in_array($type, array('object','site','group','user'))) {
-               return false;
+       if (!in_array($type, array('object', 'site', 'group', 'user'))) {
+               return FALSE;
        }
 
        if (!isset($CONFIG->registered_entities)) {
@@ -2130,7 +2130,48 @@ function register_entity_type($type, $subtype) {
                $CONFIG->registered_entities[$type][] = $subtype;
        }
 
-       return true;
+       return TRUE;
+}
+
+/**
+ * Unregisters an entity type and subtype as a public-facing entity.
+ *
+ * @warning With a blank subtype, it unregisters that entity type including
+ * all subtypes. This must be called after all subtypes have been registered.
+ *
+ * @param string $type The type of entity (object, site, user, group)
+ * @param string $subtype The subtype to register (may be blank)
+ * @return true|false Depending on success
+ * @see register_entity_type()
+ */
+function unregister_entity_type($type, $subtype) {
+       global $CONFIG;
+
+       $type = strtolower($type);
+       if (!in_array($type, array('object', 'site', 'group', 'user'))) {
+               return FALSE;
+       }
+
+       if (!isset($CONFIG->registered_entities)) {
+               return FALSE;
+       }
+
+       if (!isset($CONFIG->registered_entities[$type])) {
+               return FALSE;
+       }
+
+       if ($subtype) {
+               if (in_array($subtype, $CONFIG->registered_entities[$type])) {
+                       $key = array_search($subtype, $CONFIG->registered_entities[$type]);
+                       unset($CONFIG->registered_entities[$type][$key]);
+               } else {
+                       return FALSE;
+               }
+       } else {
+               unset($CONFIG->registered_entities[$type]);
+       }
+
+       return TRUE;
 }
 
 /**