diff --git a/README.md b/README.md index 15c57a5..9c910fd 100644 Binary files a/README.md and b/README.md differ diff --git a/assets/screenshot-1.png b/assets/screenshot-1.png index 2cf4209..b9b5bdd 100644 Binary files a/assets/screenshot-1.png and b/assets/screenshot-1.png differ diff --git a/assets/screenshot-2.png b/assets/screenshot-2.png index 8040333..87e397e 100644 Binary files a/assets/screenshot-2.png and b/assets/screenshot-2.png differ diff --git a/assets/screenshot-3.png b/assets/screenshot-3.png index 5e297a9..ba6b68c 100644 Binary files a/assets/screenshot-3.png and b/assets/screenshot-3.png differ diff --git a/src/js/Components/Wizard.js b/src/js/Components/Wizard.js index eedbdb0..2887a16 100644 --- a/src/js/Components/Wizard.js +++ b/src/js/Components/Wizard.js @@ -73,6 +73,16 @@ export default function Wizard(){ .finally(() => setDispatching(false)); } + const cancelImport = function(){ + setCancelling(true); + apiFetch({path: '/sifg/v1/import/cancel'}).then((data) => {}).catch((error) => { + createErrorNotice( __('Could not cancel import', 'site-import-for-gbp'), { + type: 'snackbar', + } ); + }) + .finally(); + } + useEffect(() => { const checkImportStatus = () => { apiFetch({path: '/sifg/v1/import/status'}).then((data) => { @@ -182,7 +192,7 @@ export default function Wizard(){ {/* checked={selectedOptions.reviews}*/} {/*/>*/}
- + +
); diff --git a/src/php/BackgroundProcessing/BackgroundProcess.php b/src/php/BackgroundProcessing/BackgroundProcess.php index 02cd666..c74440e 100644 --- a/src/php/BackgroundProcessing/BackgroundProcess.php +++ b/src/php/BackgroundProcessing/BackgroundProcess.php @@ -207,7 +207,13 @@ private function import_posts($item){ '_sifg_name' => $post->name, '_sifg_gbp_post_data' => $post, ] - ]); + ], true, false); + + if(is_wp_error($post_id)){ + //translators: %1$s is Google Location identifier, %2$s is the error message + $this->logger->add(sprintf(__('Failed to import post into %1$s WordPress: %2$s', 'site-import-for-gbp'), $post->name, $post_id->get_error_message())); + continue; + } diff --git a/src/php/Configuration/RestApiConfiguration.php b/src/php/Configuration/RestApiConfiguration.php index 47f561b..0f662b1 100644 --- a/src/php/Configuration/RestApiConfiguration.php +++ b/src/php/Configuration/RestApiConfiguration.php @@ -4,6 +4,7 @@ use Koen12344\SiteImportForGbp\DependencyInjection\Container; use Koen12344\SiteImportForGbp\DependencyInjection\ContainerConfigurationInterface; +use Koen12344\SiteImportForGbp\RestAPI\CancelImportEndpoint; use Koen12344\SiteImportForGbp\RestAPI\ConfirmImportEndpoint; use Koen12344\SiteImportForGbp\RestAPI\DisconnectGoogleEndpoint; use Koen12344\SiteImportForGbp\RestAPI\DispatchImportEndpoint; @@ -24,6 +25,7 @@ public function modify( Container $container ) { 'import_status_endpoint' => new ImportStatusEndpoint($container['service.import_process'], $container['service.import_logger']), 'import_log_endpoint' => new GetImportLogEndpoint($container['service.import_logger']), 'confirm_import_endpoint' => new ConfirmImportEndpoint($container['service.import_logger']), + 'cancel_import_endpoin' => new CancelImportEndpoint($container['service.import_process']), ]; }); } diff --git a/src/php/Logger/ImportLogger.php b/src/php/Logger/ImportLogger.php index b3a1c1b..d9242a5 100644 --- a/src/php/Logger/ImportLogger.php +++ b/src/php/Logger/ImportLogger.php @@ -8,7 +8,7 @@ class ImportLogger { public function add($message){ $log = $this->read(); $timestamp = "[".current_time('mysql')."] "; - $message = $timestamp.esc_html($message)."\n"; + $message = $timestamp.$message."\n"; $log = $message.$log; $this->save($log); diff --git a/src/php/RestAPI/CancelImportEndpoint.php b/src/php/RestAPI/CancelImportEndpoint.php new file mode 100644 index 0000000..7d219e4 --- /dev/null +++ b/src/php/RestAPI/CancelImportEndpoint.php @@ -0,0 +1,41 @@ +process = $process; + } + public function get_arguments(): array { + return []; + } + + public function respond( WP_REST_Request $request ) { + if($this->process->is_processing()){ + $this->process->cancel(); + } + return new \WP_REST_Response(true); + } + + public function validate( WP_REST_Request $request ): bool { + return current_user_can('manage_options'); + } + + public function get_methods(): array { + return [\WP_REST_Server::READABLE]; + } + + public function get_path(): string { + return '/import/confirm/'; + } +} diff --git a/src/php/RestAPI/GetImportLogEndpoint.php b/src/php/RestAPI/GetImportLogEndpoint.php index 08b073b..da7c308 100644 --- a/src/php/RestAPI/GetImportLogEndpoint.php +++ b/src/php/RestAPI/GetImportLogEndpoint.php @@ -21,7 +21,7 @@ public function get_arguments(): array { } public function respond( WP_REST_Request $request ) { - return new \WP_REST_Response(['log' => $this->logger->read()]); + return new \WP_REST_Response(['log' => esc_html($this->logger->read())]); } public function validate( WP_REST_Request $request ): bool {