President Donald Trump has signed legislation funding much of the Department of Homeland Security, but not its immigration enforcement operations, ending the longest shutdown in the agency’s history.