I had a toilet that stank, pulled it to figure out what was going on. Looks like the flange had been broken in the past and repaired, subfloor all around the flange was rotten. Tried getting the old flange out, but I think it was installed with primer. Cut out the rotten sub floor, can now see that the flange went directly into what I think is called a sanitary tee.
I can't seem to get the old flange out (already cracked part of the tee it attaches too) so now aren't sure what to do. A bunch of google results tell me you're not even supposed to use a sanitary tee horizontally like this.
What is the best approach here? Somehow try to get the remainder of the flange out of the tee then put a new one in? Cut out that tee and put something else in? One issue is that 'upstream' (I think to vent?) of the tee there isn't a lot of room to couple new pipe there.
Here's the (broken) tee with the partially removed flange
side view of the Tee
Upstream view:
Downstream view