function deleteSystemTotalTime() { //Delete everything that is not overrided. $udtlf = new UserDateTotalListFactory(); $pcf = new PunchControlFactory(); //Optimize for a direct delete query. if ($this->getUserDateID() > 0) { //Due to a MySQL gotcha: http://dev.mysql.com/doc/refman/5.0/en/subquery-errors.html //We need to wrap the subquery in a subquery of itself to hide it from MySQL //So it doesn't complain about updating a table and selecting from it at the same time. //MySQL v5.0.22 DOES NOT like this query, it takes 10+ seconds to run and seems to cause a deadlock. //Switch back to a select then a bulkDelete instead. Still fast enough I think. $udtlf->getByUserDateIdAndStatusAndOverrideAndMisMatchPunchControlUserDateId($this->getUserDateID(), array(10, 30), FALSE); //System totals $this->bulkDelete($this->getIDSByListFactory($udtlf)); } else { Debug::text('NO System Total Records to delete...', __FILE__, __LINE__, __METHOD__, 10); } return TRUE; }