Skip to content
Snippets Groups Projects
Commit 7c2402a2 authored by Satish's avatar Satish
Browse files

Fixes #528 - vt7: Recent Foreign Key changes can't save a Product to a Quote.

parent 1874dd43
No related branches found
No related tags found
No related merge requests found
......@@ -2170,8 +2170,7 @@ if(defined('VTIGER_UPGRADE')) {
$skippedTables = array('Calendar' => array('vtiger_seactivityrel', 'vtiger_cntactivityrel', 'vtiger_salesmanactivityrel'));
$allEntityModules = Vtiger_Module_Model::getEntityModules();
require_once './config.inc.php';
$dbName = $dbconfig['db_name'];
$dbName = $db->dbName;
foreach ($allEntityModules as $tabId => $moduleModel) {
$moduleName = $moduleModel->getName();
$baseTableName = $moduleModel->basetable;
......@@ -2200,10 +2199,18 @@ if(defined('VTIGER_UPGRADE')) {
//Checking foriegn key with base table
foreach ($relatedTables as $tableName => $index) {
$checkIfRelConstraintExists = $db->pquery($query, array($dbName, '%fk%', $tableName, $index, $baseTableName, $baseTableIndex));
$referenceTable = $baseTableName;
$referenceColumn = $baseTableIndex;
if ($tableName == 'vtiger_producttaxrel' || $tableName == 'vtiger_inventoryproductrel') {
$referenceTable = 'vtiger_crmentity';
$referenceColumn = 'crmid';
}
$checkIfRelConstraintExists = $db->pquery($query, array($dbName, '%fk%', $tableName, $index, $referenceTable, $referenceColumn));
if ($db->num_rows($checkIfRelConstraintExists) < 1) {
$newForiegnKey = "fk_$baseTableIndex"."_$tableName";
$db->pquery("ALTER TABLE $tableName ADD CONSTRAINT $newForiegnKey FOREIGN KEY ($index) REFERENCES $baseTableName ($baseTableIndex) ON DELETE CASCADE", array());
$newForiegnKey = "fk_$referenceColumn"."_$tableName";
$db->pquery("ALTER TABLE $tableName ADD CONSTRAINT $newForiegnKey FOREIGN KEY ($index) REFERENCES $referenceTable ($referenceColumn) ON DELETE CASCADE", array());
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment