public function Update($ID, $arFields) { global $DB; $ID = (int) $ID; if ($ID <= 0) { return false; } $boolNewVersion = true; $arFields['ID'] = $ID; if (!array_key_exists('CONDITIONS', $arFields) && !array_key_exists('ACTIONS', $arFields)) { $boolConvert = CSaleDiscount::__ConvertOldFormat('UPDATE', $arFields); if (!$boolConvert) { return false; } $boolNewVersion = false; } if (!CSaleDiscount::CheckFields("UPDATE", $arFields)) { return false; } if ($boolNewVersion) { $boolConvert = CSaleDiscount::__SetOldFields('UPDATE', $arFields); if (!$boolConvert) { return false; } } $strUpdate = $DB->PrepareUpdate("b_sale_discount", $arFields); if (!empty($strUpdate)) { $strSql = "update b_sale_discount set " . $strUpdate . " where ID = " . $ID; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if (isset($arFields['USER_GROUPS'])) { Internals\DiscountGroupTable::updateByDiscount($ID, $arFields['USER_GROUPS'], isset($arFields['ACTIVE']) ? $arFields['ACTIVE'] : '', true); } elseif (isset($arFields['ACTIVE'])) { Internals\DiscountGroupTable::changeActiveByDiscount($ID, $arFields['ACTIVE']); } if (isset($arFields['HANDLERS'])) { self::updateDiscountHandlers($ID, $arFields['HANDLERS'], true); } if (isset($arFields['ENTITIES'])) { Internals\DiscountEntitiesTable::updateByDiscount($ID, $arFields['ENTITIES'], true); } return $ID; }
public function runOperation() { global $APPLICATION; $this->getDeliveryCodes(); $found = false; $filter = array('>ID' => $this->lastID, '=VERSION' => Sale\Internals\DiscountTable::VERSION_NEW); $discountsIterator = Sale\Internals\DiscountTable::getList(array('select' => array('ID', 'MODIFIED_BY', 'TIMESTAMP_X', 'CONDITIONS_LIST', 'ACTIONS_LIST', 'NAME'), 'filter' => $filter, 'order' => array('ID' => 'ASC'), 'limit' => $this->maxOperationCounter)); while ($discount = $discountsIterator->fetch()) { $found = true; $error = array(); $this->convertDelivery($discount['CONDITIONS_LIST']); $rawFields = array('ID' => $discount['ID'], 'CONDITIONS' => $discount['CONDITIONS_LIST'], 'ACTIONS' => $discount['ACTIONS_LIST']); if (\CSaleDiscount::checkFields('UPDATE', $rawFields)) { $fields = array('MODIFIED_BY' => $discount['MODIFIED_BY'], 'TIMESTAMP_X' => $discount['TIMESTAMP_X'], 'UNPACK' => $rawFields['UNPACK'], 'CONDITIONS' => $discount['CONDITIONS_LIST'], 'VERSION' => Sale\Internals\DiscountTable::VERSION_15); if (isset($rawFields['EXECUTE_MODULE'])) { $fields['EXECUTE_MODULE'] = $rawFields['EXECUTE_MODULE']; } $updateResult = Sale\Internals\DiscountTable::update($discount['ID'], $fields); if ($updateResult->isSuccess()) { if (isset($rawFields['ENTITIES'])) { Sale\Internals\DiscountEntitiesTable::updateByDiscount($discount['ID'], $rawFields['ENTITIES'], true); } if (isset($rawFields['HANDLERS']['MODULES'])) { Sale\Internals\DiscountModuleTable::updateByDiscount($discount['ID'], $rawFields['HANDLERS']['MODULES'], true); } } else { $error = $updateResult->getErrorMessages(); } } else { if ($ex = $APPLICATION->GetException()) { $error[] = $ex->GetString(); } else { $error[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_UPDATE_UNKNOWN_ERROR'); } } $this->lastID = $discount['ID']; $this->allOperationCounter++; if (!empty($error)) { $this->errorCounter++; $this->errors[] = Loc::getMessage('SALE_DISCOUNT_REINDEX_ORDER_ERROR_REPORT', array('#URL#' => str_replace('#ID#', $discount['ID'], $this->discountEditUrl), '#TITLE#' => trim((string) $discount['NAME']) != '' ? $discount['NAME'] : $discount['ID'], '#ERRORS#' => implode('; ', $error))); } if ($this->maxExecutionTime > 0 && time() - $this->startOperationTime > $this->maxExecutionTime) { break; } } unset($discount, $discountsIterator); if (!$found) { $this->finishOperation = true; } }
public function Update($ID, $arFields) { global $DB; $ID = (int) $ID; if ($ID <= 0) { return false; } $boolNewVersion = true; $arFields['ID'] = $ID; if (!array_key_exists('CONDITIONS', $arFields) && !array_key_exists('ACTIONS', $arFields)) { $boolConvert = CSaleDiscount::__ConvertOldFormat('UPDATE', $arFields); if (!$boolConvert) { return false; } $boolNewVersion = false; } if (!CSaleDiscount::CheckFields("UPDATE", $arFields)) { return false; } if ($boolNewVersion) { $boolConvert = CSaleDiscount::__SetOldFields('UPDATE', $arFields); if (!$boolConvert) { return false; } } $strUpdate = $DB->PrepareUpdate("b_sale_discount", $arFields); if (!empty($strUpdate)) { $strSql = "update b_sale_discount set " . $strUpdate . " where ID = " . $ID; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } if (isset($arFields['USER_GROUPS'])) { Internals\DiscountGroupTable::updateByDiscount($ID, $arFields['USER_GROUPS'], isset($arFields['ACTIVE']) ? $arFields['ACTIVE'] : '', true); } elseif (isset($arFields['ACTIVE'])) { Internals\DiscountGroupTable::changeActiveByDiscount($ID, $arFields['ACTIVE']); } if (isset($arFields['HANDLERS'])) { self::updateDiscountHandlers($ID, $arFields['HANDLERS'], true); } if (isset($arFields['ENTITIES'])) { Internals\DiscountEntitiesTable::updateByDiscount($ID, $arFields['ENTITIES'], true); } if (isset($arFields['ACTIONS']) && is_string($arFields['ACTIONS'])) { \Bitrix\Sale\Discount\Gift\RelatedDataTable::deleteByDiscount($ID); $giftManager = \Bitrix\Sale\Discount\Gift\Manager::getInstance(); if ($giftManager->isContainGiftAction($arFields)) { if (!$giftManager->existsDiscountsWithGift()) { $giftManager->enableExistenceDiscountsWithGift(); } \Bitrix\Sale\Discount\Gift\RelatedDataTable::fillByDiscount($arFields + array('ID' => $ID)); } } return $ID; }