pass tablename to getInsertID(), add pgsql as new db driver

This commit is contained in:
Uwe Steinmann 2017-02-11 15:19:36 +01:00
parent e1fdfdbef6
commit c55b595ae9
6 changed files with 48 additions and 36 deletions

View File

@ -1870,7 +1870,7 @@ class SeedDMS_Core_DMS {
if (!$res)
return false;
$user = $this->getUser($this->db->getInsertID());
$user = $this->getUser($this->db->getInsertID('tblUsers'));
/* Check if 'onPostAddUser' callback is set */
if(isset($this->_dms->callbacks['onPostAddUser'])) {
@ -1932,7 +1932,7 @@ class SeedDMS_Core_DMS {
if (!$this->db->getResult($queryStr))
return false;
$group = $this->getGroup($this->db->getInsertID());
$group = $this->getGroup($this->db->getInsertID('tblGroups'));
/* Check if 'onPostAddGroup' callback is set */
if(isset($this->_dms->callbacks['onPostAddGroup'])) {
@ -2125,7 +2125,7 @@ class SeedDMS_Core_DMS {
if (!$this->db->getResult($queryStr))
return false;
$category = $this->getKeywordCategory($this->db->getInsertID());
$category = $this->getKeywordCategory($this->db->getInsertID('tblKeywordCategories'));
/* Check if 'onPostAddKeywordCategory' callback is set */
if(isset($this->_dms->callbacks['onPostAddKeywordCategory'])) {
@ -2201,7 +2201,7 @@ class SeedDMS_Core_DMS {
if (!$this->db->getResult($queryStr))
return false;
$category = $this->getDocumentCategory($this->db->getInsertID());
$category = $this->getDocumentCategory($this->db->getInsertID('tblCategory'));
/* Check if 'onPostAddDocumentCategory' callback is set */
if(isset($this->_dms->callbacks['onPostAddDocumentCategory'])) {
@ -2400,7 +2400,7 @@ class SeedDMS_Core_DMS {
if (!$res)
return false;
return $this->getAttributeDefinition($this->db->getInsertID());
return $this->getAttributeDefinition($this->db->getInsertID('tblAttributeDefinitions'));
} /* }}} */
/**
@ -2501,7 +2501,7 @@ class SeedDMS_Core_DMS {
if (!$res)
return false;
return $this->getWorkflow($db->getInsertID());
return $this->getWorkflow($db->getInsertID('tblWorkflows'));
} /* }}} */
/**
@ -2594,7 +2594,7 @@ class SeedDMS_Core_DMS {
if (!$res)
return false;
return $this->getWorkflowState($db->getInsertID());
return $this->getWorkflowState($db->getInsertID('tblWorkflowStates'));
} /* }}} */
/**
@ -2684,7 +2684,7 @@ class SeedDMS_Core_DMS {
if (!$res)
return false;
return $this->getWorkflowAction($db->getInsertID());
return $this->getWorkflowAction($db->getInsertID('tblWorkflowActions'));
} /* }}} */
/**

View File

@ -1586,7 +1586,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
return false;
}
$contentID = $db->getInsertID();
$contentID = $db->getInsertID('tblDocumentContent');
// copy file
if (!SeedDMS_Core_File::makeDir($this->_dms->contentDir . $dir)) {
@ -1632,7 +1632,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
return false;
}
$statusID = $db->getInsertID();
$statusID = $db->getInsertID('tblDocumentStatus', 'statusID');
if($workflow)
$content->setWorkflow($workflow, $user);
@ -2271,7 +2271,7 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
"(".$db->qstr($comment).", ".$db->getCurrentTimestamp().", ".$db->qstr($dir).", ".$this->_id.", ".$db->qstr($fileType).", ".$db->qstr($mimeType).", ".$db->qstr($orgFileName).",".$user->getID().",".$db->qstr($name).")";
if (!$db->getResult($queryStr)) return false;
$id = $db->getInsertID();
$id = $db->getInsertID('tblDocumentFiles');
$file = $this->getDocumentFile($id);
if (is_bool($file) && !$file) return false;
@ -3379,7 +3379,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction();
return false;
}
$reviewID = $db->getInsertID();
$reviewID = $db->getInsertID('tblDocumentReviewers', 'reviewID');
$reviewlog = array_reverse($review['logs']);
foreach($reviewlog as $log) {
if(!SeedDMS_Core_DMS::checkDate($log['date'], 'Y-m-d H:i:s')) {
@ -3392,7 +3392,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction();
return false;
}
$reviewLogID = $db->getInsertID();
$reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID');
if(!empty($log['file'])) {
SeedDMS_Core_File::copyFile($log['file'], $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID);
}
@ -3507,7 +3507,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction();
return false;
}
$reviewID = $db->getInsertID();
$reviewID = $db->getInsertID('tblDocumentApprovers', 'approveID');
$reviewlog = array_reverse($review['logs']);
foreach($reviewlog as $log) {
if(!SeedDMS_Core_DMS::checkDate($log['date'], 'Y-m-d H:i:s')) {
@ -3520,7 +3520,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
$db->rollbackTransaction();
return false;
}
$approveLogID = $db->getInsertID();
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
if(!empty($log['file'])) {
SeedDMS_Core_File::copyFile($log['file'], $this->_dms->contentDir . $this->_document->getDir() . 'a' . $approveLogID);
}
@ -3667,7 +3667,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res) {
return -1;
}
$reviewID = $db->getInsertID();
$reviewID = $db->getInsertID('tblDocumentReviewers', 'reviewID');
}
else {
$reviewID = isset($indstatus["reviewID"]) ? $indstatus["reviewID"] : NULL;
@ -3725,7 +3725,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res) {
return -1;
}
$reviewID = $db->getInsertID();
$reviewID = $db->getInsertID('tblDocumentReviewers', 'reviewID');
}
else {
$reviewID = isset($reviewStatus[0]["reviewID"])?$reviewStatus[0]["reviewID"]:NULL;
@ -3795,7 +3795,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res)
return -1;
$reviewLogID = $db->getInsertID();
$reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID');
if($file) {
SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID);
}
@ -3847,7 +3847,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res)
return -1;
else {
$reviewLogID = $db->getInsertID();
$reviewLogID = $db->getInsertID('tblDocumentReviewLog', 'reviewLogID');
if($file) {
SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'r' . $reviewLogID);
}
@ -3887,7 +3887,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res) {
return -1;
}
$approveID = $db->getInsertID();
$approveID = $db->getInsertID('tblDocumentApprovers', 'approveID');
}
else {
$approveID = isset($indstatus["approveID"]) ? $indstatus["approveID"] : NULL;
@ -3900,7 +3900,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
return -1;
}
$approveLogID = $db->getInsertID();
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
return $approveLogID;
} /* }}} */
@ -3943,7 +3943,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res) {
return -1;
}
$approveID = $db->getInsertID();
$approveID = $db->getInsertID('tblDocumentApprovers', 'approveID');
}
else {
$approveID = isset($approvalStatus[0]["approveID"])?$approvalStatus[0]["approveID"]:NULL;
@ -3959,7 +3959,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
// Add approver to event notification table.
//$this->_document->addNotify($groupID, false);
$approveLogID = $db->getInsertID();
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
return $approveLogID;
} /* }}} */
@ -4017,7 +4017,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res)
return -1;
$approveLogID = $db->getInsertID();
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
if($file) {
SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'a' . $approveLogID);
}
@ -4061,7 +4061,7 @@ class SeedDMS_Core_DocumentContent extends SeedDMS_Core_Object { /* {{{ */
if (is_bool($res) && !$res)
return -1;
$approveLogID = $db->getInsertID();
$approveLogID = $db->getInsertID('tblDocumentApproveLog', 'approveLogID');
if($file) {
SeedDMS_Core_File::copyFile($file, $this->_dms->contentDir . $this->_document->getDir() . 'a' . $approveLogID);
}

View File

@ -520,7 +520,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
$db->rollbackTransaction();
return false;
}
$newFolder = $this->_dms->getFolder($db->getInsertID());
$newFolder = $this->_dms->getFolder($db->getInsertID('tblFolders'));
unset($this->_subFolders);
if($attributes) {
@ -827,7 +827,7 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
return false;
}
$document = $this->_dms->getDocument($db->getInsertID());
$document = $this->_dms->getDocument($db->getInsertID('tblDocuments'));
// if ($version_comment!="")
$res = $document->addContent($version_comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType, $reviewers, $approvers, $reqversion, $version_attributes, $workflow, $initstate);

View File

@ -223,12 +223,15 @@ class SeedDMS_Core_Object { /* {{{ */
if(!isset($this->_attributes[$attrdef->getId()])) {
switch(get_class($this)) {
case $this->_dms->getClassname('document'):
$tablename = 'tblDocumentAttributes';
$queryStr = "INSERT INTO `tblDocumentAttributes` (`document`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
break;
case $this->_dms->getClassname('documentcontent'):
$tablename = 'tblDocumentContentAttributes';
$queryStr = "INSERT INTO `tblDocumentContentAttributes` (`content`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
break;
case $this->_dms->getClassname('folder'):
$tablename = 'tblFolderAttributes';
$queryStr = "INSERT INTO `tblFolderAttributes` (`folder`, `attrdef`, `value`) VALUES (".$this->_id.", ".$attrdef->getId().", ".$db->qstr($value).")";
break;
default:
@ -238,7 +241,7 @@ class SeedDMS_Core_Object { /* {{{ */
if (!$res)
return false;
$attr = new SeedDMS_Core_Attribute($db->getInsertID(), $this, $attrdef, $value);
$attr = new SeedDMS_Core_Attribute($db->getInsertID($tablename), $this, $attrdef, $value);
$attr->setDMS($this->_dms);
$this->_attributes[$attrdef->getId()] = $attr;
return true;

View File

@ -286,7 +286,7 @@ class SeedDMS_Core_Workflow { /* {{{ */
* transitions are added in a row, without reloading the workflow
*/
$this->_transitions = array();
$transition = $this->getTransition($db->getInsertID());
$transition = $this->getTransition($db->getInsertID('tblWorkflowTransitions'));
foreach($users as $user) {
$queryStr = "INSERT INTO `tblWorkflowTransitionUsers` (`transition`, `userid`) VALUES (".$transition->getID().", ".$user->getID().")";

View File

@ -176,6 +176,7 @@ class SeedDMS_Core_DatabaseAccess {
case 'mysql':
case 'mysqli':
case 'mysqlnd':
case 'pgsql':
$dsn = $this->_driver.":dbname=".$this->_database.";host=".$this->_hostname;
if($this->_port)
$dsn .= ";port=".$this->_port;
@ -234,7 +235,7 @@ class SeedDMS_Core_DatabaseAccess {
* @return string sanitized string
*/
function rbt($text) { /* {{{ */
return str_replace('`', '"');
return str_replace('`', '"', $text);
} /* }}} */
/**
@ -245,9 +246,12 @@ class SeedDMS_Core_DatabaseAccess {
* @param string $queryStr sql query
* @return array/boolean data if query could be executed otherwise false
*/
function getResultArray($queryStr) { /* {{{ */
function getResultArray($queryStr, $retick=true) { /* {{{ */
$resArr = array();
if($retick && $this->_driver == 'pgsql') {
$queryStr = $this->rbt($queryStr);
}
$res = $this->_conn->query($queryStr);
if ($res === false) {
if($this->_debug)
@ -265,11 +269,13 @@ class SeedDMS_Core_DatabaseAccess {
* Call this function only with sql query which do not return data records.
*
* @param string $queryStr sql query
* @param boolean $silent not used anymore. This was used when this method
* still issued an error message
* @param boolean $retick replace all '`' by '"'
* @return boolean true if query could be executed otherwise false
*/
function getResult($queryStr, $silent=false) { /* {{{ */
function getResult($queryStr, $retick=true) { /* {{{ */
if($retick && $this->_driver == 'pgsql') {
$queryStr = $this->rbt($queryStr);
}
$res = $this->_conn->exec($queryStr);
if($res === false) {
if($this->_debug)
@ -307,8 +313,11 @@ class SeedDMS_Core_DatabaseAccess {
*
* @return integer id used in last autoincrement
*/
function getInsertID() { /* {{{ */
return $this->_conn->lastInsertId();
function getInsertID($tablename='', $fieldname='id') { /* {{{ */
if($this->_driver == 'pgsql')
return $this->_conn->lastInsertId($tablename.'_'.$fieldname.'_seq');
else
return $this->_conn->lastInsertId();
} /* }}} */
function getErrorMsg() { /* {{{ */