示例#1
0
 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;
     }
 }