Skip to content

Commit 58d366a

Browse files
committed
Fix issues with Hybrid Mode.
1 parent 58770a1 commit 58d366a

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

Diff for: RedBeanPHP/Facade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,10 @@ public static function store( $bean, $unfreezeIfNeeded = FALSE )
619619
$result = self::$redbean->store( $bean );
620620
} catch (SQLException $exception) {
621621
$wasFrozen = self::$redbean->isFrozen();
622-
if ( !self::$allowHybridMode || !$wasFrozen ) throw $exception;
622+
if ( !self::$allowHybridMode || !$unfreezeIfNeeded ) throw $exception;
623623
self::freeze( FALSE );
624624
$result = self::$redbean->store( $bean );
625-
self::freeze( !$wasFrozen );
625+
self::freeze( $wasFrozen );
626626
}
627627
return $result;
628628
}

Diff for: testing/RedUNIT/Base/Hybrid.php

+28-6
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public function testHybrid()
3737
R::setAllowHybridMode( FALSE );
3838
$book->title = 'Tales of a misfit';
3939
try {
40-
R::store( $book );
40+
R::store( $book, TRUE );
41+
fail();
42+
} catch(\Exception $e) {
43+
pass();
44+
}
45+
try {
46+
R::store( $book, FALSE );
4147
fail();
4248
} catch(\Exception $e) {
4349
pass();
@@ -48,6 +54,18 @@ public function testHybrid()
4854
$book->title = 'Tales of a misfit';
4955
try {
5056
R::store( $book );
57+
fail();
58+
} catch(\Exception $e) {
59+
pass();
60+
}
61+
try {
62+
R::store( $book, FALSE );
63+
fail();
64+
} catch(\Exception $e) {
65+
pass();
66+
}
67+
try {
68+
R::store( $book, TRUE );
5169
pass();
5270
} catch(\Exception $e) {
5371
fail();
@@ -71,24 +89,28 @@ public function testHybridDataType()
7189
if ($this->currentlyActiveDriverID == 'sqlite') return;
7290
$book = R::dispense('book');
7391
$book->pages = 1;
74-
$id = R::store( $book );
92+
$id = R::store( $book, TRUE );
7593
R::freeze( TRUE );
94+
asrt( R::getRedBean()->isFrozen(), TRUE );
7695
R::setAllowHybridMode( FALSE );
7796
$book->pages = 'too many';
7897
try {
79-
R::store( $book );
98+
R::store( $book, TRUE );
8099
fail();
81100
} catch(\Exception $e) {
82101
pass();
83102
}
103+
asrt( R::getRedBean()->isFrozen(), TRUE );
84104
R::setAllowHybridMode( TRUE );
105+
asrt( R::getRedBean()->isFrozen(), TRUE );
85106
R::debug(1);
86107
try {
87-
R::store( $book );
108+
R::store( $book, TRUE );
88109
pass();
89110
} catch(\Exception $e) {
90111
fail();
91112
}
113+
asrt( R::getRedBean()->isFrozen(), TRUE );
92114
$book = $book->fresh();
93115
echo $book;
94116
asrt( $book->pages, 'too many' );
@@ -109,7 +131,7 @@ public function testHybridNonSQLException()
109131
R::freeze( TRUE );
110132
R::setAllowHybridMode( TRUE );
111133
try {
112-
R::store( $toy );
134+
R::store( $toy, TRUE );
113135
fail();
114136
} catch(\Exception $e) {
115137
pass();
@@ -120,7 +142,7 @@ public function testHybridNonSQLException()
120142
R::freeze( TRUE );
121143
R::setAllowHybridMode( TRUE );
122144
try {
123-
R::store( $toy );
145+
R::store( $toy, TRUE );
124146
pass();
125147
} catch(\Exception $e) {
126148
fail();

0 commit comments

Comments
 (0)