Fixes #6848,BZ1124547 - Checking content view environments

Checking that a content view is in the environment before trying to remove it
from the environment.