fix 'NoneType' object has no attribute 'published' issue on page publish

This pull request fixes `'NoneType' object has no attribute 'published'` issue when a user tries to publish certain pages. The issue was fixed with adding a condition to check if the parent existed in the first place.