fix for bug 9632 - Export/Import fails

The import fails because Layout contains unused Activities and that breaks the replace logic.  This fix makes the write to DB remove unused Activities from Layout, leaving the YAML consistent.