awesomemotive / one-click-demo-import

One Click Demo Import plugin
https://www.awesomemotive.com/
195 stars 83 forks source link

[Discussion] Trying to fix some errors that some people seem to have had and improve. #153

Closed redlagoon closed 6 years ago

redlagoon commented 6 years ago

Hola, Proteus! (You can mark this as closed, I'm just trying to better understand what you guys did here in the hopes of pulling a PR or furthering the advance.).

Great, amazing job with OCDI, couldn't be happier that someone thought to do this, even if I'm late at the party.

My context is that I've been re-writing the Widgets / Customizer importers, just to understand how they work, more or less, the Widgets was a bigger task and so, I defaulted to getting the code from the popular plugin, saved a lot of time and I achieved my goal - learning.

Now I'm at the content and it seems this is no easy task, and so, I have a few questions which would help a ton if answered:

1) I see you guys are extending the WXR Importer V2, why this choice? What were the issues with the original?

2) I remember reading that @capuderg said that the new Importer has functionality not every browser supports, what do you mean by this?

3) In all its pureness, could one simply call the WXR_Importer's methods and be done with the Import? Reason I ask this is I see there's a lot of setup for the screens of OCDI and have a hard time understanding exactly what the core of the plugin is.

4) In relation to 3), any chance you'd give me a quick snippet as to simply provide the XML file path for an import? Prefferably I'd call WXR_Importer->import( $path, $args ).

5) Now with the issues. Having read about Merlin and actually using it, I saw that some people have issues with timeouts, which to my guess, happen because the servers are slow and can't manage downloading a 70MB file in one shot, yet some have said that using the classic WXR Importer lands no issues. What exactly does OCDI add on top of the WXR Importer that makes it slower? (Assuming it's OCDI's fault.)

The way I've understood most things was by building them myself and right now I'm a tad bit lost at how OCDI operates, so these would help a ton!

Thanks a lot.

capuderg commented 6 years ago

Hi,

thanks for the kind words and the interest to help the project.

  1. we had to strip away the UI and other stuff in order to get only the core of the importer, which was used with our UI -> The OCDI is meant for theme authors to prepare their themes with demo imports, so you need widgets and customizer importer as well, so basically the v2 importer has the task to import WP content, while OCDI uses the import WP content just as one of its steps (it is a big one though)

  2. the WP importer v2 was using EventSource for creating connection from frontend to the server to import things and retrieve updates, but this isn't supported in IE and EDGE browsers. So we used the good old AJAX, which works on all browsers and that's important for OCDI, since you can't tell your theme clients to only use Chrome of Firefox for the import...

  3. The import usually takes quite a while to complete, but because users have restricted and slow servers, you have to break the import in multiple pieces and we did that with 25seconds long AJAX calls, so that the servers don't timeout. So the core of the plugin is to allow theme authors to predefine demo imports, so users can just click on the import button and they are done! More info here: http://proteusthemes.github.io/one-click-demo-import/

  4. You would have to instantiate the Importer class and then call the import_content method, with the parameter of XML file path: https://github.com/proteusthemes/one-click-demo-import/blob/master/inc/OneClickDemoImport.php#L294 https://github.com/proteusthemes/one-click-demo-import/blob/master/inc/OneClickDemoImport.php#L556

  5. That's the issue, I'm not sure the problem is in big files, since that wouldn't make any sense. Read this comment on Merlin: https://github.com/richtabor/MerlinWP/issues/104#issuecomment-394949791

Take care!

capuderg commented 6 years ago

I'm gonna mark it a closed, since it's just a discussion.

redlagoon commented 6 years ago

Sorry for the late reply.

I'm currently testing your fork of the WXR Importer vs. what WordPress offers, to see the difference in performance.

I'll report as soon as I'm done.

redlagoon commented 6 years ago

One issue, I just don't wanna "just copy code".

When I import my content, Woo pages now get messed up.

Assume I wanna pull the shop page link, as such, I'll do:

wc_get_page_id( 'shop' )

But that page doesn't get re-assigned to Woo as soon as the Importer is finished. I know you guys have fixed it but is there any chance you'd explain a bit what's going on here?

Also a few updates:

1) Importer works on super slow hosts, even with big files, I'm a bit...skeptical but I'll keep testing to see.

1.1) I'm experimenting with REST API instead of AJAX.

2) I've fixed (partially) the menus. With OCDI, or really, the default Importer, menus never get re-assigned.

capuderg commented 6 years ago

For the after import WooCommerce pages setup, you would have to use the "after import" plugin hook and do that manually. For more info look at: https://wordpress.org/plugins/one-click-demo-import/#faq-header the "How to automatically assign “Front page”, “Posts page” and menu locations after the importer is done?" question.

You can set the Woo shop page like this:

$shop_page = get_page_by_title( 'Shop' );
update_option( 'woocommerce_shop_page_id', $shop_page->ID );

The problem usually is not in the "slow" hostings, but in poorly configured hostings...

Menus have to be assigned to their locations via the after import hook. Look at the link I posted at the beginning of this message.

redlagoon commented 6 years ago

Oh, of course, my question was more so why does this happen?

capuderg commented 6 years ago

I don't remember, why the menus don't assign themselves via the import... maybe because the IDs change with the import and so it can't save the location of the menu, because the old menu ID doesn't exist.