Skip to content

Commit

Permalink
Merge branch 'develop' into release/5.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
felipeelia authored Apr 25, 2024
2 parents c740856 + bdf8738 commit b595118
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-with-vendor-prefixed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: npm run build:zip

- name: Make artifacts available
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Plugin Zip
retention-days: 2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/cypress-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
run: npm run cypress:run -- --env grepTags=${{ matrix.testGroup }}

- name: Make artifacts available
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-artifact-${{ matrix.core.name }}-${{ matrix.testGroup }}
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
run: npm run cypress:run -- --env grepTags=${{ matrix.testGroup }}

- name: Make artifacts available
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
if: failure()
with:
name: cypress-artifact-epio-${{ matrix.core.name }}-${{ matrix.testGroup }}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/status-report/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

& pre {
margin: 0;
overflow-x: scroll;
overflow-x: auto;
}
}
}
41 changes: 36 additions & 5 deletions assets/js/sync-ui/apps/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies.
*/
import { Panel, PanelBody } from '@wordpress/components';
import { useEffect, WPElement } from '@wordpress/element';
import { useEffect, useState, WPElement } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';

/**
Expand All @@ -27,16 +27,47 @@ import { useSyncSettings } from '../provider';
*/
export default () => {
const { createNotice } = useSettingsScreen();
const { isComplete, isEpio, isSyncing, logMessage, startSync, syncHistory, syncTrigger } =
useSync();
const {
errorCounts,
isComplete,
isEpio,
isSyncing,
logMessage,
startSync,
syncHistory,
syncTrigger,
} = useSync();
const { args, autoIndex } = useSyncSettings();

/**
* State.
*/
const [isLogOpen, setIsLogOpen] = useState(false);
const [errorCount, setErrorCount] = useState(0);

/**
* Handle toggling the log panel.
*
* @param {boolean} opened Whether the panel will be open.
*/
const onToggleLog = (opened) => {
setIsLogOpen(opened);
};

/**
* Handle a completed sync.
*/
const onComplete = () => {
if (isComplete) {
const newErrorCount = errorCounts.reduce((c, e) => c + e.count, 0);

createNotice('success', __('Sync completed.', 'elasticpress'));

if (newErrorCount > errorCount) {
setIsLogOpen(true);
}

setErrorCount(newErrorCount);
}
};

Expand Down Expand Up @@ -70,7 +101,7 @@ export default () => {
logMessage(__('Starting sync…', 'elasticpress'), 'info');
};

useEffect(onComplete, [createNotice, isComplete]);
useEffect(onComplete, [createNotice, errorCount, errorCounts, isComplete]);
useEffect(onInit, [autoIndex, logMessage, startSync, syncTrigger]);

return (
Expand Down Expand Up @@ -98,7 +129,7 @@ export default () => {
<Controls />
{syncHistory.length ? <PutMapping /> : null}
</PanelBody>
<PanelBody initialOpen={false} title="Log">
<PanelBody onToggle={onToggleLog} opened={isLogOpen} title="Log">
<Log />
</PanelBody>
{syncHistory.length ? (
Expand Down
6 changes: 5 additions & 1 deletion assets/js/sync-ui/components/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export default () => {

return (
<>
<TabPanel className="ep-sync-log" tabs={tabs}>
<TabPanel
className="ep-sync-log"
initialTabName={errorCount > 0 ? 'error' : 'full'}
tabs={tabs}
>
{({ name }) => {
switch (name) {
case 'full':
Expand Down
10 changes: 10 additions & 0 deletions includes/classes/ElasticsearchErrorInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public function maybe_suggest_solution_for_es( $error ) {
}

if ( Utils\is_epio() ) {
if ( preg_match( '/you have reached the limit of indices your plan supports/', $error, $matches ) ) {
return [
'error' => $error,
'solution' => sprintf(
/* translators: ElasticPress.io Article URL */
__( 'Please refer to <a href="%s">this article</a> outlining how to address this issue.', 'elasticpress' ),
'https://elasticpress.zendesk.com/hc/en-us/articles/26165267320461'
),
];
}
return [
'error' => $error,
'solution' => sprintf(
Expand Down
16 changes: 14 additions & 2 deletions includes/classes/IndexHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,10 @@ protected function on_error_update_and_clean( $error, $context = 'sync' ) {
esc_html__( 'Mapping failed: %s', 'elasticpress' ),
Utils\get_elasticsearch_error_reason( $error['message'] )
);
$message .= "\n";
$message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
if ( $this->should_suggest_retry( $message ) ) {
$message .= "\n";
$message .= esc_html__( 'Mapping has failed, which will cause ElasticPress search results to be incorrect. Please click `Delete all Data and Start a Fresh Sync` to retry mapping.', 'elasticpress' );
}
break;
default:
/* translators: Error message */
Expand Down Expand Up @@ -1523,6 +1525,16 @@ protected function maybe_apply_feature_settings() {
Features::factory()->apply_draft_feature_settings();
}

/**
* Whether to suggest retrying the sync or not.
*
* @param string $message The message returned by the hosting server
* @return boolean
*/
protected function should_suggest_retry( $message ) {
return ! preg_match( '/you have reached the limit of indices your plan supports/', $message );
}

/**
* Return singleton instance of class.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/cypress/integration/dashboard-sync.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ describe('Dashboard Sync', () => {
cy.contains('button', 'Log').click();
cy.contains('button', 'Errors').click();
cy.contains('.ep-sync-errors', 'No errors found in the log.').should('exist');

/**
* Reload the page, so we can check if the Error Log tab is opened by default when an error occurs.
*/
cy.visitAdminPage('admin.php?page=elasticpress-sync');
cy.contains('button', 'Start sync').click();
cy.get('.ep-sync-errors__table', {
timeout: Cypress.config('elasticPressIndexTimeout'),
}).should('be.visible');
cy.get('.ep-sync-errors tr', { timeout: Cypress.config('elasticPressIndexTimeout') })
.contains('Limit of total fields [???] in index [???] has been exceeded')
.should('exist');
Expand Down
22 changes: 20 additions & 2 deletions tests/cypress/wordpress-files/test-plugins/sync-error.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
* @package ElasticPress_Tests_E2e
*/

add_filter( 'ep_total_field_limit', fn() => 100 );
namespace ElasticPress\Tests\E2E\SyncError;

const META_COUNT = 100;

add_filter( 'ep_total_field_limit', fn() => META_COUNT );

add_filter(
'ep_prepare_meta_data',
function ( $post_meta, $post ) {
if ( 0 === $post->ID % 2 ) {
for ( $i = 0; $i < 100; $i++ ) {
for ( $i = 0; $i < META_COUNT; $i++ ) {
$post_meta[ "test_meta_{$i}_title_{$post->ID}" ] = 'Lorem';
$post_meta[ "test_meta_{$i}_body_{$post->ID}" ] = 'Ipsum';
}
Expand All @@ -25,3 +29,17 @@ function ( $post_meta, $post ) {
10,
2
);

add_filter(
'ep_prepare_meta_allowed_protected_keys',
function ( $allowed_meta, $post ) {
for ( $i = 0; $i < META_COUNT; $i++ ) {
$allowed_meta[] = "test_meta_{$i}_title_{$post->ID}";
$allowed_meta[] = "test_meta_{$i}_body_{$post->ID}";
}

return $allowed_meta;
},
10,
2
);
19 changes: 19 additions & 0 deletions tests/php/TestElasticsearchErrorInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,23 @@ public function test_maybe_suggest_solution_for_es_limit_fields() {
$this->assertSame( 'Limit of total fields [???] in index [???] has been exceeded', $suggested['error'] );
$this->assertSame( $solution, $suggested['solution'] );
}

/**
* Test the `maybe_suggest_solution_for_es` method when the indices limit was reached on EP.io
*
* @since 5.1.0
* @group elasticsearch-error-interpreter
*/
public function test_maybe_suggest_solution_for_es_limit_of_indices() {
$this->force_epio();

$error_interpreter = new ElasticsearchErrorInterpreter();

$error = 'It seems you have reached the limit of indices your plan supports and we were not able to create a new index. Currently, you can have up to 3 indices.';
$solution = 'Please refer to <a href="https://elasticpress.zendesk.com/hc/en-us/articles/26165267320461">this article</a> outlining how to address this issue.';
$suggested = $error_interpreter->maybe_suggest_solution_for_es( $error );

$this->assertSame( $error, $suggested['error'] );
$this->assertSame( $solution, $suggested['solution'] );
}
}
9 changes: 9 additions & 0 deletions tests/php/includes/classes/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,13 @@ public function assertDecayDisabled( $query ) {
)
);
}

/**
* Forces tests to use EP.io
*
* @since 5.1.0
*/
protected function force_epio() {
update_site_option( 'ep_host', 'https://prefix.elasticpress.io/' );
}
}

0 comments on commit b595118

Please sign in to comment.