From 09fffebffe9ab1cf7622aa141150157b0746e20d Mon Sep 17 00:00:00 2001 From: cweiske Date: Sun, 25 Oct 2009 19:32:48 +0000 Subject: test if deleting bookmarks works. to do this, we need a new testbase method to create users, plus we need to return the uid when creating a new user. registration process needs to be adopted to that. git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@417 b3834d28-1941-0410-a4f8-b48e95affb8f --- src/SemanticScuttle/Service/Bookmark.php | 17 ++++++++------- src/SemanticScuttle/Service/User.php | 37 ++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 15 deletions(-) (limited to 'src/SemanticScuttle') diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php index 29a2291..82e23a3 100644 --- a/src/SemanticScuttle/Service/Bookmark.php +++ b/src/SemanticScuttle/Service/Bookmark.php @@ -212,9 +212,9 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService */ public function addBookmark( $address, $title, $description, $privateNote, $status, $categories, - $date = null, $fromApi = false, $fromImport = false, $sId = -1 + $date = null, $fromApi = false, $fromImport = false, $sId = null ) { - if ($sId == -1) { + if ($sId === null) { $userservice = SemanticScuttle_Service_Factory::get('User'); $sId = $userservice->getCurrentUserId(); } @@ -436,16 +436,17 @@ class SemanticScuttle_Service_Bookmark extends SemanticScuttle_DbService $terms = null, $sortOrder = null, $watched = null, $startdate = null, $enddate = null, $hash = null ) { - $userservice =SemanticScuttle_Service_Factory::get('User'); - $b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag'); - $tag2tagservice =SemanticScuttle_Service_Factory::get('Tag2Tag'); - $sId = $userservice->getCurrentUserId(); + $userservice = SemanticScuttle_Service_Factory::get('User'); + $b2tservice = SemanticScuttle_Service_Factory::get('Bookmark2Tag'); + $tag2tagservice = SemanticScuttle_Service_Factory::get('Tag2Tag'); + $sId = $userservice->getCurrentUserId(); if ($userservice->isLoggedOn()) { - // All public bookmarks, user's own bookmarks and any shared with user + // All public bookmarks, user's own bookmarks + // and any shared with user $privacy = ' AND ((B.bStatus = 0) OR (B.uId = '. $sId .')'; $watchnames = $userservice->getWatchNames($sId, true); - foreach($watchnames as $watchuser) { + foreach ($watchnames as $watchuser) { $privacy .= ' OR (U.username = "'. $watchuser .'" AND B.bStatus = 1)'; } $privacy .= ')'; diff --git a/src/SemanticScuttle/Service/User.php b/src/SemanticScuttle/Service/User.php index bf44c4b..035c9e2 100644 --- a/src/SemanticScuttle/Service/User.php +++ b/src/SemanticScuttle/Service/User.php @@ -400,24 +400,47 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService return true; } - function addUser($username, $password, $email) { + /** + * Create a new user in database. + * No checks are done in here - you ought to have checked + * everything before calling this method! + * + * @param string $username Username to use + * @param string $password Password to use + * @param string $email Email to use + * + * @return mixed Integer user ID if all is well, + * boolean false if an error occured + */ + public function addUser($username, $password, $email) + { // Set up the SQL UPDATE statement. $datetime = gmdate('Y-m-d H:i:s', time()); $password = $this->sanitisePassword($password); - $values = array('username' => $username, 'password' => $password, 'email' => $email, 'uDatetime' => $datetime, 'uModified' => $datetime); - $sql = 'INSERT INTO '. $this->getTableName() .' '. $this->db->sql_build_array('INSERT', $values); + $values = array( + 'username' => $username, + 'password' => $password, + 'email' => $email, + 'uDatetime' => $datetime, + 'uModified' => $datetime + ); + $sql = 'INSERT INTO '. $this->getTableName() + . ' '. $this->db->sql_build_array('INSERT', $values); // Execute the statement. $this->db->sql_transaction('begin'); if (!($dbresult = & $this->db->sql_query($sql))) { $this->db->sql_transaction('rollback'); - message_die(GENERAL_ERROR, 'Could not insert user', '', __LINE__, __FILE__, $sql, $this->db); + message_die( + GENERAL_ERROR, 'Could not insert user', + '', __LINE__, __FILE__, $sql, $this->db + ); return false; } + $uId = $this->db->sql_nextid($dbresult); $this->db->sql_transaction('commit'); - // Everything worked out, so return true. - return true; + return $uId; } function updateUser($uId, $password, $name, $email, $homepage, $uContent) { @@ -564,7 +587,7 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService * * @see updateSessionStability() */ - publi function isSessionStable() + public function isSessionStable() { return $_SESSION['sessionStable'] == 1; } -- cgit v1.2.3