Skip to content
This repository was archived by the owner on Dec 19, 2025. It is now read-only.

Commit 45f0dbf

Browse files
authored
Merge pull request #59 from bobdenotter/master
Compatibility fixes for Bolt 3.3
2 parents 325179b + 30a4e3f commit 45f0dbf

4 files changed

Lines changed: 33 additions & 16 deletions

File tree

src/Parser/Field/FieldFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public static function build(
4343
$fieldCollection = new FieldCollection([]);
4444
}
4545

46+
$repeatingFieldCollection = null;
47+
$repeatingCollection = null;
48+
4649
foreach ($fields as $label => $field) {
4750
if ($fieldCollection instanceof RepeatingFieldCollection) {
4851
$data = $field->getValue();
@@ -51,7 +54,7 @@ public static function build(
5154
} else {
5255
$data = $item->get($field);
5356
if (isset($metadata['fields'])) {
54-
if (isset($metadata['fields'][$field])) {
57+
if (isset($metadata['fields'][$field]) && isset($metadata['fields'][$field]['data']['type'])) {
5558
$fieldType = $metadata['fields'][$field]['data']['type'];
5659
}
5760
}
@@ -102,8 +105,7 @@ public static function build(
102105
}
103106

104107
//Must NOT be a repeater
105-
if (! $repeatingFieldCollection) {
106-
$repeatingFieldCollection = null;
108+
if (!$repeatingFieldCollection) {
107109
$fieldCollection->add($type);
108110
}
109111
}

src/Parser/Field/Type/Taxonomy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public function render()
99
/** @var \Bolt\Storage\Collection\Taxonomy $taxonomies */
1010
$taxonomies = $this->getValue();
1111

12+
$attributes = [];
13+
1214
foreach ($taxonomies as $taxonomy) {
1315
$type = $taxonomy->getTaxonomytype();
1416
$slug = $taxonomy->getSlug();

src/Storage/Query/Handler/PagingHandler.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Bolt\Extension\Bolt\JsonApi\Storage\Query\PagingResultSet;
77
use Bolt\Storage\Query\ContentQueryParser;
88
use Bolt\Storage\Query\SearchQuery;
9+
use Bolt\Version;
910
use Doctrine\DBAL\Query\QueryBuilder;
1011

1112
/**
@@ -21,21 +22,30 @@ public function __invoke(ContentQueryParser $contentQuery)
2122
$cleanSearchQuery = $contentQuery->getService('search');
2223

2324
foreach ($contentQuery->getContentTypes() as $contenttype) {
25+
$parameters = $contentQuery->getParameters();
26+
2427
//Find out if we are searching or just doing a simple query
25-
if ($searchParam = $contentQuery->getParameter('filter')) {
28+
if (array_key_exists('filter', $parameters)) {
2629
$query = clone $cleanSearchQuery;
2730
} else {
2831
$query = $contentQuery->getService('select');
2932
}
3033

3134
$repo = $contentQuery->getEntityManager()->getRepository($contenttype);
32-
$query->setQueryBuilder($repo->createQueryBuilder($contenttype));
35+
36+
if (Version::compare('3.3', '<=')) {
37+
// Only for Bolt version 3.3 and up.
38+
$query->setQueryBuilder($repo->createQueryBuilder('_' . $contenttype));
39+
} else {
40+
// Only for Bolt versions up to 3.2.x.
41+
$query->setQueryBuilder($repo->createQueryBuilder($contenttype));
42+
}
3343
$query->setContentType($contenttype);
34-
$query->setParameters($contentQuery->getParameters());
44+
$query->setParameters($parameters);
3545

3646
//Set the search parameter if searching
3747
if ($query instanceof SearchQuery) {
38-
$query->setSearch($searchParam);
48+
$query->setSearch($contentQuery->getParameter('filter'));
3949
}
4050

4151
//Get Page from the new directive handler that allows pagination
@@ -57,15 +67,18 @@ public function __invoke(ContentQueryParser $contentQuery)
5767
/** @var QueryBuilder $qb */
5868
$qb = clone $query->getQueryBuilder();
5969

70+
// Get an intersection of current keys, and the ones we need to remove
71+
$removeparts = array_intersect(array_keys($query2->getQueryParts()), ['maxResults', 'firstResult', 'orderBy']);
72+
6073
$query2
61-
->resetQueryParts(['maxResults', 'firstResult', 'orderBy'])
74+
->resetQueryParts($removeparts)
6275
->setFirstResult(null)
6376
->setMaxResults(null)
6477
->select('COUNT(*) as total');
6578

66-
$totalItems = count($repo->findResults($query2));
79+
$totalItems = count($query2->execute()->fetchAll());
6780

68-
$result = $repo->findResults($qb);
81+
$result = $repo->queryWithLoaded($qb);
6982
if ($result) {
7083
$set->add($result, $contenttype);
7184
$set->setTotalResults((int) $totalItems);

src/Storage/Repository.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ public function getQueryBuilderAfterMappings(QueryInterface $query)
3434
}
3535

3636
/**
37-
* Since the queries are built already, we don't need to run all of the other mappings
38-
* before. Now we can just fetch the results of the query instead of running everything else.
37+
* This method is used to run the query without loading the mappings again
3938
*
4039
* @param QueryBuilder $query
4140
*
42-
* @return bool|mixed
41+
* @return array
4342
*/
44-
public function findResults(QueryBuilder $query)
43+
public function queryWithLoaded(QueryBuilder $query)
4544
{
4645
$result = $query->execute()->fetchAll();
4746
if ($result) {
4847
return $this->hydrateAll($result, $query);
49-
} else {
50-
return false;
5148
}
49+
50+
return [];
5251
}
52+
5353
}

0 commit comments

Comments
 (0)