}
/**
- * Simple comma seperated number string
+ * Simple comma separated number string
*
* @param string $string
* @return bool
}
if(!empty($ids)) {
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$queryStr1 = "DELETE FROM `".DB_PREFIX."_collection_fields_".$this->_collectionId."`
WHERE `fk_field_id` NOT IN (".implode(",",$ids).")";
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$q1 = $this->_DB->query($queryStr1);
if($q1 !== false) {
// https://dev.mysql.com/doc/refman/8.0/en/insert-on-duplicate.html
$alterQuery = $this->_DB->query($alterString);
}
if(!empty($_newColumns) && $alterQuery == false) {
- $this->_DB->rollback();
- }
- else {
- $this->_DB->commit();
- $ret = true;
+ throw new Exception("Failed to insert alter the table.");
}
}
else {
- $this->_DB->rollback();
+ throw new Exception("Failed to insert the new fields.");
}
}
+ else {
+ throw new Exception("Failed to delete old fields.");
+ }
+ $this->_DB->commit();
+ $ret = true;
}
catch (Exception $e) {
+ $this->_DB->rollback();
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
}
if(!empty($data['name']) === true
&& $this->_validNewCollectionName($data['name']) === true
) {
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$queryStr = "INSERT INTO `".DB_PREFIX."_collection`
SET `name` = '".$this->_DB->real_escape_string($data['name'])."',
`description` = '".$this->_DB->real_escape_string($data['description'])."',
private function _updateToolRelation($id,$tool) {
$ret = false;
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$queryStr = "DELETE FROM `".DB_PREFIX."_tool2collection`
WHERE `fk_collection_id` = '".$this->_DB->real_escape_string($id)."'";
if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$this->_DB->query($queryStr);
if(!empty($tool)) {
if(DEBUG) error_log("[DEBUG] ".__METHOD__." queryData: ".var_export($queryData,true));
if(!empty($queryData['init'])) {
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$queryStr = "INSERT INTO `".DB_PREFIX."_collection_entry_".$this->_collectionId."`";
if($update !== false && is_numeric($update)) {
if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$this->_DB->query($queryStr);
if($update !== false && is_numeric($update)) {
$this->_runAfter_upload($q, $newId);
}
}
-
- $this->_DB->commit();
- $ret = $newId;
}
else {
- $this->_DB->rollback();
+ throw new Exception('Failed to create entry');
}
+
+ $ret = $newId;
+ $this->_DB->commit();
}
catch (Exception $e) {
$this->_DB->rollback();
if(!empty($entryId) && !empty($this->_collectionId)) {
if ($this->_canDelete($entryId)) {
-
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
-
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
// remove assets
$_path = PATH_STORAGE.'/'.$this->_collectionId.'/'.$entryId;
if(is_dir($_path) && is_readable($_path)) {
} else {
$active = "0";
}
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
$_password = password_hash($password, PASSWORD_DEFAULT);
`group` = '".$this->_DB->real_escape_string($group)."'";
if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$query = $this->_DB->query($queryStr);
if ($query !== false) {
if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStrOwner,true));
$this->_DB->query($queryStrOwner);
$_setGroupRelation = $this->_setGroupReleation($_userid,$group);
- if($_setGroupRelation !== false) {
- $this->_DB->commit();
- $ret = true;
- }
- else {
- $this->_DB->rollback();
- error_log('ERROR Failed to insert user relation: '.var_export($queryStr, true));
+ if($_setGroupRelation === false) {
+ throw new Exception("Failed to insert user relation");
}
} else {
- $this->_DB->rollback();
- error_log('ERROR Failed to insert user: '.var_export($queryStr, true));
+ throw new Exception("Failed to insert user");
}
+
+ $this->_DB->commit();
+ $ret = true;
}
catch (Exception $e) {
+ $this->_DB->rollback();
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
}
$_password = password_hash($password, PASSWORD_DEFAULT);
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$queryStr = "UPDATE `".DB_PREFIX . "_user`
SET `name` = '".$this->_DB->real_escape_string($username)."',
AND `protected` = '0'";
if(QUERY_DEBUG) error_log("[QUERY] ".__METHOD__." query: ".var_export($queryStr,true));
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
+
$query = $this->_DB->query($queryStr);
if ($query !== false) {
$_setGroupRelation = $this->_setGroupReleation($id,$group, true);
- if($_setGroupRelation !== false) {
- $this->_DB->commit();
- $ret = true;
- }
- else {
- $this->_DB->rollback();
- error_log('ERROR Failed to insert user relation: '.var_export($queryStr, true));
+ if($_setGroupRelation === false) {
+ throw new Exception('Failed to insert user relation');
}
} else {
- $this->_DB->rollback();
- error_log('ERROR Failed to insert user: '.var_export($queryStr, true));
+ throw new Exception('Failed to insert user');
}
+ $this->_DB->commit();
+ $ret = true;
}
catch (Exception $e) {
+ $this->_DB->rollback();
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
}
$ret = false;
if(!empty($id)) {
- $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
-
try {
+ $this->_DB->begin_transaction(MYSQLI_TRANS_START_READ_WRITE);
$d1 = $this->_DB->query("DELETE FROM `".DB_PREFIX."_user`
WHERE `id` = '".$this->_DB->real_escape_string($id)."'
AND `protected` = '0'");
$d2 = $this->_DB->query("DELETE FROM `".DB_PREFIX."_user2group` WHERE `fk_user_id` = '".$this->_DB->real_escape_string($id)."'");
$d3 = $this->_DB->query("DELETE FROM `".DB_PREFIX."_userSession` WHERE `fk_user_id` = '".$this->_DB->real_escape_string($id)."'");
- if($d1 !== false && $d2 !== false && $d3 !== false) {
- $this->_DB->commit();
- $ret = true;
- }
- else {
- $this->_DB->rollback();
+ if($d1 === false || $d2 === false || $d3 === false) {
+ throw new Exception('Failed to delete the user');
}
+ $this->_DB->commit();
+ $ret = true;
}
catch (Exception $e) {
+ $this->_DB->rollback();
error_log("[ERROR] ".__METHOD__." mysql catch: ".$e->getMessage());
}
}