← All changes
|
includes/Core/Importer/Runners/GutenbergContent.php
+22
-38
3.7.5
→
3.4.9
View file →
| @@ -38,15 +38,17 @@ | ||
| 38 | 38 | |
| 39 | 39 | public function import( $data, $imported_data ): array { |
| 40 | 40 | $contents = $this->manifest['content']; |
| 41 | 41 | |
| 42 | - // Log start of import | |
| 43 | - if(!$this->is_key_processed('started', 'import')){ | |
| 42 | + $processed_templates = $this->get_progress(); | |
| 43 | + | |
| 44 | + if(empty($processed_templates)){ | |
| 44 | 45 | $this->log( 0 ); |
| 45 | - $this->mark_key_processed('started', 'import'); | |
| 46 | + $processed_templates = ["__started__"]; | |
| 47 | + $this->update_progress( $processed_templates); | |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - if(isset($this->manifest['has_settings']) && $this->manifest['has_settings'] && !$this->is_key_processed('global_colors', 'settings')){ | |
| 50 | + if(isset($this->manifest['has_settings']) && $this->manifest['has_settings'] && !in_array("global_colors", $processed_templates)){ | |
| 49 | 51 | $file = $this->dir_path . "settings.json"; |
| 50 | 52 | $settings = Utils::read_json_file( $file ); |
| 51 | 53 | |
| 52 | 54 | if(!empty($data['color'])){ |
| @@ -61,20 +63,17 @@ | ||
| 61 | 63 | $settings['custom_colors'][$key]['color'] = $data['color'][$color['var']] ?? $color['color']; |
| 62 | 64 | } |
| 63 | 65 | } |
| 64 | 66 | } |
| 65 | - $logo_url = Utils::get_logo_url($data['logo'] ?? null); | |
| 66 | - $logo_id = is_array($data['logo'] ?? null) ? ($data['logo']['id'] ?? 0) : 0; | |
| 67 | - if(!empty($logo_id)){ | |
| 68 | - $site_logo_id = $logo_id; | |
| 67 | + if(!empty($data['logo']['id'])){ | |
| 68 | + $site_logo_id = $data['logo']['id']; | |
| 69 | 69 | $settings['site_logo'] = $site_logo_id; |
| 70 | 70 | Utils::update_option( 'site_logo', $site_logo_id ); |
| 71 | - $this->origin->update_imported_list('attachment', $logo_id); | |
| 71 | + $this->origin->update_imported_list('attachment', $data['logo']['id']); | |
| 72 | 72 | } |
| 73 | - else if (!empty($logo_url) && strpos($logo_url, 'data:image/') === 0) { | |
| 74 | - // Upload base64 data URL | |
| 75 | - $site_logo = Utils::upload_logo_base64($logo_url, $this->session_id); | |
| 76 | - | |
| 73 | + else if(!empty($data['logo']) && empty(get_option('site_logo'))){ | |
| 74 | + // demo logo | |
| 75 | + $site_logo = Utils::upload_logo($data['logo'], $this->session_id); | |
| 77 | 76 | if(!empty($site_logo['id'])){ |
| 78 | 77 | $settings['site_logo'] = $site_logo['id']; |
| 79 | 78 | Utils::update_option( 'site_logo', $site_logo['id'] ); |
| 80 | 79 | $this->origin->update_imported_list('attachment', $site_logo['id']); |
| @@ -79,17 +78,8 @@ | ||
| 79 | 78 | Utils::update_option( 'site_logo', $site_logo['id'] ); |
| 80 | 79 | $this->origin->update_imported_list('attachment', $site_logo['id']); |
| 81 | 80 | } |
| 82 | 81 | } |
| 83 | - else if(!empty($logo_url)){ | |
| 84 | - // Upload remote URL | |
| 85 | - $site_logo = Utils::upload_logo($logo_url, $this->session_id); | |
| 86 | - if(!empty($site_logo['id'])){ | |
| 87 | - $settings['site_logo'] = $site_logo['id']; | |
| 88 | - Utils::update_option( 'site_logo', $site_logo['id'] ); | |
| 89 | - $this->origin->update_imported_list('attachment', $site_logo['id']); | |
| 90 | - } | |
| 91 | - } | |
| 92 | 82 | |
| 93 | 83 | |
| 94 | 84 | if(!empty($data['typography'])){ |
| 95 | 85 | $settings["global_typography"] = $data['typography']; |
| @@ -99,9 +89,10 @@ | ||
| 99 | 89 | |
| 100 | 90 | // Save the settings to the 'eb_global_styles' option |
| 101 | 91 | Utils::update_option('eb_global_styles', $settings); |
| 102 | 92 | |
| 103 | - $this->mark_key_processed('global_colors', 'settings'); | |
| 93 | + $processed_templates[] = "global_colors"; | |
| 94 | + $this->update_progress( $processed_templates); | |
| 104 | 95 | } |
| 105 | 96 | |
| 106 | 97 | $processed = 0; |
| 107 | 98 | $total = array_reduce($contents, function($carry, $item) { |
| @@ -108,10 +99,9 @@ | ||
| 108 | 99 | return $carry + count($item); |
| 109 | 100 | }, 0); |
| 110 | 101 | |
| 111 | 102 | $results = $this->loop( $contents, function($type, $posts, $results ) use($total) { |
| 112 | - // Inner loop accumulates results for this type | |
| 113 | - $inner_result = $this->loop( $posts, function($id, $settings, $result ) use($type, $results, $total) { | |
| 103 | + return $this->loop( $posts, function($id, $settings, $result ) use($type, $total, $results) { | |
| 114 | 104 | $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR; |
| 115 | 105 | |
| 116 | 106 | $import = $this->import_page_content( $id, $type, $path, $settings ); |
| 117 | 107 | |
| @@ -121,17 +111,15 @@ | ||
| 121 | 111 | Utils::import_page_settings( $import['id'], $settings ); |
| 122 | 112 | $result[ $type ]['succeed'][ $id ] = $import['id']; |
| 123 | 113 | } |
| 124 | 114 | |
| 125 | - // Broadcast Log - merge with outer results for accurate counting | |
| 126 | - $merged = array_merge($results, $result); | |
| 115 | + // Broadcast Log | |
| 127 | 116 | $processed = 0; |
| 128 | - foreach ($merged as $t => $data) { | |
| 129 | - if (is_array($data) && $t !== '__attachments') { | |
| 130 | - $processed += count($data['succeed'] ?? []) + count($data['failed'] ?? []); | |
| 131 | - } | |
| 132 | - } | |
| 133 | - $progress = $total > 0 ? floor( ( 100 * $processed ) / $total ) : 100; | |
| 117 | + $results = Helper::recursive_wp_parse_args($result, $results); | |
| 118 | + array_walk_recursive($results, function($item) use (&$processed) { | |
| 119 | + $processed++; | |
| 120 | + }); | |
| 121 | + $progress = floor( ( 100 * $processed ) / $total ); | |
| 134 | 122 | $this->log( $progress ); |
| 135 | 123 | |
| 136 | 124 | $result['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : []; |
| 137 | 125 | |
| @@ -136,12 +124,8 @@ | ||
| 136 | 124 | $result['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : []; |
| 137 | 125 | |
| 138 | 126 | return $result; |
| 139 | 127 | }, $type); |
| 140 | - | |
| 141 | - // Non-recursive merge of inner result with outer results | |
| 142 | - $results = array_merge($results, $inner_result); | |
| 143 | - return $results; | |
| 144 | 128 | }); |
| 145 | 129 | |
| 146 | 130 | return [ 'content' => $results ]; |
| 147 | 131 | } |
| @@ -195,5 +179,5 @@ | ||
| 195 | 179 | return false; |
| 196 | 180 | } |
| 197 | 181 | } |
| 198 | 182 | |
| 199 | -} | |
| 183 | +} | |