Skip to content

Commit b7828aa

Browse files
committed
Fixed issue with portable interface.
Fixed issue with Asset Import Tool. Fixed issue with Helper Tables and Custom Fields.
1 parent c9cbc2d commit b7828aa

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

admin/asset_import.php

+28-10
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ protected function btnNext_Click() {
616616
}
617617
$this->btnNext->RemoveAllActions('onclick');
618618
// Add new ajax actions for button
619-
$this->btnNext->AddAction(new QClickEvent(), new QServerAction('btnNext_Click'));
619+
$this->btnNext->AddAction(new QClickEvent(), new QAjaxAction('btnNext_Click'));
620620
$this->btnNext->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnNext));
621621
$this->btnNext->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnNext_Click'));
622622
$this->btnNext->AddAction(new QEnterKeyEvent(), new QToggleEnableAction($this->btnNext));
@@ -939,6 +939,7 @@ protected function btnNext_Click() {
939939
}
940940
// Asset Model import
941941
elseif ($this->intImportStep == 4) {
942+
$objNewAssetModelArray = array();
942943
for ($i=0; $i<$this->FileCsvData->countRows(); $i++) {
943944
$strRowArray = $this->FileCsvData->getRow($i);
944945
$strShortDescription = (trim($strRowArray[$intModelShortDescriptionKey])) ? addslashes(trim($strRowArray[$intModelShortDescriptionKey])) : false;
@@ -1035,13 +1036,13 @@ protected function btnNext_Click() {
10351036
}
10361037
}*/
10371038
$this->strModelValuesArray[] = sprintf("('%s', '%s', '%s', '%s', '%s', '%s', NOW())", $strShortDescription, (isset($intModelLongDescriptionKey)) ? addslashes(trim($strRowArray[$intModelLongDescriptionKey])) : null, $strAssetModelCode, $intCategoryId, $intManufacturerId, $_SESSION['intUserAccountId']);
1038-
$this->objNewAssetModelArray[] = $strShortDescription;
1039+
$objNewAssetModelArray[] = $strShortDescription;
10391040
}
10401041
}
10411042
//if ($this->intCurrentFile == count($this->strFilePathArray)) {
10421043
if (count($this->strModelValuesArray)) {
1043-
$strNewModelArray = array_merge($this->objNewAssetModelArray, array());
1044-
$this->objNewAssetModelArray = array();
1044+
//$strNewModelArray = array_merge($this->objNewAssetModelArray, array());
1045+
//$this->objNewAssetModelArray = array();
10451046
$objDatabase = AssetModel::GetDatabase();
10461047

10471048
//var_dump($this->strModelValuesArray);
@@ -1050,10 +1051,10 @@ protected function btnNext_Click() {
10501051
$objDatabase->NonQuery(sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`) VALUES %s;", implode(", ", $this->strModelValuesArray)));
10511052
$intStartId = $objDatabase->InsertId();
10521053

1053-
for ($i=0; $i<count($strNewModelArray); $i++) {
1054+
for ($i=0; $i<count($objNewAssetModelArray); $i++) {
10541055
//$objDatabase->NonQuery(sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`) VALUES %s;", $this->strModelValuesArray[$i]));
10551056
//$intStartId = $objDatabase->InsertId();
1056-
$this->objNewAssetModelArray[$intStartId+$i] = $strNewModelArray[$i];
1057+
$this->objNewAssetModelArray[$intStartId+$i] = $objNewAssetModelArray[$i];
10571058
}
10581059
$this->strModelValuesArray = array();
10591060
}
@@ -1381,6 +1382,19 @@ protected function btnNext_Click() {
13811382
"VALUES %s;", implode(", ", $this->strSelectedValueArray));
13821383
$objDatabase->NonQuery($strQuery);
13831384
}*/
1385+
1386+
// Insert Values into helper tables
1387+
$objDatabase = Asset::GetDatabase();
1388+
$objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=0;");
1389+
// Insert into asset_model_custom_field_helper
1390+
$objDatabase->NonQuery(sprintf("INSERT INTO `asset_model_custom_field_helper` (`asset_model_id`) (SELECT `asset_model_id` FROM `asset_model` WHERE `asset_model_id` NOT IN (SELECT `asset_model_id` FROM `asset_model_custom_field_helper`));"));
1391+
// Insert into category_custom_field_helper
1392+
$objDatabase->NonQuery(sprintf("INSERT INTO `category_custom_field_helper` (`category_id`) (SELECT `category_id` FROM `category` WHERE `category_id` NOT IN (SELECT `category_id` FROM `category_custom_field_helper`));"));
1393+
// Insert into manufacturer_custom_field_helper
1394+
$objDatabase->NonQuery(sprintf("INSERT INTO `manufacturer_custom_field_helper` (`manufacturer_id`) (SELECT `manufacturer_id` FROM `manufacturer` WHERE `manufacturer_id` NOT IN (SELECT `manufacturer_id` FROM `manufacturer_custom_field_helper`));"));
1395+
// Inserts end
1396+
$objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=1;");
1397+
13841398
$this->blnImportEnd = true;
13851399
$this->btnNext->Warning = "";
13861400

@@ -1691,17 +1705,21 @@ protected function UndoImport() {
16911705
$strQuery = "SET FOREIGN_KEY_CHECKS=1;";
16921706
$objDatabase->NonQuery($strQuery);
16931707
}
1708+
//$strQuery = "SET FOREIGN_KEY_CHECKS=0;";
1709+
//$objDatabase->NonQuery($strQuery);
16941710
if (count($this->objNewAssetArray)) {
16951711
$strQuery = sprintf("DELETE FROM `asset` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
16961712
$objDatabase->NonQuery($strQuery);
1697-
$strQuery = sprintf("DELETE FROM `asset_custom_field_helper` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
1698-
$objDatabase->NonQuery($strQuery);
1713+
// Do not need to delete it manually (automatically CASCADE deletion)
1714+
//$strQuery = sprintf("DELETE FROM `asset_custom_field_helper` WHERE `asset_id` IN (%s)", implode(", ", array_keys($this->objNewAssetArray)));
1715+
//$objDatabase->NonQuery($strQuery);
16991716
}
17001717
if (count($this->objNewAssetModelArray)) {
17011718
$strQuery = sprintf("DELETE FROM `asset_model` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
17021719
$objDatabase->NonQuery($strQuery);
1703-
$strQuery = sprintf("DELETE FROM `asset_model_custom_field_helper` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
1704-
$objDatabase->NonQuery($strQuery);
1720+
// Do not need to delete it manually (automatically CASCADE deletion)
1721+
//$strQuery = sprintf("DELETE FROM `asset_model_custom_field_helper` WHERE `asset_model_id` IN (%s)", implode(", ", array_keys($this->objNewAssetModelArray)));
1722+
//$objDatabase->NonQuery($strQuery);
17051723
}
17061724
if (count($this->objNewManufacturerArray)) {
17071725
$strQuery = sprintf("DELETE FROM `manufacturer` WHERE `manufacturer_id` IN (%s)" , implode(", ", array_keys($this->objNewManufacturerArray)));

admin/custom_field_edit.php

+7
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,13 @@ protected function UpdateEntityQtypeCustomFields() {
740740
$objDatabase = CustomField::GetDatabase();
741741
$strQuery = sprintf("ALTER TABLE %s ADD `cfv_%s` TEXT DEFAULT NULL;", $strHelperTable, $this->objCustomField->CustomFieldId);
742742
$objDatabase->NonQuery($strQuery);
743+
// If the helper table exists and have no values (empty).
744+
// It happens when the QtypeItem does not yet have the custom fields.
745+
// Uses SQL-hack to fix this issue.
746+
$strParentTableName = $strHelperTableArray[1];
747+
$strHelperTableItemId = sprintf("%s_id", $strParentTableName);
748+
$strQuery = sprintf("INSERT INTO %s (`%s`) (SELECT `%s` FROM `%s` WHERE `%s` NOT IN (SELECT `%s` FROM %s));", $strHelperTable, $strHelperTableItemId, $strHelperTableItemId, $strParentTableName, $strHelperTableItemId, $strHelperTableItemId, $strHelperTable);
749+
$objDatabase->NonQuery($strQuery);
743750
}
744751

745752
// Insert the new EntityQtypeCustomField to the RoleEntityQTypeCustomFieldAuthorization table, to all the roles, with authorized_flag set to true, one for View Auth and another for Edit Auth

portable/asset_checkout.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393

9494
// Create new AssetTransactionCheckout by that user to the same user
9595
$objAssetTransactionCheckout = new AssetTransactionCheckout();
96-
$objAssetTransactionCheckout->TransactionId = $objAssetTransaction->TransactionId;
96+
$objAssetTransactionCheckout->AssetTransactionId = $objAssetTransaction->AssetTransactionId;
9797
$objAssetTransactionCheckout->ToUserId = QApplication::$objUserAccount->UserAccountId;
9898
$objAssetTransactionCheckout->Save();
9999

@@ -114,7 +114,7 @@
114114

115115
// Create new AssetTransactionCheckout by that user to the same user for each linked asset
116116
$objAssetTransactionCheckout = new AssetTransactionCheckout();
117-
$objAssetTransactionCheckout->TransactionId = $objAssetTransaction->TransactionId;
117+
$objAssetTransactionCheckout->AssetTransactionId = $objAssetTransaction->AssetTransactionId;
118118
$objAssetTransactionCheckout->ToUserId = QApplication::$objUserAccount->UserAccountId;
119119
$objAssetTransactionCheckout->Save();
120120
}

0 commit comments

Comments
 (0)