PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.8.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.8.0
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
templately / modules / full-site-import / Utils / Form.php

Form.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.8.0, at modules/full-site-import/Utils/Form.php

76 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Modules\FullSiteImport\Utils;
4
5 use Exception;
6 use FluentForm\App\Services\Transfer\TransferService;
7 use FluentForm\Framework\Request\File;
8 use Templately\Utils\Helper;
9
10 class Form {
11 protected $plugin;
12 protected $file;
13 protected $settings = [];
14
15 public function __construct( $plugin, $file, $settings = [] ) {
16 $this->plugin = $plugin;
17 $this->file = $file;
18 $this->settings = $settings;
19 }
20
21 /**
22 * @throws Exception
23 */
24 public function run() {
25 if ( ! file_exists( $this->file ) ) {
26 throw new Exception( __( 'Form JSON does not exists.', 'templately' ) );
27 }
28
29 $data = $this->import();
30
31 if ( ! $data ) {
32 throw new Exception( __( 'Cannot be imported.', 'templately' ) );
33 }
34
35 return $data;
36 }
37
38 public function import() {
39 try {
40 $results = null;
41 switch ( $this->plugin ) {
42 // `finfo` (the PHP `fileinfo` extension) is required: FluentForm's
43 // File::__construct() resolves the MIME type via `new finfo()`, which
44 // fatals if the extension is missing. Guard it so we skip the form
45 // import instead of crashing the whole site import.
46 case 'fluent-forms' && is_plugin_active( 'fluentform/fluentform.php' ) && class_exists( File::class ) && class_exists( TransferService::class ) && class_exists( 'finfo' ):
47 $fileObject = new File( $this->file, '' );
48 $importer = new TransferService();
49 $inserted = $importer->importForms( $fileObject );
50 $results = key( $inserted['inserted_forms'] );
51 break;
52 default:
53 break;
54 }
55
56 return $results;
57
58 } catch ( \Throwable $e ) {
59 // \Throwable, not \Exception: a fatal \Error raised inside the third-party
60 // form importer (a missing class or constant) is NOT an Exception, so the
61 // old catch could not contain it and one broken form aborted the entire
62 // site import.
63 //
64 // This swallows the failure by design — a form that cannot be imported must
65 // not stop the site import — but silence made every such failure invisible,
66 // so it is logged before being dropped.
67 Helper::log(
68 sprintf( 'Form import failed (%s): %s', $this->plugin, $e->getMessage() ),
69 'fsi',
70 'error'
71 );
72
73 return null;
74 }
75 }
76 }