[BUGFIX] Use correct available columns while setting unused elements

Set unused columns has to be moved after database operations
to make sure the correct backend layout will be used for tca items

Added some CGL fixes as well.

Change-Id: I63d69d95d4b1e74cc786e2d652a3bbce88461999
Resolves: #58295
Reviewed-on: https://review.typo3.org/29880
Reviewed-by: Jo Hasenau
Tested-by: Jo Hasenau