Created
September 22, 2013 07:33
-
-
Save shanmugam-gp/6657645 to your computer and use it in GitHub Desktop.
Workstation Bug Fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Remove duplicate workstations which is identified by workstation_machine_address | |
* | |
* @param void | |
* | |
* @return void | |
*/ | |
public function remove_duplicate_workstations() | |
{ | |
//query to find the workstation duplicates | |
$sql = "SELECT count(*) as NumberofWS, | |
ws_machine_id | |
FROM `GA_workstation` | |
group by ws_machine_id | |
having NumberofWS > 1 | |
order by NumberofWS desc"; | |
//remove duplicates and update job and printer relationships | |
$result = $this->user_database->query($sql); | |
//check the number of duplications is more than 0 | |
if($result->num_rows()>0) | |
{ | |
//process eache record | |
foreach($result->result_array() as $row) | |
{ | |
//get the workstation duplications | |
$cql = "SELECT GROUP_CONCAT(ws_id) AS wrks | |
FROM GA_workstation | |
WHERE ws_machine_id = '".$row['ws_machine_id']."'"; | |
//get the workstations list | |
$duplicate_wrks = $this->user_database->query($cql); | |
//check the duplicate counts | |
if($duplicate_wrks->num_rows()>0) | |
{ | |
$dups = $duplicate_wrks->row_array(); | |
//get the duplicates | |
$wrks = explode(',', $dups['wrks']); | |
//check the workstations count | |
if(count($wrks)>1) | |
{ | |
//get the unique workstations | |
$unique = $wrks[0]; | |
//unset the unique value | |
unset($wrks[0]); | |
//update the workstation details in GA_job table | |
$update_job = "UPDATE GA_job SET workstation_id = {$unique} | |
WHERE workstation_id IN (".implode(',',$wrks).")"; | |
//execute the query | |
$this->user_database->query($update_job); | |
//update the workstation details in GA_printer table | |
$update_printer = "UPDATE GA_printer SET workstation_id = {$unique} | |
WHERE workstation_id IN (".implode(',',$wrks).")"; | |
//execute the query | |
$this->user_database->query($update_printer); | |
//delete the duplicate workstations | |
$delete_workstation = "DELETE FROM GA_workstation | |
WHERE workstation_id IN (".implode(',',$wrks).") | |
AND workstation_id !=".$unique; | |
//delete the workstations | |
$this->user_database->query($delete_workstation); | |
} | |
} | |
//free the cached result | |
$duplicate_wrks->free_result(); | |
}//endforeach | |
} | |
//avoiding memory leakage | |
$result->free_result(); | |
//status true | |
$status['status'] = TRUE; | |
//return status | |
return $status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment