Skip to content

Commit 0cea82f

Browse files
authored
Support Statamic 6 (#18)
2 parents 8a37265 + 0a0c30f commit 0cea82f

File tree

7 files changed

+23
-51
lines changed

7 files changed

+23
-51
lines changed

.github/workflows/run-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
os: [ubuntu-latest]
29-
php: [8.2, 8.3]
30-
laravel: [10.*, 11.*, 12.*]
31-
statamic: [5.*]
29+
php: [8.3, 8.4]
30+
laravel: [12.*]
31+
statamic: [6.*]
3232
dependency-version: [prefer-stable]
3333

3434
name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
composer.lock
55
.php-cs-fixer.cache
66
build/report.junit.xml
7+
.phpunit.cache

composer.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,22 @@
1010
"license": "MIT",
1111
"authors": [
1212
{
13-
"name": "Ryan Mitchell",
14-
"email": "ryan@thoughtcollective.com",
15-
"homepage": "https://github.com/ryanmitchell",
16-
"role": "Developer"
13+
"name": "Statamic Rad Pack",
14+
"homepage": "https://statamic.com/creators/rad-pack"
1715
}
1816
],
1917
"require": {
2018
"php": "^8.2",
2119
"guzzlehttp/guzzle": "^7.3",
2220
"http-interop/http-factory-guzzle": "^1.0",
23-
"illuminate/support": "^10.0|^11.0|^12.0",
24-
"statamic/cms": "^5.38",
21+
"illuminate/support": "^12.0",
22+
"statamic/cms": "^6.0.0",
2523
"typesense/typesense-php": "^5.1"
2624
},
2725
"require-dev": {
2826
"laravel/pint": "^1.17",
29-
"orchestra/testbench": "^8.14 || ^9.0 || ^10.0",
30-
"phpunit/phpunit": "^10.0 || ^11.0"
27+
"orchestra/testbench": "^10.0",
28+
"phpunit/phpunit": "^11.0"
3129
},
3230
"autoload": {
3331
"psr-4": {
@@ -60,5 +58,7 @@
6058
"name": "Typesense",
6159
"description": "Typesense search driver for Statamic"
6260
}
63-
}
61+
},
62+
"minimum-stability": "dev",
63+
"prefer-stable": true
6464
}

config/statamic-typesense.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ class ServiceProvider extends AddonServiceProvider
1111
{
1212
public function bootAddon()
1313
{
14-
$this->mergeConfigFrom(__DIR__.'/../config/statamic-typesense.php', 'statamic-typesense');
15-
16-
if ($this->app->runningInConsole()) {
17-
18-
$this->publishes([
19-
__DIR__.'/../config/statamic-typesense.php' => config_path('statamic-typesense.php'),
20-
], 'statamic-typesense-config');
21-
22-
}
23-
2414
Search::extend('typesense', function (Application $app, array $config, $name, $locale = null) {
2515
$client = new Client($config['client'] ?? []);
2616

src/Typesense/Index.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,12 @@ public function insert($document)
3333
return $this->insertMultiple(collect([$document]));
3434
}
3535

36-
public function insertMultiple($documents)
36+
public function fields(Searchable $searchable)
3737
{
38-
$documents
39-
->chunk(config('statamic-typesense.insert_chunk_size', 100))
40-
->each(function ($documents, $index) {
41-
$documents = $documents
42-
->filter()
43-
->map(fn ($document) => array_merge(
44-
$this->searchables()->fields($document),
45-
$this->getDefaultFields($document),
46-
))
47-
->values()
48-
->toArray();
49-
50-
$this->insertDocuments(new Documents($documents));
51-
});
52-
53-
return $this;
38+
return array_merge(
39+
$this->searchables()->fields($searchable),
40+
$this->getDefaultFields($searchable)
41+
);
5442
}
5543

5644
public function delete($document)
@@ -73,7 +61,7 @@ public function exists()
7361
}
7462
}
7563

76-
protected function insertDocuments(Documents $documents)
64+
public function insertDocuments(Documents $documents)
7765
{
7866
$this->getOrCreateIndex()->documents->import($documents->all(), ['action' => 'upsert']);
7967
}

tests/TestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ protected function resolveApplicationConfiguration($app)
1515
{
1616
parent::resolveApplicationConfiguration($app);
1717

18-
// add typesense driver
1918
$app['config']->set('statamic.search.drivers.typesense', [
2019
'client' => [
2120
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
@@ -40,7 +39,10 @@ protected function resolveApplicationConfiguration($app)
4039
],
4140
]);
4241

43-
// add typesense index
42+
$app['config']->set('statamic.search.indexes.cp', [
43+
'driver' => 'null',
44+
]);
45+
4446
$app['config']->set('statamic.search.indexes.typesense_index', [
4547
'driver' => 'typesense',
4648
'searchables' => ['collection:pages'],

0 commit comments

Comments
 (0)