query($sql); $exist = TRUE; if ($result == NULL) { // no result ... $exist = FALSE; } //echo("find result : ".$result); if ($result->num_rows > 0) { $userGroup = $result->fetch_assoc(); $idGroup = $userGroup['id']; } else { $exist = FALSE; } if ($exist == FALSE) { // create a new one ... $sql = " INSERT INTO `CI_group` (`user-name`, `lib-name`, `lib-branch`)" ." VALUES ('".$userName."'," ." '".$libName."'," ." '".$_POST['LIB_BRANCH']."')"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { $exist == TRUE; $idGroup = $COVERAGE_bdd->insert_id; } else { echo "[ERROR] Can not CREATE new group ..."; } } if ($idGroup <= -1) { echo("[ERROR] can not create or find group"); } else { $sql = " INSERT INTO `BUILD_list` (`time`, `id-group`, `sha1`, `tag`, `status`, `stage`)" ." VALUES ('".time()."'," ." '".$idGroup."'," ." '".$_POST['SHA1']."'," ." '".$_POST['TAG']."'," ." '".$_POST['STATUS']."'," ." '".$_POST['STAGE']."')"; //echo $sql; $result = $COVERAGE_bdd->query($sql); if ($result == FALSE) { echo("[ERROR] Can not register in db ... (LIST)"); } $sql = "SELECT `BUILD_snapshot`.`id` " ." AND `BUILD_snapshot`.`json` " ." FROM `BUILD_snapshot`" ." , `CI_group`" ." WHERE `CI_group`.`user-name` = '".$userName."'" ." AND `CI_group`.`lib-name` = '".$libName."'" ." AND `CI_group`.`lib-branch` = '".$_POST['LIB_BRANCH']."'" ." AND `CI_group`.`id` = `BUILD_snapshot`.`id-group`" ." LIMIT 1"; $result = $COVERAGE_bdd->query($sql); //echo("sql : ".$sql); if ( $result == NULL || $result->num_rows == 0) { // simply insert: $sql = " INSERT INTO `BUILD_snapshot` (`id-build`, `id-group`, `json`)" ." VALUES ('".$_POST['ID']."'," ." '".$idGroup."'," ." '{\"".$_POST['TAG']."\":\"".$_POST['STATUS']."\"')"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { echo("[OK] registered done (new entry)"); } else { echo("[ERROR] Can not register in db ... (snapshot 1)"); } } else { // update the entry: if ( $result->num_rows == 1) { $row = $result->fetch_assoc(); $jsonRaw = $row["json"]; } else { die ("error occured ..."); } $data = json_decode($jsonRaw); $data[$_POST['TAG']] = $_POST['STATUS']; $jsonRaw = json_encode($data) // try to update the curent values: $sql = " UPDATE `BUILD_snapshot`" ." SET `BUILD_snapshot`.`json` = '".$jsonRaw."'" ." WHERE `BUILD_snapshot`.`id-group` = '".$idGroup."'"; $result = $COVERAGE_bdd->query($sql); if ($result == TRUE) { echo("[OK] registered done (update)"); } else { echo("[ERROR] Can not register in db ... (snapshot 2)"); } } } // simply close link with the DB... $COVERAGE_bdd->close(); ?>