Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DB update #3533

Merged
merged 4 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/api-import.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function route_plugin_import( WP_REST_Request $request ) {

public function route_import_file( WP_REST_Request $request ) {
$upload = $request->get_file_params();
$upload = isset( $upload['file'] ) ? sanitize_text_field( $upload['file'] ) : false;
$upload = isset( $upload['file'] ) ? $upload['file'] : false;
$group_id = intval( $request['group_id'], 10 );

if ( $upload && is_uploaded_file( $upload['tmp_name'] ) ) {
Expand Down
15 changes: 6 additions & 9 deletions client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/

import React from 'react';
import { Provider } from 'react-redux';

/**
Expand All @@ -26,12 +25,10 @@ apiFetch.resetMiddlewares();
apiFetch.use( apiFetch.createRootURLMiddleware( window.Redirectioni10n?.api?.WP_API_root ?? '/wp-json/' ) );
apiFetch.use( apiFetch.createNonceMiddleware( window.Redirectioni10n?.api?.WP_API_nonce ?? '' ) );

const App = () => (
<Provider store={ createReduxStore( getInitialState() ) }>
<React.StrictMode>
export default function App() {
return (
<Provider store={ createReduxStore( getInitialState() ) }>
<Home />
</React.StrictMode>
</Provider>
);

export default App;
</Provider>
);
};
1 change: 0 additions & 1 deletion client/component/welcome-wizard/step-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/

import React from 'react';
import { __ } from '@wordpress/i18n';

/**
Expand Down
75 changes: 42 additions & 33 deletions client/page/home/database-update.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,51 @@ function AutomaticUpgrade( { onShowUpgrade } ) {
);
}

export default function DatabaseUpdate( { showDatabase, result, onShowUpgrade } ) {
const { reason, status } = useSelector( ( state ) => state.settings.database );
function ShowDatabase() {
const dispatch = useDispatch();
const [ isManual, setManual ] = useState( false );
const { reason, status, result } = useSelector( ( state ) => state.settings.database );

function onFinish() {
dispatch( finishUpgrade() );
}

return (
<>
{ result === STATUS_FAILED && (
<Error
details={ getErrorDetails() }
errors={ reason }
renderDebug={ DebugReport }
links={ getErrorLinks() }
locale="redirection"
>
{ __( 'Something went wrong when upgrading Redirection.', 'redirection' ) }
</Error>
) }

<div className="wizard-wrapper">
<div className="wizard">
<Database />

{ hasFinished( status ) && (
<button className="button button-primary" onClick={ onFinish }>
{ __( 'Finished! 🎉', 'redirection' ) }
</button>
) }
</div>
</div>
</>
);
}

function ShowNotice( { onShowUpgrade } ) {
const [ isManual, setManual ] = useState( false );

function onToggle( ev ) {
ev.preventDefault();
setManual( !isManual );
}

if ( showDatabase ) {
return (
<>
{ result === STATUS_FAILED && (
<Error
details={ getErrorDetails() }
errors={ reason }
renderDebug={ DebugReport }
links={ getErrorLinks() }
locale="redirection"
>
{ __( 'Something went wrong when upgrading Redirection.', 'redirection' ) }
</Error>
) }

<div className="wizard-wrapper">
<div className="wizard">
<Database />

{ hasFinished( status ) && (
<button className="button button-primary" onClick={ onFinish }>
{ __( 'Finished! 🎉', 'redirection' ) }
</button>
) }
</div>
</div>
</>
);
}

return (
<>
<h1 className="wp-heading-inline">{ __( 'Upgrade Required', 'redirection' ) }</h1>
Expand Down Expand Up @@ -199,3 +200,11 @@ export default function DatabaseUpdate( { showDatabase, result, onShowUpgrade }
</>
);
}

export default function DatabaseUpdate( { showDatabase, onShowUpgrade } ) {
if ( showDatabase ) {
return <ShowDatabase />;
}

return <ShowNotice onShowUpgrade={ onShowUpgrade } />
}
99 changes: 24 additions & 75 deletions client/page/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* External dependencies
*/

import React, { useState } from 'react';
import { useState } from 'react';
import { __ } from '@wordpress/i18n';
import { connect } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';

/**
* Internal dependencies
Expand Down Expand Up @@ -87,35 +87,38 @@ const getMenu = () =>

const ALLOWED_PAGES = Redirectioni10n?.caps?.pages || [];

function Home( props ) {
export default function Home() {
const dispatch = useDispatch();
const {
onClearErrors,
errors,
onClearNotices,
notices,
onAdd,
databaseStatus,
onShowUpgrade,
showDatabase,
result,
inProgress,
pluginUpdate,
} = props;
} = useSelector( state => {
return {
errors: state.message.errors,
notices: state.message.notices,
databaseStatus: state.settings.database.status,
inProgress: state.settings.database.inProgress,
showDatabase: state.settings.showDatabase,
pluginUpdate: state.settings.values.plugin_update,
}
} );
const [ page, setPage ] = useState( getPluginPage( ALLOWED_PAGES ) );

function changePage( page ) {
const { onSet404Table, onSetLogTable, onSetRedirectTable, onSetGroupTable } = props;

setPage( page === '' ? 'redirect' : page );

if ( page === '404s' ) {
onSet404Table( getInitialError().table );
dispatch( setErrorTable( getInitialError().table ) );
} else if ( page === 'log' ) {
onSetLogTable( getInitialLog().table );
dispatch( setLogTable( getInitialLog().table ) );
} else if ( page === '' ) {
onSetRedirectTable( getInitialRedirect().table );
dispatch( setRedirectTable( getInitialRedirect().table ) );
} else if ( page === 'groups' ) {
onSetGroupTable( getInitialGroup().table );
dispatch( setGroupTable( getInitialGroup().table ) );
}
}

Expand All @@ -129,31 +132,29 @@ function Home( props ) {

const needsUpgrader =
pluginUpdate === 'prompt' && ( databaseStatus === 'need-update' || databaseStatus === 'finish-update' );

return (
<ErrorBoundary renderCrash={ CrashHandler } extra={ { page } }>
<div className="wrap redirection">
{ needsUpgrader && (
<DatabaseUpdate
onShowUpgrade={ onShowUpgrade }
onShowUpgrade={ () => dispatch( showUpgrade() ) }
showDatabase={ showDatabase }
result={ result }
/>
) }

{ ! inProgress && databaseStatus !== 'finish-update' && ! showDatabase && (
{ !inProgress && databaseStatus !== 'finish-update' && !showDatabase && (
<PageRouter
page={ page }
setPage={ setPage }
onPageChange={ onClearErrors }
onPageChange={ () => dispatch( clearErrors() ) }
allowedPages={ ALLOWED_PAGES }
baseUrl="?page=redirection.php"
defaultPage="redirect"
>
<h1 className="wp-heading-inline">{ getTitles()[ page ] }</h1>

{ page === 'redirect' && has_capability( CAP_REDIRECT_ADD ) && (
<button type="button" onClick={ onAdd } className="page-title-action">
<button type="button" onClick={ () => dispatch( addToTop( true ) ) } className="page-title-action">
{ __( 'Add New', 'redirection' ) }
</button>
) }
Expand All @@ -170,7 +171,7 @@ function Home( props ) {

<Error
errors={ errors }
onClear={ onClearErrors }
onClear={ () => dispatch( clearErrors() ) }
renderDebug={ DebugReport }
details={ getErrorDetails() }
links={ getErrorLinks() }
Expand All @@ -181,62 +182,10 @@ function Home( props ) {

<PageContent page={ page } />

<Snackbar notices={ notices } onClear={ onClearNotices } snackBarViewText={ __( 'View notice', 'redirection' ) } />
<Snackbar notices={ notices } onClear={ () => dispatch( clearNotices() ) } snackBarViewText={ __( 'View notice', 'redirection' ) } />
</PageRouter>
) }
</div>
</ErrorBoundary>
);
}

function mapDispatchToProps( dispatch ) {
return {
onClearErrors: () => {
dispatch( clearErrors() );
},
onAdd: () => {
dispatch( addToTop( true ) );
},
onSet404Table: ( table ) => {
dispatch( setErrorTable( table ) );
},
onSetLogTable: ( table ) => {
dispatch( setLogTable( table ) );
},
onSetGroupTable: ( table ) => {
dispatch( setGroupTable( table ) );
},
onSetRedirectTable: ( table ) => {
dispatch( setRedirectTable( table ) );
},
onShowUpgrade: () => {
dispatch( showUpgrade() );
},
onClearNotices: () => {
dispatch( clearNotices() );
},
};
}

function mapStateToProps( state ) {
const {
message: { errors, notices },
settings: { showDatabase, values },
} = state;
const { status: databaseStatus, result, inProgress } = state.settings.database;

return {
errors,
notices,
showDatabase,
databaseStatus,
result,
inProgress,
pluginUpdate: values.plugin_update,
};
}

export default connect(
mapStateToProps,
mapDispatchToProps
)( Home );
2 changes: 1 addition & 1 deletion fileio/csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function load_from_file( $group_id, $file, $separator ) {
while ( ( $csv = fgetcsv( $file, 5000, $separator ) ) ) {
$item = $this->csv_as_item( $csv, $group_id );

if ( $this->item_is_valid( $item ) ) {
if ( $item && $this->item_is_valid( $item ) ) {
$created = Red_Item::create( $item );

// The query log can use up all the memory
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redirection",
"version": "5.3.7",
"version": "5.3.8",
"description": "Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.",
"main": "redirection.php",
"browser": {
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://redirection.me/donation/
Tags: redirect, htaccess, 301, 404, seo, permalink, apache, nginx, post, admin
Requires at least: 5.6
Tested up to: 6.1
Stable tag: 5.3.7
Stable tag: 5.3.8
Requires PHP: 5.6
License: GPLv3

Expand Down Expand Up @@ -181,6 +181,10 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho

A x.1 version increase introduces new or updated features and can be considered to contain 'breaking' changes. A x.x.1 increase is purely a bug fix and introduces no new features, and can be considered as containing no breaking changes.

= 5.3.8 - 22nd January 2023 =
* Fix app rendering twice causing problems with upgrades
* Fix CSV header being detected as an error

= 5.3.7 - 8th January 2023 =
* Fix problem with locales in certain directories
* Fix incorrect import of empty CSV lines
Expand Down
2 changes: 1 addition & 1 deletion redirection-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function red_set_options( array $settings = [] ) {
if ( $settings['database_stage'] === false ) {
unset( $options['database_stage'] );
} else {
$options['database_stage'] = sanitize_text_field( $settings['database_stage'] );
$options['database_stage'] = $settings['database_stage'];
}
}

Expand Down
4 changes: 2 additions & 2 deletions redirection-version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

define( 'REDIRECTION_VERSION', '5.3.7' );
define( 'REDIRECTION_BUILD', '82f052e6365ec12de9cc37627ae44cb8' );
define( 'REDIRECTION_VERSION', '5.3.8' );
define( 'REDIRECTION_BUILD', '2fe1525b965f0dad5e09e733bfb52ddc' );
define( 'REDIRECTION_MIN_WP', '5.4' );
4 changes: 2 additions & 2 deletions redirection.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion redirection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Redirection
Plugin URI: https://redirection.me/
Description: Manage all your 301 redirects and monitor 404 errors
Version: 5.3.7
Version: 5.3.8
Author: John Godley
Text Domain: redirection
Domain Path: /locale
Expand Down