Skip to content

Commit 28f53fe

Browse files
phansysfranmomu
authored andcommitted
Use different methods than execute() when retrieving results
1 parent a47b675 commit 28f53fe

File tree

4 files changed

+17
-52
lines changed

4 files changed

+17
-52
lines changed

src/Loggable/Document/Repository/LogEntryRepository.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,8 @@ public function getLogEntries($document)
5959
$qb->field('objectId')->equals($objectId);
6060
$qb->field('objectClass')->equals($wrapped->getMetadata()->getName());
6161
$qb->sort('version', 'DESC');
62-
$q = $qb->getQuery();
6362

64-
$result = $q->execute();
65-
if ($result instanceof Iterator) {
66-
$result = $result->toArray();
67-
}
68-
69-
return $result;
63+
return $qb->getQuery()->getIterator()->toArray();
7064
}
7165

7266
/**
@@ -95,12 +89,8 @@ public function revert($document, $version = 1)
9589
$qb->field('objectClass')->equals($objectMeta->getName());
9690
$qb->field('version')->lte((int) $version);
9791
$qb->sort('version', 'ASC');
98-
$q = $qb->getQuery();
9992

100-
$logs = $q->execute();
101-
if ($logs instanceof Iterator) {
102-
$logs = $logs->toArray();
103-
}
93+
$logs = $qb->getQuery()->getIterator()->toArray();
10494

10595
if ([] === $logs) {
10696
throw new UnexpectedValueException('Count not find any log entries under version: '.$version);

src/Sluggable/Mapping/Event/Adapter/ODM.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ public function getSimilarSlugs($object, $meta, array $config, $slug)
4747
$q = $qb->getQuery();
4848
$q->setHydrate(false);
4949

50-
$result = $q->execute();
51-
if ($result instanceof Iterator) {
52-
$result = $result->toArray();
53-
}
54-
55-
return $result;
50+
return $q->getIterator()->toArray();
5651
}
5752

5853
/**
@@ -74,14 +69,11 @@ public function replaceRelative($object, array $config, $target, $replacement)
7469
->getQuery()
7570
;
7671
$q->setHydrate(false);
77-
$result = $q->execute();
78-
79-
if (!$result instanceof Iterator) {
80-
return 0;
81-
}
72+
$result = $q->getIterator();
73+
$count = 0;
8274

83-
$result = $result->toArray();
8475
foreach ($result as $targetObject) {
76+
++$count;
8577
$slug = preg_replace("@^{$target}@smi", $replacement.$config['pathSeparator'], $targetObject[$config['slug']]);
8678
$dm
8779
->createQueryBuilder()
@@ -93,7 +85,7 @@ public function replaceRelative($object, array $config, $target, $replacement)
9385
;
9486
}
9587

96-
return count($result);
88+
return $count;
9789
}
9890

9991
/**
@@ -113,14 +105,11 @@ public function replaceInverseRelative($object, array $config, $target, $replace
113105
->getQuery()
114106
;
115107
$q->setHydrate(false);
116-
$result = $q->execute();
117-
118-
if (!$result instanceof Iterator) {
119-
return 0;
120-
}
108+
$result = $q->getIterator();
109+
$count = 0;
121110

122-
$result = $result->toArray();
123111
foreach ($result as $targetObject) {
112+
++$count;
124113
$slug = preg_replace("@^{$replacement}@smi", $target, $targetObject[$config['slug']]);
125114
$dm
126115
->createQueryBuilder()
@@ -132,6 +121,6 @@ public function replaceInverseRelative($object, array $config, $target, $replace
132121
;
133122
}
134123

135-
return count($result);
124+
return $count;
136125
}
137126
}

src/Translatable/Document/Repository/TranslationRepository.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,9 @@ public function findTranslations($document)
142142
->getQuery();
143143

144144
$q->setHydrate(false);
145-
$data = $q->execute();
146145

147-
if (is_iterable($data)) {
148-
foreach ($data as $row) {
149-
$result[$row['locale']][$row['field']] = $row['content'];
150-
}
146+
foreach ($q->getIterator() as $row) {
147+
$result[$row['locale']][$row['field']] = $row['content'];
151148
}
152149
}
153150

@@ -182,11 +179,7 @@ public function findObjectByTranslatedField($field, $value, $class)
182179
->getQuery();
183180

184181
$q->setHydrate(false);
185-
$result = $q->execute();
186-
187-
if ($result instanceof Iterator) {
188-
$result = $result->toArray();
189-
}
182+
$result = $q->getIterator()->toArray();
190183

191184
$id = $result[0]['foreign_key'] ?? null;
192185

@@ -216,12 +209,9 @@ public function findTranslationsByObjectId($id)
216209
->getQuery();
217210

218211
$q->setHydrate(false);
219-
$data = $q->execute();
220212

221-
if (is_iterable($data)) {
222-
foreach ($data as $row) {
223-
$result[$row['locale']][$row['field']] = $row['content'];
224-
}
213+
foreach ($q->getIterator() as $row) {
214+
$result[$row['locale']][$row['field']] = $row['content'];
225215
}
226216
}
227217

src/Translatable/Mapping/Event/Adapter/ODM.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,8 @@ public function loadTranslations($object, $translationClass, $locale, $objectCla
9090
;
9191
}
9292
$q->setHydrate(false);
93-
$result = $q->execute();
94-
if ($result instanceof Iterator) {
95-
$result = $result->toArray();
96-
}
9793

98-
return $result;
94+
return $q->getIterator()->toArray();
9995
}
10096

10197
public function findTranslation(AbstractWrapper $wrapped, $locale, $field, $translationClass, $objectClass)

0 commit comments

Comments
 (0)