| 1 |
<?php |
| 2 |
namespace Elementor\App\Modules\ImportExportCustomization\Data\Routes; |
| 3 |
|
| 4 |
use Elementor\Plugin; |
| 5 |
use Elementor\App\Modules\ImportExportCustomization\Data\Response; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
class Import_Runner extends Base_Route { |
| 12 |
|
| 13 |
protected function get_route(): string { |
| 14 |
return 'import-runner'; |
| 15 |
} |
| 16 |
|
| 17 |
protected function get_method(): string { |
| 18 |
return \WP_REST_Server::CREATABLE; |
| 19 |
} |
| 20 |
|
| 21 |
protected function callback( $request ): \WP_REST_Response { |
| 22 |
try { |
| 23 |
$session_id = $request->get_param( 'session' ); |
| 24 |
$runner = $request->get_param( 'runner' ); |
| 25 |
$module = Plugin::$instance->app->get_component( 'import-export-customization' ); |
| 26 |
|
| 27 |
if ( empty( $session_id ) ) { |
| 28 |
return Response::error( 'Session ID is required.', 'missing_session_id' ); |
| 29 |
} |
| 30 |
|
| 31 |
if ( empty( $runner ) ) { |
| 32 |
return Response::error( 'Runner name is required.', 'missing_runner_name' ); |
| 33 |
} |
| 34 |
|
| 35 |
$import = $module->import_kit_by_runner( $session_id, $runner ); |
| 36 |
|
| 37 |
if ( ! empty( $import['status'] ) ) { |
| 38 |
Plugin::$instance->logger->get_logger()->info( |
| 39 |
sprintf( 'Import runner completed via REST API: %1$s %2$s', |
| 40 |
$import['runner'] ?? $runner, |
| 41 |
( 'success' === $import['status'] ? '✓' : '✗' ) |
| 42 |
) |
| 43 |
); |
| 44 |
} |
| 45 |
|
| 46 |
do_action( 'elementor/import-export-customization/import-kit/runner/after-run', $import ); |
| 47 |
|
| 48 |
return Response::success( $import ); |
| 49 |
|
| 50 |
} catch ( \Error $e ) { |
| 51 |
Plugin::$instance->logger->get_logger()->error( $e->getMessage(), [ |
| 52 |
'meta' => [ |
| 53 |
'trace' => $e->getTraceAsString(), |
| 54 |
], |
| 55 |
] ); |
| 56 |
|
| 57 |
return Response::error( $e->getMessage(), 'import_runner_error' ); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
protected function get_args(): array { |
| 62 |
return [ |
| 63 |
'session' => [ |
| 64 |
'type' => 'string', |
| 65 |
'description' => 'Session ID for import operations', |
| 66 |
'required' => true, |
| 67 |
], |
| 68 |
'runner' => [ |
| 69 |
'type' => 'string', |
| 70 |
'description' => 'Runner name for import_runner action', |
| 71 |
'required' => true, |
| 72 |
], |
| 73 |
]; |
| 74 |
} |
| 75 |
} |
| 76 |
|