File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515interface IModel
1616{
17- /** @const use as an argument when needed */
18- const I_KNOW_WHAT_I_AM_DOING = 'i_know_what_i_am_doing ' ;
19-
20-
2117 /**
2218 * Returns true if repository with name is attached to model.
2319 */
@@ -81,16 +77,13 @@ public function persistAndFlush(IEntity $entity): IEntity;
8177
8278
8379 /**
84- * USE ONLY IF YOU ARE SURE YOU KNOW WHAT ARE YOU DOING.
8580 * Clears repository identity map and other possible caches.
8681 * Make sure that all references to already used entites are released,
8782 * this makes possible to free the memory for garbage collector.
8883 * Orm will not allow you to work with these entities anymore.
89- * @dangerous
90- * @internal
91- * @ignore
84+ * @return void
9285 */
93- public function clearIdentityMapAndCaches ( $ areYouSure );
86+ public function clear ( );
9487
9588
9689 /**
Original file line number Diff line number Diff line change 1111use Nette \Object ;
1212use Nextras \Orm \Entity \IEntity ;
1313use Nextras \Orm \InvalidArgumentException ;
14- use Nextras \Orm \LogicException ;
1514use Nextras \Orm \Relationships \IRelationshipCollection ;
1615use Nextras \Orm \Repository \IRepository ;
1716use Nextras \Orm \Repository \PersistenceHelper ;
@@ -167,14 +166,11 @@ public function persistAndFlush(IEntity $entity): IEntity
167166 }
168167
169168
170- public function clearIdentityMapAndCaches ($ areYouSure )
169+ /** @inheritdoc */
170+ public function clear ()
171171 {
172- if ($ areYouSure !== self ::I_KNOW_WHAT_I_AM_DOING ) {
173- throw new LogicException ('Use this method only if you are sure what are you doing. ' );
174- }
175-
176172 foreach ($ this ->getLoadedRepositories () as $ repository ) {
177- $ repository ->doClearIdentityMap ( $ areYouSure );
173+ $ repository ->doClear ( );
178174 }
179175 }
180176
Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ public function doFlush();
164164 * @internal
165165 * @ignore
166166 */
167- public function doClearIdentityMap ( $ areYouSure );
167+ public function doClear ( );
168168
169169
170170 /**
Original file line number Diff line number Diff line change @@ -327,12 +327,8 @@ public function doFlush()
327327
328328
329329 /** @inheritdoc */
330- public function doClearIdentityMap ( $ areYouSure = null )
330+ public function doClear ( )
331331 {
332- if ($ areYouSure !== IModel::I_KNOW_WHAT_I_AM_DOING ) {
333- throw new LogicException ('Do not call this method directly. Use IModel::clearIdentityMapAndCaches(). ' );
334- }
335-
336332 $ this ->identityMap ->destroyAllEntities ();
337333 $ this ->mapper ->clearCache ();
338334 }
Original file line number Diff line number Diff line change 22
33namespace NextrasTests \Orm \Collection ;
44
5- use Mockery ;
6- use Nextras \Orm \Model \IModel ;
75use NextrasTests \Orm \Author ;
86use NextrasTests \Orm \TestCase ;
97use Tester \Assert ;
108use Tester \Environment ;
119
10+
1211$ dic = require_once __DIR__ . '/../../bootstrap.php ' ;
1312
1413
@@ -34,13 +33,13 @@ class MemoryManagementTest extends TestCase
3433 }
3534
3635 $ this ->persistEntity ();
37- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
36+ $ this ->orm ->clear ( );
3837
3938 $ baseline = memory_get_usage (false );
4039
4140 for ($ i = 0 ; $ i < 200 ; ++$ i ) {
4241 $ this ->persistEntity ();
43- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
42+ $ this ->orm ->clear ( );
4443 gc_collect_cycles ();
4544
4645 $ ratio = memory_get_usage (false ) / $ baseline ;
Original file line number Diff line number Diff line change 77namespace NextrasTests \Orm \Integration \Entity ;
88
99use DateTimeImmutable ;
10- use Nextras \Orm \Model \IModel ;
1110use NextrasTests \Orm \Author ;
1211use NextrasTests \Orm \TestCase ;
1312use Tester \Assert ;
@@ -97,7 +96,7 @@ class EntityDefaultValueTest extends TestCase
9796 $ id = $ author ->getPersistedId ();
9897
9998
100- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
99+ $ this ->orm ->clear ( );
101100
102101 $ author = $ this ->orm ->authors ->getById ($ id );
103102 Assert::null ($ author ->born );
Original file line number Diff line number Diff line change 77
88namespace NextrasTests \Orm \Integration \Mapper ;
99
10- use Mockery ;
11- use Nextras \Orm \Model \IModel ;
1210use NextrasTests \Orm \Author ;
1311use NextrasTests \Orm \Book ;
1412use NextrasTests \Orm \DataTestCase ;
1513use NextrasTests \Orm \Publisher ;
1614use Tester \Assert ;
1715
16+
1817$ dic = require_once __DIR__ . '/../../../bootstrap.php ' ;
1918
2019
@@ -36,7 +35,7 @@ class StorageReflectionTest extends DataTestCase
3635
3736 $ this ->orm ->books ->persistAndFlush ($ bookA );
3837 $ id = $ bookA ->getPersistedId ();
39- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
38+ $ this ->orm ->clear ( );
4039
4140 $ bookB = $ this ->orm ->books ->getById ($ id );
4241 Assert::same ('2015-09-09T10:10:10+02:00 ' , $ bookB ->publishedAt ->format ('c ' ));
Original file line number Diff line number Diff line change 77
88namespace NextrasTests \Orm \Integration \Model ;
99
10- use Mockery ;
11- use Nextras \Orm \Model \IModel ;
1210use NextrasTests \Orm \DataTestCase ;
1311use Tester \Assert ;
1412
13+
1514$ dic = require_once __DIR__ . '/../../../bootstrap.php ' ;
1615
1716
18- class ModelClearIdentityMapAndCachesTest extends DataTestCase
17+ class ModelClearTest extends DataTestCase
1918{
2019
2120 public function testBasics ()
@@ -27,7 +26,7 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
2726
2827 Assert::equal ($ book1 , $ book2 );
2928
30- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
29+ $ this ->orm ->clear ( );
3130
3231 $ book3 = $ this ->orm ->books ->getById (1 );
3332 Assert::notEqual ($ book1 , $ book3 );
@@ -47,7 +46,7 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
4746 $memory1 = memory_get_usage();
4847
4948 unset($books, $book);
50- $this->orm->clearIdentityMapAndCaches(IModel::I_KNOW_WHAT_I_AM_DOING );
49+ $this->orm->clear( );
5150
5251
5352 $books = $this->orm->books->findAll();
@@ -62,5 +61,5 @@ class ModelClearIdentityMapAndCachesTest extends DataTestCase
6261}
6362
6463
65- $ test = new ModelClearIdentityMapAndCachesTest ($ dic );
64+ $ test = new ModelClearTest ($ dic );
6665$ test ->run ();
Original file line number Diff line number Diff line change 77
88namespace NextrasTests \Orm \Integration \Relationships ;
99
10- use Nextras \Orm \Model \IModel ;
1110use Nextras \Orm \Relationships \ManyHasMany ;
1211use NextrasTests \Orm \Book ;
1312use NextrasTests \Orm \DataTestCase ;
@@ -31,7 +30,7 @@ class RelationshipsManyHasManyCollectionTest extends DataTestCase
3130 {
3231 parent ::setUp ();
3332
34- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
33+ $ this ->orm ->clear ( );
3534 $ this ->book = $ this ->orm ->books ->getById (1 );
3635 $ this ->tags = $ this ->book ->tags ;
3736 }
Original file line number Diff line number Diff line change 77
88namespace NextrasTests \Orm \Integration \Relationships ;
99
10- use Nextras \Orm \Model \IModel ;
1110use Nextras \Orm \Relationships \OneHasMany ;
1211use NextrasTests \Orm \Author ;
1312use NextrasTests \Orm \Book ;
@@ -16,6 +15,7 @@ use NextrasTests\Orm\Helper;
1615use NextrasTests \Orm \Publisher ;
1716use Tester \Assert ;
1817
18+
1919$ dic = require_once __DIR__ . '/../../../bootstrap.php ' ;
2020
2121
@@ -39,7 +39,7 @@ class RelationshipsOneHasManyCollectionTest extends DataTestCase
3939 {
4040 parent ::setUp ();
4141
42- $ this ->orm ->clearIdentityMapAndCaches (IModel:: I_KNOW_WHAT_I_AM_DOING );
42+ $ this ->orm ->clear ( );
4343 $ this ->publisher = $ this ->orm ->publishers ->getById (1 );
4444 $ this ->authorA = $ this ->orm ->authors ->getById (1 );
4545 $ this ->authorB = $ this ->orm ->authors ->getById (2 );
You can’t perform that action at this time.
0 commit comments