The sad reality is the migrant workers take the positions despite knowing up front how poorly they can or will be treated. These jobs are often very sought after, I have friends who experience of these "trade fares" where they go and recruit large numbers of people from India, Bangladesh etc to come and work in the Gulf. They become generational/family type jobs for people in many instances, with multiple generations and family members working together to secure the positions. There are also people who "join the queue" for multiple disciplines, just in the hope of getting a job, so they will try to pass themselves off as a groundworker, then electrician, then plumber etc.
The reality is that to them the pay is worth the conditions and risk, they don't live by "Western" standards. They only do 2-3 years in many instances and then have enough money for a farm, small holding or other business back home. What needs to be stopped is the exploitation of this, and the "Western" companies operating in the Gulf need to lead this, and in many if not all they have done so. The number of migrant camps of the extremely poor variety has decreased enormously in the Gulf and continues to do so. Given the nature of the location you are never going to get rid of camps entirely, even highly paid Western oil workers live in camps, just a higher standard, and this is what needs to be filtered down to all migrant workers.
To be fair to Qatar and other Gulf states the problem is not unique to them. There is always exploitation, we have it in the UK with workers being brought in from places like Eastern Europe and Spain, and working for far less money and general conditions than people based in the UK would. This is all supposed to be controlled by European legislation, but there are ways around it for employing companies.