use strict;

return sub
{
	my $dbh = shift;
	

	{
		my $sth = $dbh->prepare("select r.id,ms.autoassign_roles as au from jin_role r inner join jin_merchant_settings ms on ms.id=1 where r.autoassign=1 and not find_in_set(r.id,ms.autoassign_roles)");
		$sth->execute;
	
		my $sth1 = $dbh->prepare("update jin_merchant_settings set autoassign_roles=if(autoassign_roles!='',concat(autoassign_roles,',',?),?) where id=1");
	
		while (my $row = $sth->fetchrow_hashref)
		{
			$sth1->execute($row->{id}, $row->{id});
		}
	}

	{
		my $sth = $dbh->prepare("select r.id,ms.autoassign_affprogs as au from jin_affprog r inner join jin_merchant_settings ms on ms.id=1 where r.autoassign=1 and not find_in_set(r.id,ms.autoassign_affprogs)");
		$sth->execute;
	
		my $sth1 = $dbh->prepare("update jin_merchant_settings set autoassign_affprogs=if(autoassign_affprogs!='',concat(autoassign_affprogs,',',?),?) where id=1");
	
		while (my $row = $sth->fetchrow_hashref)
		{
			$sth1->execute($row->{id}, $row->{id});
		}
	}

	return;
};
