/** * deletes a request with a requestID on a users DB. * * @param $userdb * @param $requestId * @return bool */ public function deleteRequest($userdb, $requestId) { $username = RequestHelper::readUsernameFromRequest(); //control variable $all_query_ok = true; //disable autocommit so commit/rollback is possible $this->core->dbh->autocommit(false); // select all intervention IDs with the specified RequestID as an array if ($stmt = $this->core->dbh->query("SELECT IntervID FROM intervention WHERE Request_id = '" . $requestId . "'")) { $row = $stmt->fetch_row(); $stmt->close(); } else { $all_query_ok = false; } if (!$all_query_ok) { LogHelper::write("select intervid failed", $username); } //skip deleting intervention work and material if no interventions are in the DB //delete from intervention_material and intervention_work if (!empty($row)) { $oIntervention = new Intervention($userdb); foreach ($row as $intervID) { $all_query_ok &= $oIntervention->deleteInterventionMaterial($intervID); $all_query_ok &= $oIntervention->deleteInterventionWork($intervID); } } //delete from interventions $this->core->dbh->query("DELETE FROM intervention WHERE Request_id = '" . $requestId . "'") ? false : ($all_query_ok = false); if (!$all_query_ok) { LogHelper::write("delete intervention failed", $username); } //delete from requests $this->core->dbh->query("DELETE FROM request WHERE Request_id = '" . $requestId . "'") ? false : ($all_query_ok = false); if (!$all_query_ok) { LogHelper::write("delete request failed", $username); } // commit or rollback if ($all_query_ok) { $this->core->dbh->commit(); $this->core->dbh->close(); return TRUE; } else { $this->core->dbh->rollback(); $this->core->dbh->close(); return FALSE; } }
/** * Deletes an asset and its belonging requests, interventions and intervention material and work * * @param $userdb * @param $assetId * @return bool */ public function deleteAsset($userdb, $assetId) { //prevent sql injection $assetId = mysqli_real_escape_string($this->core->dbh, $assetId); //control variable $all_query_ok = true; //disable autocommit so commit/rollback is possible $this->core->dbh->autocommit(false); // select all intervention IDs with the specified AssetID as an array if ($stmt = $this->core->dbh->query("SELECT IntervID FROM intervention WHERE AssetID_Visit = '" . $assetId . "'")) { $row = $stmt->fetch_row(); $stmt->close(); } else { $all_query_ok = false; } //skip deleting intervention work and material if no interventions are in the DB //delete from intervention_material and intervention_work if (!empty($row)) { $oIntervention = new Intervention($userdb); foreach ($row as $intervID) { $all_query_ok &= $oIntervention->deleteInterventionMaterial($intervID); $all_query_ok &= $oIntervention->deleteInterventionWork($intervID); } } //delete from interventions $this->core->dbh->query("DELETE FROM intervention WHERE AssetID_Visit = '" . $assetId . "'") ? false : ($all_query_ok = false); //delete from requests $this->core->dbh->query("DELETE FROM request WHERE AssetID = '" . $assetId . "'") ? false : ($all_query_ok = false); //delete from assets $this->core->dbh->query("DELETE FROM assets WHERE AssetID = '" . $assetId . "'") ? false : ($all_query_ok = false); // commit or rollback if ($all_query_ok) { $this->core->dbh->commit(); $this->core->dbh->close(); return TRUE; } else { $this->core->dbh->rollback(); $this->core->dbh->close(); return FALSE; } }