Jump to content

MultipleRedirects


HeadStand

Recommended Posts

I'm building an import script for one of my clients. Since it's dealing with thousands of entries, I've set up a multiple redirect using \IPS\Helpers\MultipleRedirect.

Everything seems to be working, however:

1. It's really really REALLY slow. Painfully slow. And the script is doing almost nothing. Reads an email address, checks if it exists, otherwise creates a member account. It's not even sending emails (because this is a test run). I'm afraid that when I turn on the email notifications, it will take hours.

2. It's doing a full page refresh instead of that nice progress bar thing that happens when you install an app or a plugin. How do I make it behave like that?

Link to comment
Share on other sites

1 hour ago, Matt said:

You really want to use the ajax progress bar as it is much faster than the full page refresh. The full page refresh only occurs if the client does not have JS enabled, or there is a JS error on the page.

:p @HeadStand had said that haha

15 hours ago, HeadStand said:

. It's doing a full page refresh instead of that nice progress bar thing that happens when you install an app or a plugin. How do I make it behave like that?

:) 

Edit: *derp*  you said why it happens. <3 *removes asshat*

Link to comment
Share on other sites

6 hours ago, Matt said:

You really want to use the ajax progress bar as it is much faster than the full page refresh. The full page refresh only occurs if the client does not have JS enabled, or there is a JS error on the page.

Yes, that's my question. How do I use that? JS is already enabled, and there is no error.

Link to comment
Share on other sites

How are you initializing the data within the MultipleRedirect? I banged my head against this for a while myself.

I needed to pass in starting configuration data to the multiple redirect, but was having a hell of a time. I ended up redirecting to the page containing my MultipleRedirect while setting the "mr" querystring to my starting data. However, if you do this, it will trigger the MultipleRedirect to go into the non ajax mode. Are you doing this also?

I finally solved it, but not until at least 45 minutes of WTF.

 

Link to comment
Share on other sites

On 11/6/2015, 4:36:48, Mark said:

Is it in the ACP or the front-end or...?

ACP.

 

21 hours ago, Kevin Carwile said:

How are you initializing the data within the MultipleRedirect? I banged my head against this for a while myself.

I needed to pass in starting configuration data to the multiple redirect, but was having a hell of a time. I ended up redirecting to the page containing my MultipleRedirect while setting the "mr" querystring to my starting data. However, if you do this, it will trigger the MultipleRedirect to go into the non ajax mode. Are you doing this also?

I finally solved it, but not until at least 45 minutes of WTF.

 

You kind of lost me, but I THINK I'm doing the same thing as you are? I tried to copy what was done for the plugin installation.

Link to comment
Share on other sites

I was doing something like this initially, which was causing the redirects to happen page by page :

protected function startWhatever()
{
  $form = new \IPS\Helpers\Form;
  $form->add( ... );

  if ( $values = $form->values() )
  {
      /* Create a starting multiple redirect configuration from form submission */
      $config = array( ... );

	/* Pass the configuration straight into the multiple redirect */
      \IPS\Output::i()->redirect( \IPS\Http\Url::internal( "...&do=doWhatever" )->setQueryString( 'mr', base64_encode( urlencode( json_encode( $config ) ) ) ) );
  }

  \IPS\Output::i()->output = $form;
}

protected function doWhatever()
{
	\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect
	(
		\IPS\Http\Url::internal( "...&do=doWhatever" ),
		function( $data ) { 
			/* $data is already initialized */ 
		},
		function() {}
	);
}

Instead, I had to do this to get the ajax redirects:

protected function startWhatever()
{
	... create starting configuration from form submission

	\IPS\Output::i()->redirect( \IPS\Http\Url::internal( "...&do=doWhatever" )->setQueryString( 'config', base64_encode( urlencode( json_encode( $config ) ) ) ) );

}

protected function doWhatever()
{
	$config = json_decode( urldecode( base64_decode( \IPS\Request::i()->config ) ), TRUE );

	\IPS\Output::i()->output = new \IPS\Helpers\MultipleRedirect( 
		\IPS\Http\Url::internal( "...&do=doWhatever" )->setQueryString( 'config', \IPS\Request::i()->config ),
		function( $data ) use ( $config ) { 
			/* initialize $data using $config */ 
		},
		function() { },
	);
}

 

Link to comment
Share on other sites

It could be empty. But I am using those values to determine what steps I need to take in my multiple redirect.

The take away here is that in order for the multiple redirect to work using the ajax mode, the $data needs to start out empty. So if you want to get a starting configuration into your multiple redirect, you have to set it using a different url parameter than "mr".

Link to comment
Share on other sites

Can you clarify - is it doing it with AJAX, but you seeing a spinning circle (rather than a progress bar) - or is it actually doing full redirects?

If it's the former - you need to return the percentage as the 3rd element in the array, for example, change this:

            return array( array(
                'step' => 'customers',
                'start' => $start
            ), \IPS\Member::loggedIn()->language()->addToStack( 'importing_customers' ) );

To this:

            return array( array(
                'step' => 'customers',
                'start' => $start
            ), \IPS\Member::loggedIn()->language()->addToStack( 'importing_customers' ), 100 / count( $lines ) * $start );

And repeat in runPurchaseImport()

 

If it's the latter - I didn't see this, but it's probably an error (if the multiple redirect hits an error, it performs an actual hard refresh with the intention that then it can show the user what the error is). Using the web inspector tools in your browser, monitor what comes back from the AJAX response before it redirects. If you can't figure it out, upload the csv files you're using so I can actually test it exactly as you are.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...