• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

AJenbo / agcms / 21420560247

28 Jan 2026 12:59AM UTC coverage: 52.306% (-1.4%) from 53.72%
21420560247

push

github

AJenbo
Bump phpunit/phpunit from 9.6.11 to 9.6.33 in /application

Bumps [phpunit/phpunit](https://github.com/sebastianbergmann/phpunit) from 9.6.11 to 9.6.33.
- [Release notes](https://github.com/sebastianbergmann/phpunit/releases)
- [Changelog](https://github.com/sebastianbergmann/phpunit/blob/9.6.33/ChangeLog-9.6.md)
- [Commits](https://github.com/sebastianbergmann/phpunit/compare/9.6.11...9.6.33)

---
updated-dependencies:
- dependency-name: phpunit/phpunit
  dependency-version: 9.6.33
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>

3039 of 5810 relevant lines covered (52.31%)

12.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.82
/application/inc/Http/Controllers/Search.php
1
<?php
2

3
namespace App\Http\Controllers;
4

5
use App\Http\Request;
6
use App\Models\Brand;
7
use App\Models\Category;
8
use App\Models\Page;
9
use App\Models\VolatilePage;
10
use App\Services\DbService;
11
use App\Services\OrmService;
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\Response;
14

15
class Search extends Base
16
{
17
    /**
18
     * Show the advanced search form.
19
     */
20
    public function index(): Response
21
    {
22
        $data = $this->basicPageData();
1✔
23
        $crumbs = $data['crumbs'] ?? null;
1✔
24
        if (!is_array($crumbs)) {
1✔
25
            $crumbs = [];
×
26
        }
27
        $crumbs[] = new VolatilePage(_('Search'), '/search/');
1✔
28
        $data['crumbs'] = $crumbs;
1✔
29
        $data['brands'] = $this->getActiveBrands();
1✔
30

31
        $response = $this->render('search', $data);
1✔
32

33
        return $this->cachedResponse($response);
1✔
34
    }
35

36
    /**
37
     * Get brands used on active pages.
38
     *
39
     * @return Brand[]
40
     */
41
    private function getActiveBrands(): array
42
    {
43
        $orm = app(OrmService::class);
1✔
44

45
        $categoryIds = [];
1✔
46
        $categories = $orm->getByQuery(Category::class, 'SELECT * FROM kat');
1✔
47
        foreach ($categories as $category) {
1✔
48
            if ($category->isInactive()) {
1✔
49
                continue;
1✔
50
            }
51
            $categoryIds[] = $category->getId();
1✔
52
        }
53

54
        return $orm->getByQuery(
1✔
55
            Brand::class,
1✔
56
            '
1✔
57
            SELECT * FROM `maerke`
58
            WHERE id IN(
59
                SELECT DISTINCT sider.maerke FROM bind
60
                JOIN sider ON sider.id = bind.side
61
                WHERE bind.kat IN(' . implode(',', $categoryIds) . ')
1✔
62
            ) ORDER BY `navn`
63
            '
1✔
64
        );
1✔
65
    }
66

67
    /**
68
     * Show search results.
69
     */
70
    public function results(Request $request): Response
71
    {
72
        if ($response = $this->checkSearchable($request)) {
2✔
73
            return $response;
2✔
74
        }
75

76
        $searchString = $request->get('q');
×
77
        if (!is_string($searchString)) {
×
78
            $searchString = '';
×
79
        }
80
        $brandId = $request->query->getInt('maerke');
×
81
        $varenr = $request->get('varenr');
×
82
        if (!is_string($varenr)) {
×
83
            $varenr = '';
×
84
        }
85
        $minpris = $request->query->getInt('minpris', 0);
×
86
        $maxpris = $request->query->getInt('maxpris', 0);
×
87
        $antiWords = $request->get('sogikke');
×
88
        if (!is_string($antiWords)) {
×
89
            $antiWords = '';
×
90
        }
91

92
        $pages = $this->findPages($searchString, $brandId, $varenr, $minpris, $maxpris, $antiWords);
×
93
        if (1 === count($pages)) {
×
94
            $page = array_shift($pages);
×
95

96
            return redirect($page->getCanonicalLink());
×
97
        }
98

99
        $brands = $this->findBrands(
×
100
            $searchString,
×
101
            $antiWords
×
102
        );
×
103

104
        $categories = $this->findCategories(
×
105
            $searchString,
×
106
            $antiWords
×
107
        );
×
108

109
        $contentList = array_merge($pages, $brands, $categories);
×
110

111
        $requirement = new VolatilePage('Results', $request->getRequestUri(), $contentList);
×
112

113
        $data = $this->basicPageData();
×
114
        $crumbs = $data['crumbs'] ?? null;
×
115
        if (!is_array($crumbs)) {
×
116
            $crumbs = [];
×
117
        }
118
        $crumbs[] = new VolatilePage(_('Search'), '/search/');
×
119
        $crumbs[] = $requirement;
×
120
        $data['crumbs'] = $crumbs;
×
121

122
        $data['renderable'] = $requirement;
×
123
        $data['search'] = $searchString;
×
124

125
        $response = $this->render('tiles', $data);
×
126

127
        return $this->cachedResponse($response);
×
128
    }
129

130
    /**
131
     * Check if we should performe the search or handle it else where.
132
     */
133
    private function checkSearchable(Request $request): ?RedirectResponse
134
    {
135
        $brandId = $request->get('maerke');
2✔
136
        if (!$request->get('q')
2✔
137
            && !$request->get('varenr')
2✔
138
            && !$request->get('minpris')
2✔
139
            && !$request->get('maxpris')
2✔
140
            && !$request->get('sogikke')
2✔
141
        ) {
142
            if (ctype_digit($brandId) || is_int($brandId)) {
2✔
143
                $brand = app(OrmService::class)->getOne(Brand::class, (int)$brandId);
2✔
144
                if ($brand && $brand->hasPages()) {
2✔
145
                    return redirect($brand->getCanonicalLink(), Response::HTTP_MOVED_PERMANENTLY);
1✔
146
                }
147
            }
148

149
            return redirect('/search/', Response::HTTP_MOVED_PERMANENTLY);
1✔
150
        }
151

152
        return null;
×
153
    }
154

155
    /**
156
     * Search for pages and generate a list or redirect if only one was found.
157
     *
158
     * @todo search in keywords
159
     *
160
     * @return Page[]
161
     */
162
    private function findPages(
163
        string $searchString,
164
        int $brandId,
165
        string $varenr = '',
166
        int $minpris = 0,
167
        int $maxpris = 0,
168
        string $antiWords = ''
169
    ): array {
170
        $db = app(DbService::class);
×
171

172
        $simpleQuery = '%' . preg_replace('/\s+/u', '%', $searchString) . '%';
×
173
        $simpleQuery = $db->quote($simpleQuery);
×
174

175
        //Full search
176
        $where = '';
×
177
        if ($brandId) {
×
178
            $where = ' AND `maerke` = ' . $brandId;
×
179
        }
180
        if ($varenr) {
×
181
            $where .= ' AND varenr LIKE ' . $db->quote($varenr . '%');
×
182
        }
183
        if ($minpris) {
×
184
            $where .= ' AND pris > ' . $minpris;
×
185
        }
186
        if ($maxpris) {
×
187
            $where .= ' AND pris < ' . $maxpris;
×
188
        }
189
        if ($antiWords) {
×
190
            $simpleAntiQuery = '%' . preg_replace('/\s+/u', '%', $antiWords) . '%';
×
191
            $simpleAntiQuery = $db->quote($simpleAntiQuery);
×
192
            $where .= ' AND !MATCH (navn, text, beskrivelse) AGAINST(' . $db->quote($antiWords) . ") > 0
×
193
            AND `navn` NOT LIKE $simpleAntiQuery
×
194
            AND `text` NOT LIKE $simpleAntiQuery
×
195
            AND `beskrivelse` NOT LIKE $simpleAntiQuery
×
196
            ";
×
197
        }
198

199
        $db->addLoadedTable('list_rows', 'lists', 'bind');
×
200
        $columns = [];
×
201
        foreach ($db->fetchArray('SHOW COLUMNS FROM sider') as $column) {
×
202
            $columns[] = $column['Field'];
×
203
        }
204

205
        $against = $db->quote($searchString);
×
206

207
        $pages = app(OrmService::class)->getByQuery(
×
208
            Page::class,
×
209
            '
×
210
            SELECT `' . implode('`, `', $columns) . '`
×
211
            FROM (SELECT sider.*, MATCH(navn, text, beskrivelse) AGAINST (' . $against . ') AS score
×
212
            FROM sider
213
            JOIN bind ON sider.id = bind.side AND bind.kat != -1
214
            WHERE (
215
                MATCH (navn, text, beskrivelse) AGAINST(' . $against . ") > 0
×
216
                OR `navn` LIKE $simpleQuery
×
217
                OR `text` LIKE $simpleQuery
×
218
                OR `beskrivelse` LIKE $simpleQuery
×
219
            )
220
            $where
×
221
            ORDER BY `score` DESC) x
222
            UNION
223
            SELECT sider.* FROM `list_rows`
224
            JOIN lists ON list_rows.list_id = lists.id
225
            JOIN sider ON lists.page_id = sider.id
226
            JOIN bind ON sider.id = bind.side AND bind.kat != -1
227
            WHERE list_rows.`cells` LIKE $simpleQuery"
×
228
            . $where
×
229
        );
×
230

231
        // Remove inactive pages
232
        foreach ($pages as $key => $page) {
×
233
            if ($page->isInactive()) {
×
234
                unset($pages[$key]);
×
235
            }
236
        }
237

238
        return $pages;
×
239
    }
240

241
    /**
242
     * Search for brands.
243
     *
244
     * @return Brand[]
245
     */
246
    private function findBrands(string $searchString, string $antiWords): array
247
    {
248
        if (!$searchString) {
×
249
            return [];
×
250
        }
251

252
        $simpleSearchString = '%' . preg_replace('/\s+/u', '%', $searchString) . '%';
×
253
        $simpleAntiWords = $antiWords ? '%' . preg_replace('/\s+/u', '%', $antiWords) . '%' : '';
×
254

255
        $db = app(DbService::class);
×
256

257
        return app(OrmService::class)->getByQuery(
×
258
            Brand::class,
×
259
            '
×
260
            SELECT * FROM `maerke`
261
            WHERE (
262
                MATCH (navn) AGAINST(' . $db->quote($searchString) . ') > 0
×
263
                OR navn LIKE ' . $db->quote($simpleSearchString) . '
×
264
            )
265
            AND !MATCH (navn) AGAINST(' . $db->quote($antiWords) . ') > 0
×
266
            AND navn NOT LIKE ' . $db->quote($simpleAntiWords) . '
×
267
            '
×
268
        );
×
269
    }
270

271
    /**
272
     * Search for categories.
273
     *
274
     * @return Category[]
275
     */
276
    private function findCategories(string $searchString, string $antiWords): array
277
    {
278
        if (!$searchString) {
×
279
            return [];
×
280
        }
281

282
        $simpleSearchString = '%' . preg_replace('/\s+/u', '%', $searchString) . '%';
×
283
        $simpleAntiWords = $antiWords ? '%' . preg_replace('/\s+/u', '%', $antiWords) . '%' : '';
×
284

285
        $db = app(DbService::class);
×
286

287
        $categories = app(OrmService::class)->getByQuery(
×
288
            Category::class,
×
289
            '
×
290
            SELECT *, MATCH (navn) AGAINST (' . $db->quote($searchString) . ') AS score
×
291
            FROM kat
292
            WHERE (
293
                MATCH (navn) AGAINST(' . $db->quote($searchString) . ') > 0
×
294
                OR navn LIKE ' . $db->quote($simpleSearchString) . '
×
295
            )
296
            AND !MATCH (navn) AGAINST(' . $db->quote($antiWords) . ') > 0
×
297
            AND navn NOT LIKE ' . $db->quote($simpleAntiWords) . "
×
298
            AND `vis` != '0'
299
            ORDER BY score, navn
300
            "
×
301
        );
×
302

303
        $activeCategories = [];
×
304
        foreach ($categories as $category) {
×
305
            if ($category->isVisible()) {
×
306
                $activeCategories[] = $category;
×
307
            }
308
        }
309

310
        return $activeCategories;
×
311
    }
312
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc