use strict;

return sub
{
	my $dbh = shift;
	

	my $sth = $dbh->prepare("select id,settings from jin_pgate where type='paypal'");
	$sth->execute;
	
	my $str1 = "pro_mode:1,";
	my $str2 = "test_mode_for_pro:1,";
	
	while (my $row = $sth->fetchrow_hashref)
	{
		my $pos1 = index $row->{settings}, $str1;
		
		next
			if $pos1 < 0;
			
		if (my $pos2 = index $row->{settings}, $str2)
		{
			substr($row->{settings}, $pos2, length($str2)) = 'test_mode:1';
		}

		$dbh->do("UPDATE jin_pgate SET type='paypal_wppdp',settings=".$dbh->quote($row->{settings})." WHERE id=$row->{id}");
	}
	

	$sth = $dbh->prepare("select distinct pgtxn_id from jin_paylog where pgtxn_id!=0");
	$sth->execute;

	my $sth1 = $dbh->prepare("select order_id,sale_id from jin_pgtxn where id=?");
	my $sth2 = $dbh->prepare("update jin_paylog set pgtxn_id=0,order_id=?,sale_id=? where pgtxn_id=?");

	while (my $row = $sth->fetchrow_hashref)
	{
		$sth1->execute($row->{pgtxn_id});
		if (my $row1 = $sth1->fetchrow_hashref)
		{
			$sth2->execute($row1->{order_id}, $row1->{sale_id}, $row->{pgtxn_id});
		}
	}
	
	return;
};
