From 80b8ca3408965a08b5952a48d5c016a08ab91f11 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 11 Jul 2012 17:35:09 +0200 Subject: [PATCH] Fix #786 Update baskets transfer --- .../Session/Authentication/Guest.class.php | 1 + lib/classes/Session/Handler.class.php | 68 +++++-------------- tests/Session/Session_HandlerTest.php | 44 ------------ www/login/index.php | 2 +- 4 files changed, 20 insertions(+), 95 deletions(-) diff --git a/lib/classes/Session/Authentication/Guest.class.php b/lib/classes/Session/Authentication/Guest.class.php index 9993672289..a89b1734ad 100644 --- a/lib/classes/Session/Authentication/Guest.class.php +++ b/lib/classes/Session/Authentication/Guest.class.php @@ -88,6 +88,7 @@ class Session_Authentication_Guest implements Session_Authentication_Interface */ public function postlog() { + \Session_Handler::set_cookie('invite-usr_id', $this->user->get_id(), 0, true); return $this; } } diff --git a/lib/classes/Session/Handler.class.php b/lib/classes/Session/Handler.class.php index 3b1ed91c89..2b5d7680fb 100644 --- a/lib/classes/Session/Handler.class.php +++ b/lib/classes/Session/Handler.class.php @@ -186,22 +186,22 @@ class Session_Handler public function isset_postlog() { - return $this->storage()->has('postlog'); + return self::isset_cookie('postlog'); } - public function set_postlog($boolean) + public function set_postlog() { - return $this->storage()->set('postlog', $boolean); + return self::set_cookie('postlog', '1', 0, false); } public function get_postlog() { - return $this->storage()->get('postlog'); + return self::get_cookie('postlog', null); } public function delete_postlog() { - return $this->storage()->remove('postlog'); + return self::set_cookie('postlog', '', -5, false); } /** @@ -403,6 +403,7 @@ class Session_Handler } $this->set_usr_lastconn($conn, $user->get_id()); + $this->transfer_baskets($user); $this->delete_postlog(); $auth->postlog(); @@ -412,61 +413,28 @@ class Session_Handler return $this; } - protected function transfer_baskets() + protected function transfer_baskets(\User_Adapter $user) { - $conn = $this->appbox->get_connection(); - $transferBasks = ($this->isset_postlog() && $this->get_postlog() === true); + $Core = \bootstrap::getCore(); + + $transferBasks = ($this->isset_postlog() && $this->get_postlog() == '1'); + if ($transferBasks && $user->is_guest() == false && Session_Handler::isset_cookie('invite-usr_id')) { - if ( ! $transferBasks) - self::set_cookie('last_act', '', -400000, true); - if ($transferBasks && Session_Handler::isset_cookie('invite-usr_id')) { - $basks = array(); $oldusr = self::get_cookie('invite-usr_id'); - if ($oldusr == $this->get_usr_id()) { + if ($oldusr == $user->get_id()) { return $this; } - $sql = 'SELECT sselcont_id, s.ssel_id - FROM sselcont c, ssel s - WHERE s.usr_id = :usr_id - AND s.ssel_id = c.ssel_id'; + $repo = $Core['EM']->getRepository('Entities\Basket'); + $baskets = $repo->findBy(array('usr_id' => $oldusr)); - $stmt = $conn->prepare($sql); - $stmt->execute(array(':usr_id' => $this->get_usr_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $sql = 'UPDATE ssel set usr_id = :usr_id WHERE ssel_id = :ssel_id AND usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - - foreach ($rs as $row) { - $stmt->execute(array(':usr_id' => $this->get_usr_id(), ':ssel_id' => $row['ssel_id'], ':old_usr_id' => $oldusr)); + foreach ($baskets as $basket) { + $basket->setUsrId($user->get_id()); + $Core['EM']->persist($basket); } - $stmt->closeCursor(); - $sql = 'DELETE FROM ssel WHERE usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':old_usr_id' => $oldusr)); - $stmt->closeCursor(); - - $sql = 'UPDATE dsel SET usr_id = :usr_id WHERE usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':usr_id' => $this->get_usr_id(), ':old_usr_id' => $oldusr)); - $stmt->closeCursor(); - - $sql = 'DELETE FROM usr WHERE usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':old_usr_id' => $oldusr)); - $stmt->closeCursor(); - $sql = 'DELETE FROM basusr WHERE usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':old_usr_id' => $oldusr)); - $stmt->closeCursor(); - $sql = 'DELETE FROM sbasusr WHERE usr_id = :old_usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':old_usr_id' => $oldusr)); - $stmt->closeCursor(); + $Core['EM']->flush(); } return $this; diff --git a/tests/Session/Session_HandlerTest.php b/tests/Session/Session_HandlerTest.php index c676dca1e1..3b4b7add5e 100644 --- a/tests/Session/Session_HandlerTest.php +++ b/tests/Session/Session_HandlerTest.php @@ -171,50 +171,6 @@ class Session_HandlerTest extends PhraseanetPHPUnitAbstract $this->assertNull($this->object->get_ses_id()); } - /** - * @todo Implement testIsset_postlog(). - */ - public function testIsset_postlog() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testSet_postlog(). - */ - public function testSet_postlog() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testGet_postlog(). - */ - public function testGet_postlog() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - - /** - * @todo Implement testDelete_postlog(). - */ - public function testDelete_postlog() - { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - public function testSet_session_prefs() { $datas = array('bla' => 1, 2 => 'boum'); diff --git a/www/login/index.php b/www/login/index.php index ecbee01f34..e68e1295af 100644 --- a/www/login/index.php +++ b/www/login/index.php @@ -30,7 +30,7 @@ $parm = $request->get_parms('lng', 'error', 'confirm', 'badlog', 'postlog', 'usr if ($parm['postlog']) { $session->set_postlog(true); - return phrasea::redirect("/login/index.php?redirect=" . $parm['redirect']); + return phrasea::redirect("/login/logout.php?redirect=" . $parm['redirect']); } if ( ! $session->isset_postlog() && $session->is_authenticated() && $parm['error'] != 'no-connection') {