From e2ecf4fc6a89f1ef5a0badb020d2a7a25c03ed03 Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Wed, 20 Feb 2013 22:07:24 -0500 Subject: [PATCH] Fixes #4986, #4984 deprecates create_*_entity functions --- engine/lib/deprecated-1.9.php | 248 ++++++++++++++++++++++++++++++++++ engine/lib/group.php | 31 ----- engine/lib/objects.php | 54 -------- engine/lib/sites.php | 61 --------- engine/lib/users.php | 41 ------ 5 files changed, 248 insertions(+), 187 deletions(-) diff --git a/engine/lib/deprecated-1.9.php b/engine/lib/deprecated-1.9.php index a00fcee9a2d..ac17c26b562 100644 --- a/engine/lib/deprecated-1.9.php +++ b/engine/lib/deprecated-1.9.php @@ -956,3 +956,251 @@ function unregister_service_handler($handler) { return elgg_ws_unregister_service_handler($handler); } } + +/** + * Create or update the entities table for a given site. + * Call create_entity first. + * + * @param int $guid Site GUID + * @param string $name Site name + * @param string $description Site Description + * @param string $url URL of the site + * + * @return bool + * @access private + * @deprecated 1.9 Use ElggSite constructor + */ +function create_site_entity($guid, $name, $description, $url) { + elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use ElggSite constructor', 1.9); + global $CONFIG; + + $guid = (int)$guid; + $name = sanitise_string($name); + $description = sanitise_string($description); + $url = sanitise_string($url); + + $row = get_entity_as_row($guid); + + if ($row) { + // Exists and you have access to it + $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}"; + if ($exists = get_data_row($query)) { + $query = "UPDATE {$CONFIG->dbprefix}sites_entity + set name='$name', description='$description', url='$url' where guid=$guid"; + $result = update_data($query); + + if ($result != false) { + // Update succeeded, continue + $entity = get_entity($guid); + if (elgg_trigger_event('update', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + //delete_entity($guid); + } + } + } else { + // Update failed, attempt an insert. + $query = "INSERT into {$CONFIG->dbprefix}sites_entity + (guid, name, description, url) values ($guid, '$name', '$description', '$url')"; + $result = insert_data($query); + + if ($result !== false) { + $entity = get_entity($guid); + if (elgg_trigger_event('create', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + //delete_entity($guid); + } + } + } + } + + return false; +} + +/** + * Create or update the entities table for a given group. + * Call create_entity first. + * + * @param int $guid GUID + * @param string $name Name + * @param string $description Description + * + * @return bool + * @access private + * @deprecated 1.9 Use ElggGroup constructor + */ +function create_group_entity($guid, $name, $description) { + elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use ElggGroup constructor', 1.9); + global $CONFIG; + + $guid = (int)$guid; + $name = sanitise_string($name); + $description = sanitise_string($description); + + $row = get_entity_as_row($guid); + + if ($row) { + // Exists and you have access to it + $exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}"); + if ($exists) { + $query = "UPDATE {$CONFIG->dbprefix}groups_entity set" + . " name='$name', description='$description' where guid=$guid"; + $result = update_data($query); + if ($result != false) { + // Update succeeded, continue + $entity = get_entity($guid); + if (elgg_trigger_event('update', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + } + } + } else { + // Update failed, attempt an insert. + $query = "INSERT into {$CONFIG->dbprefix}groups_entity" + . " (guid, name, description) values ($guid, '$name', '$description')"; + + $result = insert_data($query); + if ($result !== false) { + $entity = get_entity($guid); + if (elgg_trigger_event('create', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + } + } + } + } + + return false; +} + +/** + * Create or update the entities table for a given user. + * Call create_entity first. + * + * @param int $guid The user's GUID + * @param string $name The user's display name + * @param string $username The username + * @param string $password The password + * @param string $salt A salt for the password + * @param string $email The user's email address + * @param string $language The user's default language + * @param string $code A code + * + * @return bool + * @access private + * @deprecated 1.9 Use ElggUser constructor + */ +function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code) { + elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use ElggUser constructor', 1.9); + global $CONFIG; + + $guid = (int)$guid; + $name = sanitise_string($name); + $username = sanitise_string($username); + $password = sanitise_string($password); + $salt = sanitise_string($salt); + $email = sanitise_string($email); + $language = sanitise_string($language); + $code = sanitise_string($code); + + $row = get_entity_as_row($guid); + if ($row) { + // Exists and you have access to it + $query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}"; + if ($exists = get_data_row($query)) { + $query = "UPDATE {$CONFIG->dbprefix}users_entity + SET name='$name', username='$username', password='$password', salt='$salt', + email='$email', language='$language', code='$code' + WHERE guid = $guid"; + + $result = update_data($query); + if ($result != false) { + // Update succeeded, continue + $entity = get_entity($guid); + if (elgg_trigger_event('update', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + } + } + } else { + // Exists query failed, attempt an insert. + $query = "INSERT into {$CONFIG->dbprefix}users_entity + (guid, name, username, password, salt, email, language, code) + values ($guid, '$name', '$username', '$password', '$salt', '$email', '$language', '$code')"; + + $result = insert_data($query); + if ($result !== false) { + $entity = get_entity($guid); + if (elgg_trigger_event('create', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + } + } + } + } + + return false; +} + +/** + * Create or update the extras table for a given object. + * Call create_entity first. + * + * @param int $guid The guid of the entity you're creating (as obtained by create_entity) + * @param string $title The title of the object + * @param string $description The object's description + * + * @return bool + * @access private + * @deprecated 1.9 Use ElggObject constructor + */ +function create_object_entity($guid, $title, $description) { + elgg_deprecated_notice(__FUNCTION__ . ' is deprecated. Use ElggObject constructor', 1.9); + global $CONFIG; + + $guid = (int)$guid; + $title = sanitise_string($title); + $description = sanitise_string($description); + + $row = get_entity_as_row($guid); + + if ($row) { + // Core entities row exists and we have access to it + $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}"; + if ($exists = get_data_row($query)) { + $query = "UPDATE {$CONFIG->dbprefix}objects_entity + set title='$title', description='$description' where guid=$guid"; + + $result = update_data($query); + if ($result != false) { + // Update succeeded, continue + $entity = get_entity($guid); + elgg_trigger_event('update', $entity->type, $entity); + return $guid; + } + } else { + // Update failed, attempt an insert. + $query = "INSERT into {$CONFIG->dbprefix}objects_entity + (guid, title, description) values ($guid, '$title','$description')"; + + $result = insert_data($query); + if ($result !== false) { + $entity = get_entity($guid); + if (elgg_trigger_event('create', $entity->type, $entity)) { + return $guid; + } else { + $entity->delete(); + } + } + } + } + + return false; +} diff --git a/engine/lib/group.php b/engine/lib/group.php index 7068c83e91f..d6436e33e64 100644 --- a/engine/lib/group.php +++ b/engine/lib/group.php @@ -24,37 +24,6 @@ function get_group_entity_as_row($guid) { return get_data_row("SELECT * from {$CONFIG->dbprefix}groups_entity where guid=$guid"); } -/** - * Create or update the entities table for a given group. - * Call create_entity first. - * - * @param int $guid GUID - * @param string $name Name - * @param string $description Description - * - * @return bool - * @access private - */ -function create_group_entity($guid, $name, $description) { - global $CONFIG; - - $guid = (int)$guid; - $name = sanitise_string($name); - $description = sanitise_string($description); - - $row = get_entity_as_row($guid); - - if ($row) { - // Exists and you have access to it - $exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}groups_entity WHERE guid = {$guid}"); - if ($exists) { - } else { - } - } - - return false; -} - /** * Add an object to the given group. * diff --git a/engine/lib/objects.php b/engine/lib/objects.php index 3b11b5d0c01..580c8d0e2a0 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -22,60 +22,6 @@ function get_object_entity_as_row($guid) { return get_data_row("SELECT * from {$CONFIG->dbprefix}objects_entity where guid=$guid"); } -/** - * Create or update the extras table for a given object. - * Call create_entity first. - * - * @param int $guid The guid of the entity you're creating (as obtained by create_entity) - * @param string $title The title of the object - * @param string $description The object's description - * - * @return bool - * @access private - */ -function create_object_entity($guid, $title, $description) { - global $CONFIG; - - $guid = (int)$guid; - $title = sanitise_string($title); - $description = sanitise_string($description); - - $row = get_entity_as_row($guid); - - if ($row) { - // Core entities row exists and we have access to it - $query = "SELECT guid from {$CONFIG->dbprefix}objects_entity where guid = {$guid}"; - if ($exists = get_data_row($query)) { - $query = "UPDATE {$CONFIG->dbprefix}objects_entity - set title='$title', description='$description' where guid=$guid"; - - $result = update_data($query); - if ($result != false) { - // Update succeeded, continue - $entity = get_entity($guid); - elgg_trigger_event('update', $entity->type, $entity); - return $guid; - } - } else { - // Update failed, attempt an insert. - $query = "INSERT into {$CONFIG->dbprefix}objects_entity - (guid, title, description) values ($guid, '$title','$description')"; - - $result = insert_data($query); - if ($result !== false) { - $entity = get_entity($guid); - if (elgg_trigger_event('create', $entity->type, $entity)) { - return $guid; - } else { - $entity->delete(); - } - } - } - } - - return false; -} - /** * Get the sites this object is part of * diff --git a/engine/lib/sites.php b/engine/lib/sites.php index 9603e88f457..b2e94074aac 100644 --- a/engine/lib/sites.php +++ b/engine/lib/sites.php @@ -48,67 +48,6 @@ function get_site_entity_as_row($guid) { return get_data_row("SELECT * from {$CONFIG->dbprefix}sites_entity where guid=$guid"); } -/** - * Create or update the entities table for a given site. - * Call create_entity first. - * - * @param int $guid Site GUID - * @param string $name Site name - * @param string $description Site Description - * @param string $url URL of the site - * - * @return bool - * @access private - */ -function create_site_entity($guid, $name, $description, $url) { - global $CONFIG; - - $guid = (int)$guid; - $name = sanitise_string($name); - $description = sanitise_string($description); - $url = sanitise_string($url); - - $row = get_entity_as_row($guid); - - if ($row) { - // Exists and you have access to it - $query = "SELECT guid from {$CONFIG->dbprefix}sites_entity where guid = {$guid}"; - if ($exists = get_data_row($query)) { - $query = "UPDATE {$CONFIG->dbprefix}sites_entity - set name='$name', description='$description', url='$url' where guid=$guid"; - $result = update_data($query); - - if ($result != false) { - // Update succeeded, continue - $entity = get_entity($guid); - if (elgg_trigger_event('update', $entity->type, $entity)) { - return $guid; - } else { - $entity->delete(); - //delete_entity($guid); - } - } - } else { - // Update failed, attempt an insert. - $query = "INSERT into {$CONFIG->dbprefix}sites_entity - (guid, name, description, url) values ($guid, '$name', '$description', '$url')"; - $result = insert_data($query); - - if ($result !== false) { - $entity = get_entity($guid); - if (elgg_trigger_event('create', $entity->type, $entity)) { - return $guid; - } else { - $entity->delete(); - //delete_entity($guid); - } - } - } - } - - return false; -} - /** * Add a user to a site. * diff --git a/engine/lib/users.php b/engine/lib/users.php index f1b7d6d7ac8..34ac6b6d30f 100644 --- a/engine/lib/users.php +++ b/engine/lib/users.php @@ -30,47 +30,6 @@ function get_user_entity_as_row($guid) { return get_data_row("SELECT * from {$CONFIG->dbprefix}users_entity where guid=$guid"); } -/** - * Create or update the entities table for a given user. - * Call create_entity first. - * - * @param int $guid The user's GUID - * @param string $name The user's display name - * @param string $username The username - * @param string $password The password - * @param string $salt A salt for the password - * @param string $email The user's email address - * @param string $language The user's default language - * @param string $code A code - * - * @return bool - * @access private - */ -function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code) { - global $CONFIG; - - $guid = (int)$guid; - $name = sanitise_string($name); - $username = sanitise_string($username); - $password = sanitise_string($password); - $salt = sanitise_string($salt); - $email = sanitise_string($email); - $language = sanitise_string($language); - $code = sanitise_string($code); - - $row = get_entity_as_row($guid); - if ($row) { - // Exists and you have access to it - $query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}"; - if ($exists = get_data_row($query)) { - } else { - // Exists query failed, attempt an insert. - } - } - - return false; -} - /** * Disables all of a user's entities *