← All changes
|
includes/Core/Importer/Runners/GutenbergContent.php
+24
-32
3.1.10
→
3.4.5
View file →
| @@ -3,9 +3,9 @@ | ||
| 3 | 3 | namespace Templately\Core\Importer\Runners; |
| 4 | 4 | |
| 5 | 5 | use Templately\Builder\PageTemplates; |
| 6 | 6 | use Templately\Core\Importer\Utils\Utils; |
| 7 | -use Templately\Core\Importer\WPImport; | |
| 7 | +use Templately\Utils\Helper; | |
| 8 | 8 | use WP_Error; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * @property GutenbergHelper $json |
| @@ -28,26 +28,24 @@ | ||
| 28 | 28 | return true; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | public function get_action(): string { |
| 32 | - return 'eventLog'; | |
| 32 | + return 'updateLog'; | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function log_message(): string { |
| 36 | - return __( 'Importing Gutenberg Templates (Pages, Posts etc)', 'templately' ); | |
| 36 | + return __( 'Importing Gutenberg Page and Post Templates', 'templately' ); | |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function import( $data, $imported_data ): array { |
| 40 | - $results = $data["imported_data"]["content"] ?? []; | |
| 41 | 40 | $contents = $this->manifest['content']; |
| 42 | - $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR; | |
| 43 | 41 | |
| 44 | - $processed_templates = $this->origin->get_progress(); | |
| 42 | + $processed_templates = $this->get_progress(); | |
| 45 | 43 | |
| 46 | 44 | if(empty($processed_templates)){ |
| 47 | 45 | $this->log( 0 ); |
| 48 | 46 | $processed_templates = ["__started__"]; |
| 49 | - $this->origin->update_progress( $processed_templates); | |
| 47 | + $this->update_progress( $processed_templates); | |
| 50 | 48 | } |
| 51 | 49 | |
| 52 | 50 | if(isset($this->manifest['has_settings']) && $this->manifest['has_settings'] && !in_array("global_colors", $processed_templates)){ |
| 53 | 51 | $file = $this->dir_path . "settings.json"; |
| @@ -73,9 +71,9 @@ | ||
| 73 | 71 | $this->origin->update_imported_list('attachment', $data['logo']['id']); |
| 74 | 72 | } |
| 75 | 73 | else if(!empty($data['logo']) && empty(get_option('site_logo'))){ |
| 76 | 74 | // demo logo |
| 77 | - $site_logo = Utils::upload_logo($data['logo']); | |
| 75 | + $site_logo = Utils::upload_logo($data['logo'], $this->session_id); | |
| 78 | 76 | if(!empty($site_logo['id'])){ |
| 79 | 77 | $settings['site_logo'] = $site_logo['id']; |
| 80 | 78 | Utils::update_option( 'site_logo', $site_logo['id'] ); |
| 81 | 79 | $this->origin->update_imported_list('attachment', $site_logo['id']); |
| @@ -81,8 +79,13 @@ | ||
| 81 | 79 | $this->origin->update_imported_list('attachment', $site_logo['id']); |
| 82 | 80 | } |
| 83 | 81 | } |
| 84 | 82 | |
| 83 | + | |
| 84 | + if(!empty($data['typography'])){ | |
| 85 | + $settings["global_typography"] = $data['typography']; | |
| 86 | + } | |
| 87 | + | |
| 85 | 88 | $settings = array_map('json_encode', $settings); |
| 86 | 89 | |
| 87 | 90 | // Save the settings to the 'eb_global_styles' option |
| 88 | 91 | Utils::update_option('eb_global_styles', $settings); |
| @@ -87,9 +90,9 @@ | ||
| 87 | 90 | // Save the settings to the 'eb_global_styles' option |
| 88 | 91 | Utils::update_option('eb_global_styles', $settings); |
| 89 | 92 | |
| 90 | 93 | $processed_templates[] = "global_colors"; |
| 91 | - $this->origin->update_progress( $processed_templates, [ 'content' => $results ]); | |
| 94 | + $this->update_progress( $processed_templates); | |
| 92 | 95 | } |
| 93 | 96 | |
| 94 | 97 | $processed = 0; |
| 95 | 98 | $total = array_reduce($contents, function($carry, $item) { |
| @@ -95,46 +98,35 @@ | ||
| 95 | 98 | $total = array_reduce($contents, function($carry, $item) { |
| 96 | 99 | return $carry + count($item); |
| 97 | 100 | }, 0); |
| 98 | 101 | |
| 99 | - foreach ( $contents as $type => $posts ) { | |
| 100 | - foreach ( $posts as $id => $settings ) { | |
| 101 | - if (in_array("$type::$id", $processed_templates)) { | |
| 102 | - continue; | |
| 103 | - } | |
| 102 | + $results = $this->loop( $contents, function($type, $posts, $results ) use($total) { | |
| 103 | + return $this->loop( $posts, function($id, $settings, $result ) use($type, $total, $results) { | |
| 104 | + $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR; | |
| 105 | + | |
| 104 | 106 | $import = $this->import_page_content( $id, $type, $path, $settings ); |
| 105 | 107 | |
| 106 | 108 | if ( ! $import ) { |
| 107 | - $results[ $type ]['failed'][ $id ] = $import; | |
| 109 | + $result[ $type ]['failed'][ $id ] = $import; | |
| 108 | 110 | } else { |
| 109 | 111 | Utils::import_page_settings( $import['id'], $settings ); |
| 110 | - $results[ $type ]['succeed'][ $id ] = $import['id']; | |
| 112 | + $result[ $type ]['succeed'][ $id ] = $import['id']; | |
| 111 | 113 | } |
| 112 | 114 | |
| 113 | 115 | // Broadcast Log |
| 114 | 116 | $processed = 0; |
| 117 | + $results = Helper::recursive_wp_parse_args($result, $results); | |
| 115 | 118 | array_walk_recursive($results, function($item) use (&$processed) { |
| 116 | 119 | $processed++; |
| 117 | 120 | }); |
| 118 | 121 | $progress = floor( ( 100 * $processed ) / $total ); |
| 119 | - $this->log( $progress, null, 'eventLog' ); | |
| 122 | + $this->log( $progress ); | |
| 120 | 123 | |
| 124 | + $result['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : []; | |
| 121 | 125 | |
| 122 | - $results['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : []; | |
| 123 | - // Add the template to the processed templates and update the session data | |
| 124 | - $processed_templates[] = "$type::$id"; | |
| 125 | - $this->origin->update_progress( $processed_templates, [ 'content' => $results ]); | |
| 126 | - // If it's not the last item, send the SSE message and exit | |
| 127 | - if( end($contents) !== $posts || end($posts) !== $settings) { | |
| 128 | - $this->sse_message( [ | |
| 129 | - 'type' => 'continue', | |
| 130 | - 'action' => 'continue', | |
| 131 | - 'results' => __METHOD__ . '::' . __LINE__, | |
| 132 | - ] ); | |
| 133 | - exit; | |
| 134 | - } | |
| 135 | - } | |
| 136 | - } | |
| 126 | + return $result; | |
| 127 | + }, $type); | |
| 128 | + }); | |
| 137 | 129 | |
| 138 | 130 | return [ 'content' => $results ]; |
| 139 | 131 | } |
| 140 | 132 | |