mirror of
https://github.com/silverstripe/silverstripe-fulltextsearch
synced 2024-06-24 13:39:39 +02:00
Compare commits
80 Commits
3.9.0-beta
...
3
Author | SHA1 | Date | |
---|---|---|---|
|
7609ca8716 | ||
|
285eb16cc0 | ||
|
23f9210918 | ||
|
47a2a1e1a8 | ||
|
0aa57c788a | ||
|
f3c22299b8 | ||
|
39a37d9c41 | ||
|
157e303228 | ||
|
776c99bbaa | ||
|
831438fe9d | ||
|
66321b6e50 | ||
|
6fe21430e7 | ||
|
d75925cc49 | ||
|
6b9aa83597 | ||
|
65d53d9918 | ||
|
f6819cbcc6 | ||
|
99af1a0d21 | ||
|
5610c56365 | ||
|
d067054f72 | ||
|
9b2e9e332c | ||
|
d666c4f0bf | ||
|
b5ed2dd238 | ||
|
11ec50e03a | ||
|
47d13600f9 | ||
|
59d60e6edc | ||
|
860d8be9fa | ||
|
20c2a4efa7 | ||
|
03da5016bf | ||
|
74107de9fd | ||
|
c0a3d3a5ba | ||
|
a6657f76d6 | ||
|
78d4907eab | ||
|
a536434581 | ||
|
8da777409d | ||
|
f4a2ad1f45 | ||
|
206a01541b | ||
|
66956c682f | ||
|
ef2d27fba9 | ||
|
35c9484f05 | ||
|
7ac991a82a | ||
|
0560e8a180 | ||
|
bd9501a1d5 | ||
|
6d90b3ca35 | ||
|
72722e83d8 | ||
|
24b53e65ca | ||
|
302af21cad | ||
|
1d9e98cd3b | ||
|
f9ace692f4 | ||
|
b544d93121 | ||
|
fad7c0421c | ||
|
30ed311386 | ||
|
9da3c2b331 | ||
|
0788dc4e81 | ||
|
7a1047320b | ||
|
c8e997ae89 | ||
|
b39b5c6801 | ||
|
4947961d5a | ||
|
adefb3fddf | ||
|
8befac8f65 | ||
|
eac962d103 | ||
|
767fa29bab | ||
|
5282cdc3ed | ||
|
e0ec87a0ed | ||
|
2c0e2df02d | ||
|
f0e781da36 | ||
|
b1675d4df1 | ||
|
a5ce0e8781 | ||
|
fbe899e85f | ||
|
355e928ec9 | ||
|
8ac7964220 | ||
|
a621f77380 | ||
|
573fbf9edc | ||
|
95f50f6ce2 | ||
|
ec054c666b | ||
|
8ed79dd893 | ||
|
94bb78fc7f | ||
|
5611e24e10 | ||
|
34e0594e48 | ||
|
9dfcbf9c90 | ||
|
8876a47f0d |
15
.github/workflows/ci.yml
vendored
Normal file
15
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
ci:
|
||||
name: CI
|
||||
uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
|
||||
with:
|
||||
extra_jobs: |
|
||||
- name_suffix: subsites
|
||||
composer_require_extra: silverstripe/subsites:^2
|
16
.github/workflows/dispatch-ci.yml
vendored
Normal file
16
.github/workflows/dispatch-ci.yml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
|||
name: Dispatch CI
|
||||
|
||||
on:
|
||||
# At 2:10 PM UTC, only on Wednesday and Thursday
|
||||
schedule:
|
||||
- cron: '10 14 * * 3,4'
|
||||
|
||||
jobs:
|
||||
dispatch-ci:
|
||||
name: Dispatch CI
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Dispatch CI
|
||||
uses: silverstripe/gha-dispatch-ci@v1
|
17
.github/workflows/keepalive.yml
vendored
Normal file
17
.github/workflows/keepalive.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
name: Keepalive
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
# The 4th of every month at 10:50am UTC
|
||||
schedule:
|
||||
- cron: '50 10 4 * *'
|
||||
|
||||
jobs:
|
||||
keepalive:
|
||||
name: Keepalive
|
||||
# Only run cron on the silverstripe account
|
||||
if: (github.event_name == 'schedule' && github.repository_owner == 'silverstripe') || (github.event_name != 'schedule')
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Keepalive
|
||||
uses: silverstripe/gha-keepalive@v1
|
|
@ -1,15 +0,0 @@
|
|||
inherit: true
|
||||
|
||||
build:
|
||||
nodes:
|
||||
analysis:
|
||||
tests:
|
||||
override: [php-scrutinizer-run]
|
||||
|
||||
checks:
|
||||
php:
|
||||
code_rating: true
|
||||
duplication: true
|
||||
|
||||
filter:
|
||||
paths: [src/*, tests/*]
|
18
.travis.yml
18
.travis.yml
|
@ -1,18 +0,0 @@
|
|||
version: ~> 1.0
|
||||
|
||||
import:
|
||||
- silverstripe/silverstripe-travis-shared:config/provision/standard-jobs-range.yml
|
||||
|
||||
env:
|
||||
global:
|
||||
- COMPOSER_ROOT_VERSION="3.x-dev"
|
||||
- REQUIRE_EXTRA="symbiote/silverstripe-queuedjobs:^4.0"
|
||||
|
||||
jobs:
|
||||
include:
|
||||
- php: 7.3
|
||||
env:
|
||||
- DB=MYSQL
|
||||
- REQUIRE_INSTALLER=4.x-dev
|
||||
- PHPUNIT_TEST=1
|
||||
- REQUIRE_EXTRA="symbiote/silverstripe-queuedjobs:^4 silverstripe/subsites:^2"
|
8
.tx/config
Normal file
8
.tx/config
Normal file
|
@ -0,0 +1,8 @@
|
|||
[main]
|
||||
host = https://www.transifex.com
|
||||
|
||||
[o:silverstripe:p:silverstripe-fulltextsearch:r:master]
|
||||
file_filter = lang/<lang>.yml
|
||||
source_file = lang/en.yml
|
||||
source_lang = en
|
||||
type = YML
|
11
README.md
11
README.md
|
@ -1,11 +1,8 @@
|
|||
# FullTextSearch module
|
||||
|
||||
[![Build Status](https://api.travis-ci.com/silverstripe/silverstripe-fulltextsearch.svg?branch=3)](https://travis-ci.com/silverstripe/silverstripe-fulltextsearch)
|
||||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/silverstripe/silverstripe-fulltextsearch/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-fulltextsearch/?branch=master)
|
||||
[![codecov](https://codecov.io/gh/silverstripe/silverstripe-fulltextsearch/branch/master/graph/badge.svg)](https://codecov.io/gh/silverstripe/silverstripe-fulltextsearch)
|
||||
[![SilverStripe supported module](https://img.shields.io/badge/silverstripe-supported-0071C4.svg)](https://www.silverstripe.org/software/addons/silverstripe-commercially-supported-module-list/)
|
||||
[![CI](https://github.com/silverstripe/silverstripe-fulltextsearch/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-fulltextsearch/actions/workflows/ci.yml)
|
||||
|
||||
Adds support for fulltext search engines like Sphinx and Solr to SilverStripe CMS.
|
||||
Adds support for fulltext search engines like Sphinx and Solr to Silverstripe CMS.
|
||||
Compatible with PHP 7.2
|
||||
|
||||
## Important notes when upgrading to fulltextsearch 3.7.0+
|
||||
|
@ -86,9 +83,9 @@ it's recommended you update your implementation to call `SearchableService::isVi
|
|||
|
||||
## Requirements
|
||||
|
||||
* SilverStripe 4.0+
|
||||
* Silverstripe 4.0+
|
||||
|
||||
**Note:** For SilverStripe 3.x, please use the [2.x release line](https://github.com/silverstripe/silverstripe-fulltextsearch/tree/2).
|
||||
**Note:** For Silverstripe 3.x, please use the [2.x release line](https://github.com/silverstripe/silverstripe-fulltextsearch/tree/2).
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
<?php
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
|
||||
Deprecation::notification_version('3.0', 'silverstripe/fulltextsearch');
|
|
@ -21,17 +21,19 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.3 || ^8.0",
|
||||
"php": "^7.4 || ^8.0",
|
||||
"silverstripe/framework": "^4.10",
|
||||
"monolog/monolog": "~1.15",
|
||||
"ptcinc/solr-php-client": "^1.0",
|
||||
"symfony/process": "^3.2",
|
||||
"tractorcow/silverstripe-proxy-db": "~0.1"
|
||||
"silverstripe/solr-php-client": "^1.0",
|
||||
"symfony/process": "^3.4 || ^4",
|
||||
"tractorcow/silverstripe-proxy-db": "^1",
|
||||
"ext-curl": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"silverstripe/cms": "^4.0",
|
||||
"phpunit/phpunit": "^9.5",
|
||||
"squizlabs/php_codesniffer": "^3.0"
|
||||
"squizlabs/php_codesniffer": "^3.0",
|
||||
"symbiote/silverstripe-queuedjobs": "^4.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
|
|
@ -379,7 +379,7 @@
|
|||
-->
|
||||
|
||||
<autoSoftCommit>
|
||||
<maxTime>${solr.autoSoftCommit.maxTime:-1}</maxTime>
|
||||
<maxTime>${solr.autoSoftCommit.maxTime:60000}</maxTime>
|
||||
</autoSoftCommit>
|
||||
|
||||
<!-- Update Related Event Listeners
|
||||
|
|
|
@ -1,13 +1,26 @@
|
|||
# Troubleshooting
|
||||
|
||||
## Newly indexed content only shows in searches after a delay
|
||||
|
||||
First, check how you're running index operations.
|
||||
In many cases where the `queuedjobs` module is installed,
|
||||
saving or publishing a record will create a new index job which needs to complete first.
|
||||
Solr also distinguishes between adding documents to the indexing,
|
||||
committing them, and making them available to new searches.
|
||||
In most cases this happens within a few seconds, but
|
||||
in sometimes it can take up to a minute due to the
|
||||
`autoSoftCommit` configuration setting defaults in your `solrconfig.xml`.
|
||||
To find out more detail, read about
|
||||
[soft vs. hard commits](https://lucidworks.com/post/understanding-transaction-logs-softcommit-and-commit-in-sorlcloud/).
|
||||
|
||||
## Common gotchas
|
||||
|
||||
* By default number-letter boundaries are treated as a word boundary. For example, `A1` is two words - `a` and `1` - when Solr parses the search term.
|
||||
* Special characters and operators are not correctly escaped
|
||||
* Multi-word synonym issues
|
||||
* When Dolr indexes are reconfigured and reindexed, their content is trashed and rebuilt
|
||||
* When Solr indexes are reconfigured and reindexed, their content is trashed and rebuilt
|
||||
|
||||
### CWP-specific
|
||||
## CWP-specific
|
||||
|
||||
* `solrconfig.xml` customisations fail silently
|
||||
* Developers aren’t able to test raw queries or see output via the
|
||||
|
|
10
lang/en.yml
10
lang/en.yml
|
@ -2,3 +2,13 @@ en:
|
|||
SilverStripe\FullTextSearch\Solr\Forms\SearchForm:
|
||||
GO: Go
|
||||
SEARCH: Search
|
||||
SolrResultsPage:
|
||||
DidYouMean: 'Did you mean'
|
||||
NoResults: 'Sorry, your search query did not return any results.'
|
||||
Page: Page
|
||||
ReadMore: 'Read more about'
|
||||
SearchQuery: 'You searched for'
|
||||
ViewNextPage: 'View the next page'
|
||||
ViewPageNumber: 'View page number'
|
||||
ViewPreviousPage: 'View the previous page'
|
||||
of: of
|
||||
|
|
14
lang/eo.yml
Normal file
14
lang/eo.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
eo:
|
||||
SilverStripe\FullTextSearch\Solr\Forms\SearchForm:
|
||||
GO: Iri
|
||||
SEARCH: Serĉi
|
||||
SolrResultsPage:
|
||||
DidYouMean: 'Ĉu vi intencis'
|
||||
NoResults: 'Bedaŭrinde via serĉpeto ne liveris rezultojn.'
|
||||
Page: Paĝo
|
||||
ReadMore: 'Legi pli pri'
|
||||
SearchQuery: 'Vi serĉis por'
|
||||
ViewNextPage: 'Vidi la sekvan paĝon'
|
||||
ViewPageNumber: 'Vidi paĝnumeron'
|
||||
ViewPreviousPage: 'Vidi la antaŭan paĝon'
|
||||
of: de
|
14
lang/fi.yml
14
lang/fi.yml
|
@ -3,12 +3,12 @@ fi:
|
|||
GO: Hae
|
||||
SEARCH: Haku
|
||||
SolrResultsPage:
|
||||
SearchQuery: 'Hakusanasi oli'
|
||||
DidYouMean: 'Tarkoititko'
|
||||
ReadMore: 'Lue lisää'
|
||||
DidYouMean: Tarkoititko
|
||||
NoResults: 'Pahoittelut, mutta hakusi ei tuottanut yhtään osumaa.'
|
||||
Page: 'Sivu'
|
||||
of: '/'
|
||||
ViewPreviousPage: 'Katso edellinen sivu'
|
||||
View page number: 'Siirry sivulle'
|
||||
Page: Sivu
|
||||
ReadMore: 'Lue lisää'
|
||||
SearchQuery: 'Hakusanasi oli'
|
||||
'View page number': 'Siirry sivulle'
|
||||
ViewNextPage: 'Katso seuraava sivu'
|
||||
ViewPreviousPage: 'Katso edellinen sivu'
|
||||
of: /
|
||||
|
|
14
lang/nl.yml
Normal file
14
lang/nl.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
nl:
|
||||
SilverStripe\FullTextSearch\Solr\Forms\SearchForm:
|
||||
GO: Zoek
|
||||
SEARCH: Zoeken
|
||||
SolrResultsPage:
|
||||
DidYouMean: 'Bedoelde je'
|
||||
NoResults: 'Helaas, deze zoekterm heeft geen resultaten opgeleverd.'
|
||||
Page: Pagina
|
||||
ReadMore: 'Lees meer over'
|
||||
SearchQuery: 'Er is gezocht op'
|
||||
ViewNextPage: 'Bekijk volgende pagina'
|
||||
ViewPageNumber: 'Bekijk pagina'
|
||||
ViewPreviousPage: 'Bekijk volgende pagina'
|
||||
of: van
|
14
lang/sl.yml
Normal file
14
lang/sl.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
sl:
|
||||
SilverStripe\FullTextSearch\Solr\Forms\SearchForm:
|
||||
GO: Išči
|
||||
SEARCH: Iskanje
|
||||
SolrResultsPage:
|
||||
DidYouMean: 'Ste morda mislili'
|
||||
NoResults: 'Fraze, ki ste jo iskali, nismo našli.'
|
||||
Page: Stran
|
||||
ReadMore: 'Več o'
|
||||
SearchQuery: 'Iskali ste'
|
||||
ViewNextPage: Naslednja
|
||||
ViewPageNumber: 'Skoči na stran'
|
||||
ViewPreviousPage: Prejšnja
|
||||
of: od
|
14
lang/sv.yml
Normal file
14
lang/sv.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
sv:
|
||||
SilverStripe\FullTextSearch\Solr\Forms\SearchForm:
|
||||
GO: Gå
|
||||
SEARCH: Sök
|
||||
SolrResultsPage:
|
||||
DidYouMean: 'Menade du'
|
||||
NoResults: 'Förlåt, din sökfråga gav inga resultat.'
|
||||
Page: Sida
|
||||
ReadMore: 'Läs mera om'
|
||||
SearchQuery: 'Du sökte efter'
|
||||
ViewNextPage: 'Visa nästa sida'
|
||||
ViewPageNumber: 'Visa sidnummer'
|
||||
ViewPreviousPage: 'Visa föregående sida'
|
||||
of: av
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Default">
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
namespace SilverStripe\FullTextSearch\Search\Captures;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\ORM\Connect\MySQLDatabase;
|
||||
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||
|
||||
/**
|
||||
* @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
* @deprecated 3.1.0 Use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
*/
|
||||
|
||||
class SearchManipulateCapture_MySQLDatabase extends MySQLDatabase
|
||||
|
@ -14,6 +15,11 @@ class SearchManipulateCapture_MySQLDatabase extends MySQLDatabase
|
|||
|
||||
public $isManipulationCapture = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Deprecation::notice('3.1.0', 'Use tractorcow/silverstripe-proxy-db to proxy the database connector instead', Deprecation::SCOPE_CLASS);
|
||||
}
|
||||
|
||||
public function manipulate($manipulation)
|
||||
{
|
||||
$res = parent::manipulate($manipulation);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace SilverStripe\FullTextSearch\Search\Captures;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\PostgreSQL\PostgreSQLDatabase;
|
||||
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||
|
||||
|
@ -10,13 +11,17 @@ if (!class_exists(PostgreSQLDatabase::class)) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
* @deprecated 3.1.0 Use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
*/
|
||||
|
||||
class SearchManipulateCapture_PostgreSQLDatabase extends PostgreSQLDatabase
|
||||
{
|
||||
public $isManipulationCapture = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Deprecation::notice('3.1.0', 'Use tractorcow/silverstripe-proxy-db to proxy the database connector instead', Deprecation::SCOPE_CLASS);
|
||||
}
|
||||
|
||||
public function manipulate($manipulation)
|
||||
{
|
||||
$res = parent::manipulate($manipulation);
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace SilverStripe\FullTextSearch\Search\Captures;
|
||||
|
||||
use SilverStripe\Dev\Deprecation;
|
||||
use SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater;
|
||||
use SilverStripe\SQLite\SQLite3Database;
|
||||
|
||||
|
@ -10,7 +11,7 @@ if (!class_exists(SQLite3Database::class)) {
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated 3.1...4.0 Please use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
* @deprecated 3.1.0 Use tractorcow/silverstripe-proxy-db to proxy the database connector instead
|
||||
*/
|
||||
|
||||
class SearchManipulateCapture_SQLite3Database extends SQLite3Database
|
||||
|
@ -18,6 +19,11 @@ class SearchManipulateCapture_SQLite3Database extends SQLite3Database
|
|||
|
||||
public $isManipulationCapture = true;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
Deprecation::notice('3.1.0', 'Use tractorcow/silverstripe-proxy-db to proxy the database connector instead', Deprecation::SCOPE_CLASS);
|
||||
}
|
||||
|
||||
public function manipulate($manipulation)
|
||||
{
|
||||
$res = parent::manipulate($manipulation);
|
||||
|
|
|
@ -222,7 +222,7 @@ class SearchCriteria implements SearchCriteriaInterface
|
|||
protected function getConjunction($key)
|
||||
{
|
||||
$conjunctions = $this->getConjunctions();
|
||||
if (!array_key_exists($key, $conjunctions)) {
|
||||
if (!array_key_exists($key, $conjunctions ?? [])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ class FullTextSearch
|
|||
}
|
||||
|
||||
if ($hidden) {
|
||||
$candidates = array_diff($candidates, $hidden);
|
||||
$candidates = array_diff($candidates ?? [], $hidden);
|
||||
}
|
||||
|
||||
// Create all indexes
|
||||
|
@ -86,7 +86,7 @@ class FullTextSearch
|
|||
|
||||
$valid = array();
|
||||
foreach ($all as $indexclass => $instance) {
|
||||
if (is_subclass_of($indexclass, $class)) {
|
||||
if (is_subclass_of($indexclass, $class ?? '')) {
|
||||
$valid[$indexclass] = $instance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ abstract class SearchIndex extends ViewableData
|
|||
*/
|
||||
protected function getSourceName($source)
|
||||
{
|
||||
$source = explode(self::config()->get('class_delimiter'), $source);
|
||||
$source = explode(self::config()->get('class_delimiter') ?? '', $source ?? '');
|
||||
|
||||
return $source[0];
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ abstract class SearchIndex extends ViewableData
|
|||
*/
|
||||
public function fieldData($field, $forceType = null, $extraOptions = [])
|
||||
{
|
||||
$fullfield = str_replace(".", "_", $field);
|
||||
$fullfield = str_replace(".", "_", $field ?? '');
|
||||
$sources = $this->getClasses();
|
||||
|
||||
foreach ($sources as $source => $options) {
|
||||
|
@ -112,8 +112,8 @@ abstract class SearchIndex extends ViewableData
|
|||
|
||||
$found = [];
|
||||
|
||||
if (strpos($field, '.') !== false) {
|
||||
$lookups = explode(".", $field);
|
||||
if (strpos($field ?? '', '.') !== false) {
|
||||
$lookups = explode(".", $field ?? '');
|
||||
$field = array_pop($lookups);
|
||||
|
||||
foreach ($lookups as $lookup) {
|
||||
|
@ -133,7 +133,7 @@ abstract class SearchIndex extends ViewableData
|
|||
// we only want to include base class for relation, omit classes that inherited the relation
|
||||
$relationList = Config::inst()->get($dataclass, 'has_one', Config::UNINHERITED);
|
||||
$relationList = (!is_null($relationList)) ? $relationList : [];
|
||||
if (!array_key_exists($lookup, $relationList)) {
|
||||
if (!array_key_exists($lookup, $relationList ?? [])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ abstract class SearchIndex extends ViewableData
|
|||
// we only want to include base class for relation, omit classes that inherited the relation
|
||||
$relationList = Config::inst()->get($dataclass, 'has_many', Config::UNINHERITED);
|
||||
$relationList = (!is_null($relationList)) ? $relationList : [];
|
||||
if (!array_key_exists($lookup, $relationList)) {
|
||||
if (!array_key_exists($lookup, $relationList ?? [])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -160,7 +160,7 @@ abstract class SearchIndex extends ViewableData
|
|||
// we only want to include base class for relation, omit classes that inherited the relation
|
||||
$relationList = Config::inst()->get($dataclass, 'many_many', Config::UNINHERITED);
|
||||
$relationList = (!is_null($relationList)) ? $relationList : [];
|
||||
if (!array_key_exists($lookup, $relationList)) {
|
||||
if (!array_key_exists($lookup, $relationList ?? [])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ abstract class SearchIndex extends ViewableData
|
|||
$class = $this->getSourceName($class);
|
||||
$dataclasses = SearchIntrospection::hierarchy($class, $options['include_children']);
|
||||
|
||||
while (count($dataclasses)) {
|
||||
while (count($dataclasses ?? [])) {
|
||||
$dataclass = array_shift($dataclasses);
|
||||
$type = null;
|
||||
$fieldoptions = $options;
|
||||
|
@ -228,9 +228,9 @@ abstract class SearchIndex extends ViewableData
|
|||
|
||||
if ($type) {
|
||||
// Don't search through child classes of a class we matched on. TODO: Should we?
|
||||
$dataclasses = array_diff($dataclasses, array_values(ClassInfo::subclassesFor($dataclass)));
|
||||
$dataclasses = array_diff($dataclasses ?? [], array_values(ClassInfo::subclassesFor($dataclass) ?? []));
|
||||
// Trim arguments off the type string
|
||||
if (preg_match('/^(\w+)\(/', $type, $match)) {
|
||||
if (preg_match('/^(\w+)\(/', $type ?? '', $match)) {
|
||||
$type = $match[1];
|
||||
}
|
||||
// Get the origin
|
||||
|
@ -412,7 +412,7 @@ abstract class SearchIndex extends ViewableData
|
|||
|
||||
public function buildDependancyList()
|
||||
{
|
||||
$this->dependancyList = array_keys($this->getClasses());
|
||||
$this->dependancyList = array_keys($this->getClasses() ?? []);
|
||||
|
||||
foreach ($this->getFieldsIterator() as $name => $field) {
|
||||
if (!isset($field['class'])) {
|
||||
|
@ -434,7 +434,7 @@ abstract class SearchIndex extends ViewableData
|
|||
$this->derivedFields = array();
|
||||
|
||||
foreach ($this->getFieldsIterator() as $name => $field) {
|
||||
if (count($field['lookup_chain']) < 2) {
|
||||
if (count($field['lookup_chain'] ?? []) < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,7 @@ abstract class SearchIndex extends ViewableData
|
|||
$this->derivedFields[$key]['fields'][$fieldname] = $fieldname;
|
||||
SearchIntrospection::add_unique_by_ancestor($this->derivedFields['classes'], $field['class']);
|
||||
} else {
|
||||
$chain = array_reverse($field['lookup_chain']);
|
||||
$chain = array_reverse($field['lookup_chain'] ?? []);
|
||||
array_shift($chain);
|
||||
|
||||
$this->derivedFields[$key] = array(
|
||||
|
@ -473,7 +473,7 @@ abstract class SearchIndex extends ViewableData
|
|||
{
|
||||
ksort($state);
|
||||
$parts = array('id' => $id, 'base' => $base, 'state' => json_encode($state));
|
||||
return implode('-', array_values($parts));
|
||||
return implode('-', array_values($parts ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -501,7 +501,7 @@ abstract class SearchIndex extends ViewableData
|
|||
$errorHandler = function ($no, $str) {
|
||||
throw new Exception('HTML Parse Error: ' . $str);
|
||||
};
|
||||
set_error_handler($errorHandler, E_ALL);
|
||||
set_error_handler($errorHandler, E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED));
|
||||
|
||||
try {
|
||||
foreach ($field['lookup_chain'] as $step) {
|
||||
|
@ -586,7 +586,7 @@ abstract class SearchIndex extends ViewableData
|
|||
|
||||
// First, if this object is directly contained in the index, add it
|
||||
foreach ($this->classes as $searchclass => $options) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass))) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass ?? ''))) {
|
||||
$base = DataObject::getSchema()->baseDataClass($searchclass);
|
||||
$dirty[$base] = array();
|
||||
foreach ($statefulids as $statefulid) {
|
||||
|
@ -605,7 +605,7 @@ abstract class SearchIndex extends ViewableData
|
|||
if (!SearchIntrospection::is_subclass_of($class, $derivation['classes'])) {
|
||||
continue;
|
||||
}
|
||||
if (!array_intersect_key($fields, $derivation['fields'])) {
|
||||
if (!array_intersect_key($fields ?? [], $derivation['fields'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ abstract class SearchUpdateBatchedProcessor extends SearchUpdateProcessor
|
|||
}
|
||||
|
||||
// Don't re-process completed queue
|
||||
if ($this->currentBatch >= count($this->batches)) {
|
||||
if ($this->currentBatch >= count($this->batches ?? [])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -138,14 +138,14 @@ abstract class SearchUpdateBatchedProcessor extends SearchUpdateProcessor
|
|||
while ($ids) {
|
||||
// Estimate maximum number of items to take for this iteration, allowing for the soft cap
|
||||
$take = $batchSize - $currentSize;
|
||||
if (count($ids) <= $take + $softCap) {
|
||||
if (count($ids ?? []) <= $take + $softCap) {
|
||||
$take += $softCap;
|
||||
}
|
||||
$items = array_slice($ids, 0, $take, true);
|
||||
$ids = array_slice($ids, count($items), null, true);
|
||||
$items = array_slice($ids ?? [], 0, $take, true);
|
||||
$ids = array_slice($ids ?? [], count($items ?? []), null, true);
|
||||
|
||||
// Update batch
|
||||
$currentSize += count($items);
|
||||
$currentSize += count($items ?? []);
|
||||
$merge = array(
|
||||
$base => array(
|
||||
$stateKey => array(
|
||||
|
|
|
@ -97,7 +97,7 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
|
||||
if ($dirty) {
|
||||
$indexes = FullTextSearch::get_indexes();
|
||||
static::$dirty_indexes = array_keys($indexes);
|
||||
static::$dirty_indexes = array_keys($indexes ?? []);
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
{
|
||||
if (empty($this->indexes)) {
|
||||
$indexes = FullTextSearch::get_indexes();
|
||||
$this->indexes = array_keys($indexes);
|
||||
$this->indexes = array_keys($indexes ?? []);
|
||||
}
|
||||
return $this->indexes;
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
{
|
||||
// If we've indexed exactly as many as we would like, we are done
|
||||
return $this->skipped
|
||||
|| (count($this->getAllIndexes()) <= count($this->completed));
|
||||
|| (count($this->getAllIndexes() ?? []) <= count($this->completed ?? []));
|
||||
}
|
||||
|
||||
public function prepareForRestart()
|
||||
|
@ -213,7 +213,7 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
{
|
||||
// Skip index if this is already complete
|
||||
$name = get_class($index);
|
||||
if (in_array($name, $this->completed)) {
|
||||
if (in_array($name, $this->completed ?? [])) {
|
||||
$this->addMessage("Skipping already comitted index {$name}");
|
||||
return;
|
||||
}
|
||||
|
@ -240,8 +240,8 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
public function getJobData()
|
||||
{
|
||||
$data = new stdClass();
|
||||
$data->totalSteps = count($this->getAllIndexes());
|
||||
$data->currentStep = count($this->completed);
|
||||
$data->totalSteps = count($this->getAllIndexes() ?? []);
|
||||
$data->currentStep = count($this->completed ?? []);
|
||||
$data->isComplete = $this->jobFinished();
|
||||
$data->messages = $this->messages;
|
||||
|
||||
|
@ -265,7 +265,7 @@ class SearchUpdateCommitJobProcessor implements QueuedJob
|
|||
|
||||
public function addMessage($message, $severity = 'INFO')
|
||||
{
|
||||
$severity = strtoupper($severity);
|
||||
$severity = strtoupper($severity ?? '');
|
||||
$this->messages[] = '[' . date('Y-m-d H:i:s') . "][$severity] $message";
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace SilverStripe\FullTextSearch\Search\Processors;
|
|||
use SilverStripe\FullTextSearch\Search\Services\SearchableService;
|
||||
use SilverStripe\FullTextSearch\Search\Variants\SearchVariantVersioned;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\FullTextSearch\Search\Variants\SearchVariant;
|
||||
use SilverStripe\FullTextSearch\Search\FullTextSearch;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
|
@ -54,7 +55,7 @@ abstract class SearchUpdateProcessor
|
|||
$forclass[$statekey] = array('state' => $state, 'ids' => array($id => array($index)));
|
||||
} elseif (!isset($forclass[$statekey]['ids'][$id])) {
|
||||
$forclass[$statekey]['ids'][$id] = array($index);
|
||||
} elseif (array_search($index, $forclass[$statekey]['ids'][$id]) === false) {
|
||||
} elseif (array_search($index, $forclass[$statekey]['ids'][$id] ?? []) === false) {
|
||||
$forclass[$statekey]['ids'][$id][] = $index;
|
||||
// dirty count stays the same
|
||||
}
|
||||
|
@ -88,7 +89,7 @@ abstract class SearchUpdateProcessor
|
|||
SearchVariant::activate_state($state);
|
||||
|
||||
// Ensure that indexes for all new / updated objects are included
|
||||
$objs = DataObject::get($base)->byIDs(array_keys($ids));
|
||||
$objs = DataObject::get($base)->byIDs(array_keys($ids ?? []));
|
||||
|
||||
/** @var DataObject $obj */
|
||||
foreach ($objs as $obj) {
|
||||
|
@ -154,6 +155,9 @@ abstract class SearchUpdateProcessor
|
|||
*/
|
||||
public function process()
|
||||
{
|
||||
if (!DB::is_active()) {
|
||||
return false;
|
||||
}
|
||||
// Generate and commit all instances
|
||||
$indexes = $this->prepareIndexes();
|
||||
foreach ($indexes as $index) {
|
||||
|
|
|
@ -45,7 +45,7 @@ class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implem
|
|||
|
||||
public function jobFinished()
|
||||
{
|
||||
return $this->currentBatch >= count($this->batches);
|
||||
return $this->currentBatch >= count($this->batches ?? []);
|
||||
}
|
||||
|
||||
public function setup()
|
||||
|
@ -68,7 +68,7 @@ class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implem
|
|||
public function getJobData()
|
||||
{
|
||||
$data = new stdClass();
|
||||
$data->totalSteps = count($this->batches);
|
||||
$data->totalSteps = count($this->batches ?? []);
|
||||
$data->currentStep = $this->currentBatch;
|
||||
$data->isComplete = $this->jobFinished();
|
||||
$data->messages = $this->messages;
|
||||
|
@ -91,7 +91,7 @@ class SearchUpdateQueuedJobProcessor extends SearchUpdateBatchedProcessor implem
|
|||
|
||||
public function addMessage($message, $severity = 'INFO')
|
||||
{
|
||||
$severity = strtoupper($severity);
|
||||
$severity = strtoupper($severity ?? '');
|
||||
$this->messages[] = '[' . date('Y-m-d H:i:s') . "][$severity] $message";
|
||||
}
|
||||
|
||||
|
|
|
@ -284,81 +284,81 @@ class SearchQuery extends ViewableData
|
|||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use addSearchTerm() instead
|
||||
*/
|
||||
public function search($text, $fields = null, $boost = [])
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use addSearchTerm() instead');
|
||||
Deprecation::notice('4.0.0', 'Use addSearchTerm() instead');
|
||||
return $this->addSearchTerm($text, $fields, $boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use addFuzzySearchTerm() instead
|
||||
*/
|
||||
public function fuzzysearch($text, $fields = null, $boost = [])
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use addFuzzySearchTerm() instead');
|
||||
Deprecation::notice('4.0.0', 'Use addFuzzySearchTerm() instead');
|
||||
return $this->addFuzzySearchTerm($text, $fields, $boost);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use addClassFilter() instead
|
||||
*/
|
||||
public function inClass($class, $includeSubclasses = true)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use addClassFilter() instead');
|
||||
Deprecation::notice('4.0.0', 'Use addClassFilter() instead');
|
||||
return $this->addClassFilter($class, $includeSubclasses);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use addFilter() instead
|
||||
*/
|
||||
public function filter($field, $values)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use addFilter() instead');
|
||||
Deprecation::notice('4.0.0', 'Use addFilter() instead');
|
||||
return $this->addFilter($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use addExclude() instead
|
||||
*/
|
||||
public function exclude($field, $values)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use addExclude() instead');
|
||||
Deprecation::notice('4.0.0', 'Use addExclude() instead');
|
||||
return $this->addExclude($field, $values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use setStart() instead
|
||||
*/
|
||||
public function start($start)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use setStart() instead');
|
||||
Deprecation::notice('4.0.0', 'Use setStart() instead');
|
||||
return $this->setStart($start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use setLimit() instead
|
||||
*/
|
||||
public function limit($limit)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use setLimit() instead');
|
||||
Deprecation::notice('4.0.0', 'Use setLimit() instead');
|
||||
return $this->setLimit($limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use setPageSize() instead
|
||||
*/
|
||||
public function page($page)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use setPageSize() instead');
|
||||
Deprecation::notice('4.0.0', 'Use setPageSize() instead');
|
||||
return $this->setPageSize($page);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,22 +40,22 @@ class SearchQuery_Range
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use setStart() instead
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function start($start)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use setStart() instead');
|
||||
Deprecation::notice('4.0.0', 'Use setStart() instead');
|
||||
return $this->setStart($start);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated 4.0.0 Use setEnd() instead
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function end($end)
|
||||
{
|
||||
Deprecation::notice('4.0', 'Use setEnd() instead');
|
||||
Deprecation::notice('4.0.0', 'Use setEnd() instead');
|
||||
return $this->setEnd($end);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class SearchIntrospection
|
|||
public static function is_subclass_of($class, $of)
|
||||
{
|
||||
$ancestry = isset(self::$ancestry[$class]) ? self::$ancestry[$class] : (self::$ancestry[$class] = ClassInfo::ancestry($class));
|
||||
return is_array($of) ? (bool)array_intersect($of, $ancestry) : array_key_exists($of, $ancestry);
|
||||
return is_array($of) ? (bool)array_intersect($of, $ancestry) : array_key_exists($of, $ancestry ?? []);
|
||||
}
|
||||
|
||||
protected static $hierarchy = array();
|
||||
|
@ -40,12 +40,12 @@ class SearchIntrospection
|
|||
$key = "$class!" . ($includeSubclasses ? 'sc' : 'an') . '!' . ($dataOnly ? 'do' : 'al');
|
||||
|
||||
if (!isset(self::$hierarchy[$key])) {
|
||||
$classes = array_values(ClassInfo::ancestry($class));
|
||||
$classes = array_values(ClassInfo::ancestry($class) ?? []);
|
||||
if ($includeSubclasses) {
|
||||
$classes = array_unique(array_merge($classes, array_values(ClassInfo::subclassesFor($class))));
|
||||
$classes = array_unique(array_merge($classes, array_values(ClassInfo::subclassesFor($class) ?? [])));
|
||||
}
|
||||
|
||||
$idx = array_search(DataObject::class, $classes);
|
||||
$idx = array_search(DataObject::class, $classes ?? []);
|
||||
if ($idx !== false) {
|
||||
array_splice($classes, 0, $idx+1);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class SearchIntrospection
|
|||
|
||||
// Strip out any subclasses of $class already in the list
|
||||
$children = ClassInfo::subclassesFor($class);
|
||||
$list = array_diff($list, $children);
|
||||
$list = array_diff($list ?? [], $children);
|
||||
|
||||
// Then add the class in
|
||||
$list[] = $class;
|
||||
|
|
|
@ -151,12 +151,12 @@ class SearchableService
|
|||
// Anonymous member canView() for indexing
|
||||
if (!$this->classSkipsCanViewCheck($objClass)) {
|
||||
$value = Member::actAs(null, function () use ($obj) {
|
||||
return $obj->canView();
|
||||
return (bool) $obj->canView();
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Current member canView() check for retrieving search results
|
||||
$value = $obj->canView();
|
||||
$value = (bool) $obj->canView();
|
||||
}
|
||||
}
|
||||
$this->extend('updateIsSearchable', $obj, $indexing, $value);
|
||||
|
@ -199,11 +199,11 @@ class SearchableService
|
|||
if (empty($skipClasses)) {
|
||||
return false;
|
||||
}
|
||||
if (in_array($class, $skipClasses)) {
|
||||
if (in_array($class, $skipClasses ?? [])) {
|
||||
return true;
|
||||
}
|
||||
foreach ($skipClasses as $skipClass) {
|
||||
if (in_array($skipClass, class_parents($class))) {
|
||||
if (in_array($skipClass, class_parents($class) ?? [])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ class SearchUpdater
|
|||
'command' => $command,
|
||||
'fields' => array()
|
||||
);
|
||||
} elseif (is_subclass_of($class, $writes[$key]['class'])) {
|
||||
} elseif (is_subclass_of($class, $writes[$key]['class'] ?? '')) {
|
||||
// Otherwise update the class label if it's more specific than the currently recorded one
|
||||
$writes[$key]['class'] = $class;
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ class SearchUpdater
|
|||
}
|
||||
|
||||
// Trim non-delete records without fields
|
||||
foreach (array_keys($writes) as $key) {
|
||||
foreach (array_keys($writes ?? []) as $key) {
|
||||
if ($writes[$key]['command'] !== 'delete' && empty($writes[$key]['fields'])) {
|
||||
unset($writes[$key]);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,9 @@ abstract class SearchVariant
|
|||
$ref = new ReflectionClass($variantclass);
|
||||
if ($ref->isInstantiable()) {
|
||||
$variant = singleton($variantclass);
|
||||
// reassign actual class since Injector could be involved when creating the singleton
|
||||
$variantclass = get_class($variant);
|
||||
|
||||
if ($variant->appliesToEnvironment()) {
|
||||
$concrete[$variantclass] = $variant;
|
||||
}
|
||||
|
@ -202,7 +205,7 @@ abstract class SearchVariant
|
|||
// Merge the variants applicable to the current class into the list of common variants, using
|
||||
// the variant instance to replace any previous versions for the same class name (should be singleton
|
||||
// anyway).
|
||||
$commonVariants = array_replace($commonVariants, $variantsForClass);
|
||||
$commonVariants = array_replace($commonVariants ?? [], $variantsForClass);
|
||||
}
|
||||
|
||||
// Cache for future calls
|
||||
|
@ -322,7 +325,7 @@ abstract class SearchVariant
|
|||
$merged = array_values(array_unique(array_merge($left, $right)));
|
||||
|
||||
// If there is only one item, return it as a single string
|
||||
if (count($merged) === 1) {
|
||||
if (count($merged ?? []) === 1) {
|
||||
return reset($merged);
|
||||
}
|
||||
return $merged;
|
||||
|
|
|
@ -65,7 +65,7 @@ class SearchVariantVersioned extends SearchVariant
|
|||
$class = $details['class'];
|
||||
$stage = Versioned::DRAFT;
|
||||
|
||||
if (preg_match('/^(.*)_' . Versioned::LIVE . '$/', $table, $matches)) {
|
||||
if (preg_match('/^(.*)_' . Versioned::LIVE . '$/', $table ?? '', $matches)) {
|
||||
$class = DataObject::getSchema()->tableClass($matches[1]);
|
||||
$stage = Versioned::LIVE;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class SearchVariant_Caller
|
|||
$values = array();
|
||||
|
||||
foreach ($this->variants as $variant) {
|
||||
if (method_exists($variant, $method)) {
|
||||
if (method_exists($variant, $method ?? '')) {
|
||||
$value = $variant->$method(...$args);
|
||||
if ($value !== null) {
|
||||
$values[] = $value;
|
||||
|
|
|
@ -81,9 +81,9 @@ abstract class SolrReindexBase implements SolrReindexHandler
|
|||
|
||||
// Apply filter
|
||||
if (!is_array($filterClasses)) {
|
||||
$filterClasses = explode(',', $filterClasses);
|
||||
$filterClasses = explode(',', $filterClasses ?? '');
|
||||
}
|
||||
return array_intersect_key($classes, array_combine($filterClasses, $filterClasses));
|
||||
return array_intersect_key($classes ?? [], array_combine($filterClasses ?? [], $filterClasses ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,27 +77,26 @@ class SolrReindexImmediateHandler extends SolrReindexBase
|
|||
$indexClass = get_class($indexInstance);
|
||||
|
||||
// Build script parameters
|
||||
$indexClassEscaped = $indexClass;
|
||||
$statevar = json_encode($state);
|
||||
|
||||
if (strpos(PHP_OS, "WIN") !== false) {
|
||||
$statevar = '"' . str_replace('"', '\\"', $statevar) . '"';
|
||||
} else {
|
||||
$statevar = "'" . $statevar . "'";
|
||||
$class = addslashes($class);
|
||||
$indexClassEscaped = addslashes($indexClass);
|
||||
}
|
||||
|
||||
$php = Environment::getEnv('SS_PHP_BIN') ?: Config::inst()->get(static::class, 'php_bin');
|
||||
|
||||
// Build script line
|
||||
$frameworkPath = ModuleLoader::getModule('silverstripe/framework')->getPath();
|
||||
$scriptPath = sprintf("%s%scli-script.php", $frameworkPath, DIRECTORY_SEPARATOR);
|
||||
$scriptTask = "{$php} {$scriptPath} dev/tasks/{$taskName}";
|
||||
|
||||
$cmd = "{$scriptTask} index={$indexClassEscaped} class={$class} group={$group} groups={$groups} variantstate={$statevar}";
|
||||
$cmd .= " verbose=1";
|
||||
$logger->info("Running '$cmd'");
|
||||
$cmd = [
|
||||
$php,
|
||||
$scriptPath,
|
||||
"dev/tasks/{$taskName}",
|
||||
"index={$indexClass}",
|
||||
"class={$class}",
|
||||
"group={$group}",
|
||||
"groups={$groups}",
|
||||
"variantstate={$statevar}",
|
||||
"verbose=1"
|
||||
];
|
||||
$logger->info('Running ' . implode(' ', $cmd));
|
||||
|
||||
// Execute script via shell
|
||||
$process = new Process($cmd);
|
||||
|
@ -110,7 +109,7 @@ class SolrReindexImmediateHandler extends SolrReindexBase
|
|||
|
||||
$res = $process->getOutput();
|
||||
if ($logger) {
|
||||
$logger->info(preg_replace('/\r\n|\n/', '$0 ', $res));
|
||||
$logger->info(preg_replace('/\r\n|\n/', '$0 ', $res ?? ''));
|
||||
}
|
||||
|
||||
// If we're in dev mode, commit more often for fun and profit
|
||||
|
|
|
@ -24,7 +24,7 @@ class SolrService extends SolrService_Core
|
|||
*/
|
||||
protected function coreCommand($command, $core, $params = array())
|
||||
{
|
||||
$command = strtoupper($command);
|
||||
$command = strtoupper($command ?? '');
|
||||
$params = array_merge($params, array('action' => $command, 'wt' => 'json'));
|
||||
$params[$command === 'CREATE' ? 'name' : 'core'] = $core;
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ class Solr
|
|||
$module = ModuleLoader::getModule('silverstripe/fulltextsearch');
|
||||
$modulePath = $module->getPath();
|
||||
|
||||
if (version_compare($version, '4', '>=')) {
|
||||
if (version_compare($version ?? '', '4', '>=')) {
|
||||
$versionDefaults = [
|
||||
'service' => Solr4Service::class,
|
||||
'extraspath' => $modulePath . '/conf/solr/4/extras/',
|
||||
|
|
|
@ -89,7 +89,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
{
|
||||
$globalOptions = Solr::solr_options();
|
||||
$path = $this->templatesPath ? $this->templatesPath : $globalOptions['templatespath'];
|
||||
return rtrim($path, '/');
|
||||
return rtrim($path ?? '', '/');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -127,7 +127,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
$indexParts[] = $indexSuffix;
|
||||
}
|
||||
|
||||
return implode($indexParts);
|
||||
return implode($indexParts ?? '');
|
||||
}
|
||||
|
||||
public function getTypes()
|
||||
|
@ -256,11 +256,11 @@ abstract class SolrIndex extends SearchIndex
|
|||
*/
|
||||
protected function getNiceSuggestion($collation = '')
|
||||
{
|
||||
$collationParts = explode(' ', $collation);
|
||||
$collationParts = explode(' ', $collation ?? '');
|
||||
|
||||
// Remove advanced query params from the beginning of each collation part.
|
||||
foreach ($collationParts as $key => &$part) {
|
||||
$part = ltrim($part, '+');
|
||||
$part = ltrim($part ?? '', '+');
|
||||
}
|
||||
|
||||
return implode(' ', $collationParts);
|
||||
|
@ -275,7 +275,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
*/
|
||||
protected function getSuggestionQueryString($collation = '')
|
||||
{
|
||||
return str_replace(' ', '+', $this->getNiceSuggestion($collation));
|
||||
return str_replace(' ', '+', $this->getNiceSuggestion($collation) ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -312,7 +312,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
{
|
||||
// Ensure that 'boost' is recorded here without being captured by solr
|
||||
$boost = null;
|
||||
if (array_key_exists('boost', $extraOptions)) {
|
||||
if (array_key_exists('boost', $extraOptions ?? [])) {
|
||||
$boost = $extraOptions['boost'];
|
||||
unset($extraOptions['boost']);
|
||||
}
|
||||
|
@ -515,7 +515,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
}
|
||||
|
||||
// Check single origin
|
||||
return $class === $base || is_subclass_of($class, $base);
|
||||
return $class === $base || is_subclass_of($class, $base ?? '');
|
||||
}
|
||||
|
||||
protected function _addField($doc, $object, $field)
|
||||
|
@ -536,7 +536,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
if (!$sub) {
|
||||
continue;
|
||||
}
|
||||
$sub = gmdate('Y-m-d\TH:i:s\Z', strtotime($sub));
|
||||
$sub = gmdate('Y-m-d\TH:i:s\Z', strtotime($sub ?? ''));
|
||||
}
|
||||
|
||||
/* Solr requires numbers to be valid if presented, not just empty */
|
||||
|
@ -552,7 +552,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
if (!$value) {
|
||||
return;
|
||||
}
|
||||
$value = gmdate('Y-m-d\TH:i:s\Z', strtotime($value));
|
||||
$value = gmdate('Y-m-d\TH:i:s\Z', strtotime($value ?? ''));
|
||||
}
|
||||
|
||||
/* Solr requires numbers to be valid if presented, not just empty */
|
||||
|
@ -586,7 +586,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
// Add the user-specified fields
|
||||
|
||||
foreach ($this->getFieldsIterator() as $name => $field) {
|
||||
if ($field['base'] === $base || (is_array($field['base']) && in_array($base, $field['base']))) {
|
||||
if ($field['base'] === $base || (is_array($field['base']) && in_array($base, $field['base'] ?? []))) {
|
||||
$this->_addField($doc, $object, $field);
|
||||
}
|
||||
}
|
||||
|
@ -607,7 +607,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
$docs = array();
|
||||
|
||||
foreach ($this->getClasses() as $searchclass => $options) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass))) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass ?? ''))) {
|
||||
$base = DataObject::getSchema()->baseDataClass($searchclass);
|
||||
$docs[] = $this->_addAs($object, $base, $options);
|
||||
}
|
||||
|
@ -619,7 +619,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
public function canAdd($class)
|
||||
{
|
||||
foreach ($this->classes as $searchclass => $options) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass))) {
|
||||
if ($searchclass == $class || ($options['include_children'] && is_subclass_of($class, $searchclass ?? ''))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -713,7 +713,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
|
||||
// If using boosting, set the clean term separately for highlighting.
|
||||
// See https://issues.apache.org/jira/browse/SOLR-2632
|
||||
if (array_key_exists('hl', $params) && !array_key_exists('hl.q', $params)) {
|
||||
if (array_key_exists('hl', $params ?? []) && !array_key_exists('hl.q', $params ?? [])) {
|
||||
$params['hl.q'] = implode(' ', $hlq);
|
||||
}
|
||||
|
||||
|
@ -870,7 +870,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
*/
|
||||
protected function applySearchVariants(SearchQuery $query)
|
||||
{
|
||||
$classes = count($query->classes) ? $query->classes : $this->getClasses();
|
||||
$classes = count($query->classes ?? []) ? $query->classes : $this->getClasses();
|
||||
|
||||
/** @var SearchVariant_Caller $variantCaller */
|
||||
$variantCaller = SearchVariant::withCommon($classes);
|
||||
|
@ -886,7 +886,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
*/
|
||||
public function sanitiseClassName($className, $replaceWith = '\\\\')
|
||||
{
|
||||
return str_replace('\\', $replaceWith, $className);
|
||||
return str_replace('\\', $replaceWith ?? '', $className ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -901,14 +901,14 @@ abstract class SolrIndex extends SearchIndex
|
|||
$q = array();
|
||||
foreach ($searchQuery->search as $search) {
|
||||
$text = $search['text'];
|
||||
preg_match_all('/"[^"]*"|\S+/', $text, $parts);
|
||||
preg_match_all('/"[^"]*"|\S+/', $text ?? '', $parts);
|
||||
|
||||
$fuzzy = $search['fuzzy'] ? '~' : '';
|
||||
|
||||
foreach ($parts[0] as $part) {
|
||||
$fields = (isset($search['fields'])) ? $search['fields'] : array();
|
||||
if (isset($search['boost'])) {
|
||||
$fields = array_merge($fields, array_keys($search['boost']));
|
||||
$fields = array_merge($fields, array_keys($search['boost'] ?? []));
|
||||
}
|
||||
if ($fields) {
|
||||
$searchq = array();
|
||||
|
@ -1014,7 +1014,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
*/
|
||||
protected function getCriteriaComponent(SearchQuery $searchQuery)
|
||||
{
|
||||
if (count($searchQuery->getCriteria()) === 0) {
|
||||
if (count($searchQuery->getCriteria() ?? []) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1095,7 +1095,7 @@ abstract class SolrIndex extends SearchIndex
|
|||
|
||||
// Upload additional files
|
||||
foreach (glob($this->getExtrasPath() . '/*') as $file) {
|
||||
if (is_file($file)) {
|
||||
if (is_file($file ?? '')) {
|
||||
$store->uploadFile($this->getIndexName(), $file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ class SolrConfigStore_File implements SolrConfigStore
|
|||
{
|
||||
$targetDir = "{$this->local}/{$index}/conf";
|
||||
|
||||
if (!is_dir($targetDir)) {
|
||||
$worked = @mkdir($targetDir, 0770, true);
|
||||
if (!is_dir($targetDir ?? '')) {
|
||||
$worked = @mkdir($targetDir ?? '', 0770, true);
|
||||
|
||||
if (!$worked) {
|
||||
throw new \RuntimeException(
|
||||
|
@ -36,7 +36,7 @@ class SolrConfigStore_File implements SolrConfigStore
|
|||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
copy($file, $targetDir . '/' . basename($file));
|
||||
copy($file ?? '', $targetDir . '/' . basename($file ?? ''));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
|
|
|
@ -43,7 +43,7 @@ class SolrConfigStore_Post implements SolrConfigStore
|
|||
*/
|
||||
public function uploadFile($index, $file)
|
||||
{
|
||||
$this->uploadString($index, basename($file), file_get_contents($file));
|
||||
$this->uploadString($index, basename($file ?? ''), file_get_contents($file ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,7 +46,7 @@ class SolrConfigStore_WebDAV implements SolrConfigStore
|
|||
public function uploadFile($index, $file)
|
||||
{
|
||||
$targetDir = $this->getTargetDir($index);
|
||||
WebDAV::upload_from_file($file, $targetDir . '/' . basename($file));
|
||||
WebDAV::upload_from_file($file, $targetDir . '/' . basename($file ?? ''));
|
||||
}
|
||||
|
||||
public function uploadString($index, $filename, $string)
|
||||
|
|
|
@ -86,7 +86,7 @@ class Solr_Reindex extends Solr_BuildTask
|
|||
continue;
|
||||
}
|
||||
//check the indexname matches the index passed to the request
|
||||
if (!strcasecmp(singleton($solrIndexClass)->getIndexName(), $index)) {
|
||||
if (!strcasecmp(singleton($solrIndexClass)->getIndexName() ?? '', $index ?? '')) {
|
||||
//if we match, set the correct index name and move on
|
||||
$index = $solrIndexClass;
|
||||
break;
|
||||
|
@ -104,7 +104,7 @@ class Solr_Reindex extends Solr_BuildTask
|
|||
// Run grouped batches (id % groups = group)
|
||||
$group = $request->getVar('group');
|
||||
$indexInstance = singleton($index);
|
||||
$state = json_decode($request->getVar('variantstate'), true);
|
||||
$state = json_decode($request->getVar('variantstate') ?? '', true);
|
||||
|
||||
$handler->runGroup($this->getLogger(), $indexInstance, $state, $class, $groups, $group);
|
||||
return;
|
||||
|
|
|
@ -20,7 +20,7 @@ class SolrSearchQueryWriterBasic extends AbstractSearchQueryWriter
|
|||
return sprintf(
|
||||
'%s(%s%s%s)',
|
||||
$this->getComparisonPolarity($searchCriterion->getComparison()),
|
||||
addslashes($searchCriterion->getTarget()),
|
||||
addslashes($searchCriterion->getTarget() ?? ''),
|
||||
$this->getComparisonConjunction(),
|
||||
$searchCriterion->getQuoteValue($searchCriterion->getValue())
|
||||
);
|
||||
|
|
|
@ -62,7 +62,7 @@ class SolrSearchQueryWriterIn extends AbstractSearchQueryWriter
|
|||
|
||||
$conditions[] = sprintf(
|
||||
'%s%s%s',
|
||||
addslashes($searchCriterion->getTarget()),
|
||||
addslashes($searchCriterion->getTarget() ?? ''),
|
||||
$this->getComparisonConjunction(),
|
||||
$value
|
||||
);
|
||||
|
|
|
@ -21,7 +21,7 @@ class SolrSearchQueryWriterRange extends AbstractSearchQueryWriter
|
|||
return sprintf(
|
||||
'%s(%s:%s%s%s%s%s)',
|
||||
$this->getComparisonPolarity($searchCriterion->getComparison()),
|
||||
addslashes($searchCriterion->getTarget()),
|
||||
addslashes($searchCriterion->getTarget() ?? ''),
|
||||
$this->getOpenComparisonContainer($searchCriterion->getComparison()),
|
||||
$this->getLeftComparison($searchCriterion),
|
||||
$this->getComparisonConjunction(),
|
||||
|
|
|
@ -18,20 +18,21 @@ class CombinationsArrayIterator implements Iterator
|
|||
$this->arrays = array();
|
||||
$this->keys = array();
|
||||
|
||||
$keys = array_keys($args);
|
||||
$values = array_values($args);
|
||||
$keys = array_keys($args ?? []);
|
||||
$values = array_values($args ?? []);
|
||||
|
||||
foreach ($values as $i => $arg) {
|
||||
if (is_array($arg) && count($arg)) {
|
||||
if (is_array($arg) && count($arg ?? [])) {
|
||||
$this->arrays[] = $arg;
|
||||
$this->keys[] = $keys[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$this->numArrays = count($this->arrays);
|
||||
$this->numArrays = count($this->arrays ?? []);
|
||||
$this->rewind();
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
if (!$this->numArrays) {
|
||||
|
@ -46,11 +47,13 @@ class CombinationsArrayIterator implements Iterator
|
|||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
$this->k++;
|
||||
|
@ -68,15 +71,17 @@ class CombinationsArrayIterator implements Iterator
|
|||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
$res = array();
|
||||
for ($i = 0; $i < $this->numArrays; $i++) {
|
||||
$res[$this->keys[$i]] = current($this->arrays[$i]);
|
||||
$res[$this->keys[$i]] = current($this->arrays[$i] ?? []);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return $this->k;
|
||||
|
|
|
@ -90,7 +90,7 @@ class MonologFactory implements SearchLogFactory
|
|||
{
|
||||
return Injector::inst()->createWithArgs(
|
||||
Logger::class,
|
||||
array(strtolower($name))
|
||||
array(strtolower($name ?? ''))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class MultipleArrayIterator implements Iterator
|
|||
|
||||
$this->arrays = array();
|
||||
foreach ($args as $arg) {
|
||||
if (is_array($arg) && count($arg)) {
|
||||
if (is_array($arg) && count($arg ?? [])) {
|
||||
$this->arrays[] = $arg;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ class MultipleArrayIterator implements Iterator
|
|||
$this->rewind();
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function rewind()
|
||||
{
|
||||
$this->active = $this->arrays;
|
||||
|
@ -30,16 +31,19 @@ class MultipleArrayIterator implements Iterator
|
|||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
{
|
||||
return $this->active ? current($this->active[0]) : false;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return $this->active ? key($this->active[0]) : false;
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function next()
|
||||
{
|
||||
if (!$this->active) {
|
||||
|
@ -54,8 +58,9 @@ class MultipleArrayIterator implements Iterator
|
|||
}
|
||||
}
|
||||
|
||||
#[\ReturnTypeWillChange]
|
||||
public function valid()
|
||||
{
|
||||
return $this->active && (current($this->active[0]) !== false);
|
||||
return $this->active && (current($this->active[0] ?? []) !== false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,15 +17,19 @@ class WebDAV
|
|||
public static function exists($url)
|
||||
{
|
||||
// WebDAV expects that checking a directory exists has a trailing slash
|
||||
if (substr($url, -1) != '/') {
|
||||
if (substr($url ?? '', -1) != '/') {
|
||||
$url .= '/';
|
||||
}
|
||||
|
||||
$ch = self::curl_init($url, 'PROPFIND');
|
||||
|
||||
$res = curl_exec($ch);
|
||||
curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
$err = curl_error($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
if ($code == 404) {
|
||||
return false;
|
||||
}
|
||||
|
@ -33,15 +37,16 @@ class WebDAV
|
|||
return true;
|
||||
}
|
||||
|
||||
user_error("Got error from webdav server - " . $code, E_USER_ERROR);
|
||||
user_error("Got error from webdav server - " . $err, E_USER_ERROR);
|
||||
}
|
||||
|
||||
public static function mkdir($url)
|
||||
{
|
||||
$ch = self::curl_init(rtrim($url, '/') . '/', 'MKCOL');
|
||||
$ch = self::curl_init(rtrim($url ?? '', '/') . '/', 'MKCOL');
|
||||
|
||||
$res = curl_exec($ch);
|
||||
curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return $code == 201;
|
||||
}
|
||||
|
@ -56,22 +61,24 @@ class WebDAV
|
|||
|
||||
curl_setopt($ch, CURLOPT_INFILE, $handle);
|
||||
|
||||
$res = curl_exec($ch);
|
||||
curl_exec($ch);
|
||||
fclose($handle);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
return $code;
|
||||
}
|
||||
|
||||
public static function upload_from_string($string, $url)
|
||||
{
|
||||
$fh = tmpfile();
|
||||
fwrite($fh, $string);
|
||||
fwrite($fh, $string ?? '');
|
||||
fseek($fh, 0);
|
||||
return self::put($fh, $url);
|
||||
}
|
||||
|
||||
public static function upload_from_file($string, $url)
|
||||
{
|
||||
return self::put(fopen($string, 'rb'), $url);
|
||||
return self::put(fopen($string ?? '', 'rb'), $url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ class BatchedProcessorTest extends SapphireTest
|
|||
$processor->addDirtyIDs(
|
||||
BatchedProcessorTest_Object::class,
|
||||
array(array(
|
||||
'id' => $id,
|
||||
'id' => $object->ID,
|
||||
'state' => array(SearchVariantVersioned::class => 'Stage')
|
||||
)),
|
||||
BatchedProcessorTest_Index::class
|
||||
|
@ -133,28 +133,28 @@ class BatchedProcessorTest extends SapphireTest
|
|||
$this->assertEquals(9, $data->totalSteps);
|
||||
$this->assertEquals(0, $data->currentStep);
|
||||
$this->assertEmpty($data->isComplete);
|
||||
$this->assertEquals(0, count($index->getAdded()));
|
||||
$this->assertEquals(0, count($index->getAdded() ?? []));
|
||||
|
||||
// Advance state
|
||||
for ($pass = 1; $pass <= 8; $pass++) {
|
||||
$processor->process();
|
||||
$data = $processor->getJobData();
|
||||
$this->assertEquals($pass, $data->currentStep);
|
||||
$this->assertEquals($pass * 5, count($index->getAdded()));
|
||||
$this->assertEquals($pass * 5, count($index->getAdded() ?? []));
|
||||
}
|
||||
|
||||
// Last run should have two hanging items
|
||||
$processor->process();
|
||||
$data = $processor->getJobData();
|
||||
$this->assertEquals(9, $data->currentStep);
|
||||
$this->assertEquals(42, count($index->getAdded()));
|
||||
$this->assertEquals(42, count($index->getAdded() ?? []));
|
||||
$this->assertTrue($data->isComplete);
|
||||
|
||||
// Check any additional queued jobs
|
||||
$processor->afterComplete();
|
||||
$service = singleton(QueuedJobService::class);
|
||||
$jobs = $service->getJobs();
|
||||
$this->assertEquals(1, count($jobs));
|
||||
$this->assertEquals(1, count($jobs ?? []));
|
||||
$this->assertInstanceOf(SearchUpdateCommitJobProcessor::class, $jobs[0]['job']);
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ class BatchedProcessorTest extends SapphireTest
|
|||
}
|
||||
$data = $processor->getJobData();
|
||||
$this->assertEquals(8, $data->currentStep);
|
||||
$this->assertEquals(42, count($index->getAdded()));
|
||||
$this->assertEquals(42, count($index->getAdded() ?? []));
|
||||
$this->assertTrue($data->isComplete);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class SearchVariantSubsiteTest extends SapphireTest
|
|||
self::$index = singleton(static::class);
|
||||
}
|
||||
|
||||
Config::inst()->update(Injector::class, SearchUpdateProcessor::class, [
|
||||
Config::inst()->merge(Injector::class, SearchUpdateProcessor::class, [
|
||||
'class' => SearchUpdateImmediateProcessor::class
|
||||
]);
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ class SolrIndexSubsitesTest extends SapphireTest
|
|||
$subsiteIDs = ['0'] + $this->allFixtureIDs(Subsite::class);
|
||||
$subsiteIDs = array_map(function ($v) {
|
||||
return (string) $v;
|
||||
}, $subsiteIDs);
|
||||
}, $subsiteIDs ?? []);
|
||||
$mockWrites = [
|
||||
'35910:File:a:0:{}' => [
|
||||
'base' => File::class,
|
||||
|
@ -253,7 +253,7 @@ class SolrIndexSubsitesTest extends SapphireTest
|
|||
$tmpMockWrites = $mockWrites;
|
||||
$variant->extractManipulationWriteState($tmpMockWrites);
|
||||
foreach ($tmpMockWrites as $mockWrite) {
|
||||
$this->assertCount(count($subsiteIDs), $mockWrite['statefulids']);
|
||||
$this->assertCount(count($subsiteIDs ?? []), $mockWrite['statefulids']);
|
||||
foreach ($mockWrite['statefulids'] as $statefulIDs) {
|
||||
$this->assertContains(
|
||||
(string) $statefulIDs['state'][SearchVariantSubsites::class],
|
||||
|
|
|
@ -478,7 +478,7 @@ class SolrIndexTest extends SapphireTest
|
|||
SolrIndexTest_MyDataObjectOne::class . $objOneA->ID,
|
||||
SolrIndexTest_MyDataObjectTwo::class . $objTwoA->ID
|
||||
];
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys);
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys ?? []);
|
||||
};
|
||||
|
||||
$serviceMock
|
||||
|
@ -504,7 +504,7 @@ class SolrIndexTest extends SapphireTest
|
|||
->method('deleteById')
|
||||
->withConsecutive(
|
||||
[$this->callback(function (string $docID) use ($pageA): bool {
|
||||
return strpos($docID, $pageA->ID . '-' . SiteTree::class) !== false;
|
||||
return strpos($docID ?? '', $pageA->ID . '-' . SiteTree::class) !== false;
|
||||
})]
|
||||
);
|
||||
|
||||
|
@ -578,7 +578,7 @@ class SolrIndexTest extends SapphireTest
|
|||
File::class . $fileA->ID,
|
||||
SolrIndexTest_MyDataObjectOne::class . $objOneA->ID
|
||||
];
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys);
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys ?? []);
|
||||
};
|
||||
|
||||
$serviceMock
|
||||
|
@ -602,7 +602,7 @@ class SolrIndexTest extends SapphireTest
|
|||
->method('deleteById')
|
||||
->withConsecutive(
|
||||
[$this->callback(function (string $docID) use ($pageA): bool {
|
||||
return strpos($docID, $pageA->ID . '-' . SiteTree::class) !== false;
|
||||
return strpos($docID ?? '', $pageA->ID . '-' . SiteTree::class) !== false;
|
||||
})]
|
||||
);
|
||||
|
||||
|
|
|
@ -233,9 +233,9 @@ class SolrReindexQueuedTest extends SapphireTest
|
|||
|
||||
// Check IDs
|
||||
$idMessage = $logger->filterMessages('Updated ');
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/i', $idMessage[0], $matches));
|
||||
$ids = array_unique(explode(',', $matches['ids']));
|
||||
$this->assertEquals(6, count($ids));
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/i', $idMessage[0] ?? '', $matches));
|
||||
$ids = array_unique(explode(',', $matches['ids'] ?? ''));
|
||||
$this->assertEquals(6, count($ids ?? []));
|
||||
foreach ($ids as $id) {
|
||||
// Each id should be % 3 == 0
|
||||
$this->assertEquals(0, $id % 3, "ID $id Should match pattern ID % 3 = 0");
|
||||
|
|
|
@ -250,8 +250,8 @@ class SolrReindexTest extends SapphireTest
|
|||
$state = array(SolrReindexTest_Variant::class => '1');
|
||||
$this->getHandler()->runGroup($logger, $this->index, $state, SolrReindexTest_Item::class, 6, 2);
|
||||
$idMessage = $logger->filterMessages('Updated ');
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/i', $idMessage[0], $matches));
|
||||
$ids = array_unique(explode(',', $matches['ids']));
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/i', $idMessage[0] ?? '', $matches));
|
||||
$ids = array_unique(explode(',', $matches['ids'] ?? ''));
|
||||
|
||||
// Test successful
|
||||
$this->assertNotEmpty($logger->getMessages('Adding ' . SolrReindexTest_Item::class));
|
||||
|
@ -259,7 +259,7 @@ class SolrReindexTest extends SapphireTest
|
|||
|
||||
// Test that items in this variant / group are re-indexed
|
||||
// 120 divided into 6 groups should be 20 at least (max 21)
|
||||
$c = count($ids);
|
||||
$c = count($ids ?? []);
|
||||
$this->assertTrue($c === 20 || $c === 21, 'Group size is about 20');
|
||||
foreach ($ids as $id) {
|
||||
// Each id should be % 6 == 2
|
||||
|
@ -301,12 +301,12 @@ class SolrReindexTest extends SapphireTest
|
|||
// Count all ids updated
|
||||
$ids = array();
|
||||
foreach ($logger->filterMessages('Updated ') as $message) {
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/', $message, $matches));
|
||||
$ids = array_unique(array_merge($ids, explode(',', $matches['ids'])));
|
||||
$this->assertNotEmpty(preg_match('/^Updated (?<ids>[,\d]+)/', $message ?? '', $matches));
|
||||
$ids = array_unique(array_merge($ids, explode(',', $matches['ids'] ?? '')));
|
||||
}
|
||||
|
||||
// Check ids
|
||||
$this->assertEquals(120, count($ids));
|
||||
$this->assertEquals(120, count($ids ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -385,7 +385,7 @@ class SolrReindexTest extends SapphireTest
|
|||
SolrIndexTest_MyDataObjectOne::class . $objOneA->ID,
|
||||
SolrIndexTest_MyDataObjectTwo::class . $objTwoA->ID
|
||||
];
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys);
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys ?? []);
|
||||
};
|
||||
|
||||
$serviceMock
|
||||
|
@ -470,7 +470,7 @@ class SolrReindexTest extends SapphireTest
|
|||
SolrIndexTest_MyDataObjectOne::class . $objOneA->ID,
|
||||
];
|
||||
$solrDocKey = $this->createSolrDocKey($doc);
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys);
|
||||
return in_array($this->createSolrDocKey($doc), $validKeys ?? []);
|
||||
};
|
||||
|
||||
$serviceMock
|
||||
|
|
|
@ -49,9 +49,9 @@ class SolrReindexTest_RecordingLogger extends Logger implements TestOnly
|
|||
public function filterMessages($containing)
|
||||
{
|
||||
return array_values(array_filter(
|
||||
$this->getMessages(),
|
||||
$this->getMessages() ?? [],
|
||||
function ($content) use ($containing) {
|
||||
return stripos($content, $containing) !== false;
|
||||
return stripos($content ?? '', $containing ?? '') !== false;
|
||||
}
|
||||
));
|
||||
}
|
||||
|
@ -69,6 +69,6 @@ class SolrReindexTest_RecordingLogger extends Logger implements TestOnly
|
|||
} else {
|
||||
$messages = $this->getMessages();
|
||||
}
|
||||
return count($messages);
|
||||
return count($messages ?? []);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ class SolrWritersTest extends SapphireTest
|
|||
|
||||
$index = new SolrIndexTest_FakeIndex();
|
||||
|
||||
$this->assertTrue(in_array($expected, $index->getFiltersComponent($query)));
|
||||
$this->assertTrue(in_array($expected, $index->getFiltersComponent($query) ?? []));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,6 +235,6 @@ class SolrWritersTest extends SapphireTest
|
|||
|
||||
$index = new SolrIndexTest_FakeIndex();
|
||||
|
||||
$this->assertTrue(in_array($expected, $index->getFiltersComponent($query)));
|
||||
$this->assertTrue(in_array($expected, $index->getFiltersComponent($query) ?? []));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user