CRM-14871 - Extension & Flushing

This is a resubmission of https://github.com/civicrm/civicrm-core/pull/3512
which adds some fixes.