Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- 5.x
- 6.x
pull_request:
branches:
- '*'
Expand All @@ -18,10 +19,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version: ['8.1', '8.2', '8.3', '8.4', '8.5']
php-version: ['8.4', '8.5']
prefer-lowest: ['']
include:
- php-version: '8.1'
- php-version: '8.4'
prefer-lowest: 'prefer-lowest'

services:
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/deploy_docs_6x.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: 'deploy_docs_6x'

on:
push:
branches:
- 6.x
workflow_dispatch:

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Cloning repo
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Push to dokku
uses: dokku/github-action@cc7dec1d2b9fed249a14ae462bc953bba436f78c # v1.10.0
with:
git_remote_url: 'ssh://dokku@apps.cakephp.org:22/elasticsearch-docs-6'
git_push_flags: '-f'
ssh_private_key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }}
branch: '6.x'
6 changes: 3 additions & 3 deletions .github/workflows/docs-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Documentation Validation
on:
push:
branches:
- 5.x
- 6.x
paths:
- 'docs/**'
- '.github/**'
Expand All @@ -14,7 +14,7 @@ on:

jobs:
validate:
uses: cakephp/.github/.github/workflows/docs-validation.yml@5.x
uses: cakephp/.github/.github/workflows/docs-validation.yml@6.x
with:
docs-path: 'docs'
vitepress-path: 'docs/.vitepress'
Expand All @@ -24,4 +24,4 @@ jobs:
enable-spell-check: true
enable-markdown-lint: true
enable-link-check: true
tools-ref: '5.x'
tools-ref: '6.x'
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Elasticsearch Datasource for CakePHP

![Build Status](https://github.com/cakephp/elastic-search/actions/workflows/ci.yml/badge.svg?branch=5.x)
![Build Status](https://github.com/cakephp/elastic-search/actions/workflows/ci.yml/badge.svg?branch=6.x)
[![Latest Stable Version](https://img.shields.io/github/v/release/cakephp/elastic-search?sort=semver&style=flat-square)](https://packagist.org/packages/cakephp/elastic-search)
[![Total Downloads](https://img.shields.io/packagist/dt/cakephp/elastic-search?style=flat-square)](https://packagist.org/packages/cakephp/elastic-search/stats)
[![codecov](https://codecov.io/gh/cakephp/elastic-search/branch/5.x/graph/badge.svg?token=G3Tcg116OX)](https://app.codecov.io/gh/cakephp/elastic-search/tree/5.x)
[![codecov](https://codecov.io/gh/cakephp/elastic-search/branch/6.x/graph/badge.svg?token=G3Tcg116OX)](https://app.codecov.io/gh/cakephp/elastic-search/tree/6.x)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat-square)](https://phpstan.org/)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)

Use [Elastic Search](https://www.elastic.co/) as an alternative ORM backend in CakePHP 5.2+.
Use [Elastic Search](https://www.elastic.co/) as an alternative ORM backend in CakePHP 6.0+.

You can [find the documentation for the plugin in the Cake Book](https://book.cakephp.org/elasticsearch).

Expand All @@ -17,7 +17,7 @@ You can install Elasticsearch into your project using
[composer](https://getcomposer.org). For existing applications you can run:

```bash
composer require cakephp/elastic-search:^5.0
composer require cakephp/elastic-search:^6.0
```

### Versions Table
Expand All @@ -30,8 +30,9 @@ composer require cakephp/elastic-search:^5.0
| [>=3.4.0](https://github.com/cakephp/elastic-search/tree/3.x) | 4.0+ | 7.x | 7.x |
| [4.x](https://github.com/cakephp/elastic-search/tree/4.x) | 5.0+ | 7.x | 7.x |
| [5.x](https://github.com/cakephp/elastic-search/tree/5.x) | 5.2+ | 9.x | 9.x |
| [6.x](https://github.com/cakephp/elastic-search/tree/6.x) | 6.0+ | 9.x | 9.x |

You are seeing the 5.x version.
You are seeing the 6.x version.

## Connecting the Plugin to your Application

Expand All @@ -42,7 +43,7 @@ use Cake\ElasticSearch\Plugin as ElasticSearchPlugin;

class Application extends BaseApplication
{
public function bootstrap()
public function bootstrap(): void
{
$this->addPlugin(ElasticSearchPlugin::class);

Expand Down
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"source": "https://github.com/cakephp/elastic-search"
},
"require": {
"cakephp/cakephp": "^5.2.0",
"php": ">=8.4",
"cakephp/cakephp": "^6.0",
"ruflin/elastica": "^9.0"
},
"require-dev": {
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.5.5 || ^11.5.3 || ^12.1.3",
"cakephp/cakephp-codesniffer": "^6.0",
"phpunit/phpunit": "^13.0",
"nyholm/psr7": "^1.8"
},
"autoload": {
Expand Down Expand Up @@ -56,8 +57,10 @@
"test-coverage": "phpunit --coverage-clover=clover.xml",
"phpstan": "vendor/bin/phpstan analyse",
"phpstan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:^2.0 --no-update && composer update && mv composer.backup composer.json",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"^2.2\" && mv composer.backup composer.json",
"rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.6.0\" && mv composer.backup composer.json",
"rector-check": "vendor/bin/rector process --dry-run",
"rector-fix": "vendor/bin/rector process"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
1 change: 1 addition & 0 deletions docs/.vitepress/toc_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"text": "Migration",
"collapsed": false,
"items": [
{ "text": "6.0 Upgrade Guide", "link": "/6-0-upgrade-guide" },
{ "text": "5.0 Upgrade Guide", "link": "/5-0-upgrade-guide" },
{ "text": "4.0 Upgrade Guide", "link": "/4-0-upgrade-guide" },
{ "text": "3.0 Upgrade Guide", "link": "/3-0-upgrade-guide" }
Expand Down
114 changes: 114 additions & 0 deletions docs/en/6-0-upgrade-guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# 6.0 Upgrade Guide

::: warning Requirements
CakePHP ElasticSearch `6.x` requires CakePHP `6.0+`, Elasticsearch `9.x`, Elastica `9.x`, and PHP `8.4+`.
:::

## Requirements

- CakePHP `6.0+`
- Elasticsearch `9.x`
- Elastica `9.x`
- PHP `8.4+`

## Breaking Changes

Version `6.x` requires CakePHP `6.x`.
The Elasticsearch, Elastica and PHP version requirements are unchanged from `5.x`,
apart from the PHP version bump required by CakePHP `6`.

### Updated dependencies

Update your application requirements:

```bash
composer require cakephp/elastic-search:^6.0
```

- `cakephp/cakephp` is now `^6.0`.
- `php` is now `>=8.4`.

### Entity access rules

`Cake\Datasource\EntityTrait` renamed its access control API:

| CakePHP 5.x | CakePHP 6.x |
| ------------------------------- | ------------------------------- |
| `$entity->setAccess(...)` | `$entity->setPatchable(...)` |
| `$entity->getAccessible()` | `$entity->getPatchable()` |
| `$entity->isAccessible(...)` | `$entity->isPatchable(...)` |
| `'accessibleFields' => [...]` | `'patchableFields' => [...]` |

The `Marshaller` options array follows the same rename:

```php
// Before (5.x)
$entity = $this->Articles->marshallOne($data, ['accessibleFields' => ['title' => false]]);

// After (6.x)
$entity = $this->Articles->marshallOne($data, ['patchableFields' => ['title' => false]]);
```

### Query changes

- `Query::order()` has been removed. Use `Query::orderBy()` instead.
- Finders no longer accept a positional options array. Pass finder options as
named arguments; passing an array now throws an `InvalidArgumentException`:

```php
// Before (5.x, deprecated)
$this->Articles->find('all', ['limit' => 10]);

// After (6.x)
$this->Articles->find('all', limit: 10);
```

- Fluent query methods (`select()`, `where()`, `limit()`, `offset()`, `page()`,
`orderBy()`, `applyOptions()`, `setRepository()`, ...) now declare a `static`
return type, as required by `Cake\Datasource\QueryInterface`.

### Fixtures

`Cake\Datasource\FixtureInterface::insert()` and `truncate()` now return `void`.
If you have custom fixtures that implement or extend `Cake\ElasticSearch\TestSuite\TestFixture`,
update their signatures accordingly:

```php
public function insert(ConnectionInterface $connection): void
{
}
```

### Subclassing `Cake\ElasticSearch\Document`

CakePHP `6` removed the underscore prefix convention. Plugin classes follow the
same rule, so protected members that custom subclasses may rely on were renamed:

| 5.x | 6.x |
| -------------------- | ---------------- |
| `Document::$_result` | `Document::$searchResult` |

`$searchResult` holds the `Elastica\Result` the document was hydrated from and
backs `index()`, `version()`, `highlights()` and `explanation()`.

The same convention applies to `Query`, `Index`, `Connection`, `Marshaller` and
friends - for example `Query::$_queryParts` is now `Query::$queryParts`.

### Test suite

- `Index` and `Connection` fluent setters (`setConnection()`, `setName()`,
`setEntityClass()`, `setCacher()`, `setLogger()`, `enableQueryLogging()`, ...)
now declare a `static` return type.

## Recommended Migration Steps

1. Update `composer.json` to require `cakephp/elastic-search:^6.0` and run `composer update`.
2. Upgrade your application to CakePHP `6.0` and PHP `8.4` by following the
[CakePHP 6 migration guide](https://book.cakephp.org/6.x/appendices/6-0-migration-guide.html).
3. Replace `setAccess()`/`getAccessible()`/`isAccessible()` calls with their
`setPatchable()`/`getPatchable()`/`isPatchable()` equivalents.
4. Rename the `accessibleFields` marshaller option to `patchableFields`.
5. Replace `Query::order()` with `Query::orderBy()` and convert finder option
arrays to named arguments.
6. Update custom fixture `insert()`/`truncate()` signatures to `void`.
7. Re-run your test suite against Elasticsearch `9.x`.
4 changes: 2 additions & 2 deletions docs/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The ElasticSearch plugin provides an ORM-like abstraction for working with [Elasticsearch](https://www.elastic.co/products/elasticsearch) indexes in CakePHP. It helps with indexing, searching, validation, embedded documents, and fixture-backed tests.

Version `5.x` targets CakePHP `5.2+`, Elasticsearch `9.x`, Elastica `9.x`, and PHP `8.1+`.
Version `6.x` targets CakePHP `6.0+`, Elasticsearch `9.x`, Elastica `9.x`, and PHP `8.4+`.

## Documentation Map

Expand All @@ -11,4 +11,4 @@ Version `5.x` targets CakePHP `5.2+`, Elasticsearch `9.x`, Elastica `9.x`, and P
- [Searching and Saving](/searching-and-saving) covers finding, validating, saving, updating, bulk operations, and deleting documents.
- [Embedded Documents](/embedded-documents) explains `embedOne()` and `embedMany()` for nested document objects.
- [Testing](/testing) shows how to load mappings and fixtures for integration tests.
- [3.0 Upgrade Guide](/3-0-upgrade-guide), [4.0 Upgrade Guide](/4-0-upgrade-guide), and [5.0 Upgrade Guide](/5-0-upgrade-guide) describe version-specific migration changes.
- [6.0 Upgrade Guide](/6-0-upgrade-guide), [5.0 Upgrade Guide](/5-0-upgrade-guide), [4.0 Upgrade Guide](/4-0-upgrade-guide), and [3.0 Upgrade Guide](/3-0-upgrade-guide) describe version-specific migration changes.
2 changes: 1 addition & 1 deletion docs/en/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Install the plugin with Composer from your application's root directory:

```bash
composer require cakephp/elastic-search:^5.0
composer require cakephp/elastic-search:^6.0
```

Load the plugin in your application bootstrap:
Expand Down
2 changes: 1 addition & 1 deletion docs/ja/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ElasticSearch プラグインは、[Elasticsearch](https://www.elastic.co/produc
アプリケーションのルートディレクトリーで Composer を使ってインストールします。

```bash
composer require cakephp/elastic-search:^5.0
composer require cakephp/elastic-search:^6.0
```

`src/Application.php` でプラグインを読み込みます。
Expand Down
7 changes: 1 addition & 6 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
<file>tests/</file>

<rule ref="CakePHP"/>
<arg value="nps"/>
<arg value="ps"/>
<arg name="colors"/>
<arg name="parallel" value="4"/>
<arg name="cache" value=".phpcs.cache"/>

<!-- Necessary for class aliases used for backwards compat -->
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<severity>0</severity>
</rule>
</ruleset>
16 changes: 10 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
<?php
declare(strict_types=1);

use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Config\RectorConfig;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->withPhpVersion(PhpVersion::PHP_83)
->withPhpVersion(PhpVersion::PHP_84)
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
])
->withSkip([
// CakePHP coding standards compatibility
DisallowedEmptyRuleFixerRector::class,
SimplifyIfElseToTernaryRector::class,
// Skip visibility changes that might break inheritance
MakeInheritedMethodVisibilitySameAsParentRector::class,
// Docblock removal rules added in rector 2.5/2.6. They are skipped to keep
// the diff behavior-neutral, and because `@return $this` is still needed for
// PHPStan to track the fluent interfaces declared by CakePHP interfaces.
RemoveDuplicatedReturnSelfDocblockRector::class,
RemoveUselessReturnTagRector::class,
RemoveUselessUnionReturnDocblockRector::class,
])
->withParallel()
->withPreparedSets(
Expand Down
8 changes: 4 additions & 4 deletions src/Association/Embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getProperty(): string
* @param string|null $name The property name to set.
* @return $this
*/
public function setProperty(?string $name = null)
public function setProperty(?string $name = null): static
{
if ($name !== null) {
$this->property = $name;
Expand Down Expand Up @@ -149,7 +149,7 @@ public function getEntityClass(): string
* @param string $name The name of the class to use
* @return $this
*/
public function setEntityClass(string $name)
public function setEntityClass(string $name): static
{
$class = App::className($name, 'Model/Document');
$this->entityClass = $class ?? Document::class;
Expand Down Expand Up @@ -186,7 +186,7 @@ public function getIndexClass(): string
* @throws \InvalidArgumentException In case the class name is set after the target index has been
* resolved, and it doesn't match the target index's class name.
*/
public function setIndexClass(string|Index|null $className)
public function setIndexClass(string|Index|null $className): static
{
if ($className instanceof Index) {
$this->index = $className;
Expand Down Expand Up @@ -219,7 +219,7 @@ public function setIndexClass(string|Index|null $className)
* @param \Cake\ElasticSearch\Index $index the instance to be assigned as target side
* @return $this
*/
public function setIndex(Index $index)
public function setIndex(Index $index): static
{
$this->index = $index;

Expand Down
Loading
Loading