Guarantee Rules integrity when deleting referenced objects #2716

This is done by deleting all Rules referencing deleted objects
via DB triggers. It does not have any security check and thus deleting
an object from DB manually may have a impact on hundreds of objects.