M
M
mirexdoors2018-05-20 18:01:22
PHP
mirexdoors, 2018-05-20 18:01:22

How to get rid of the 500 error with a large script?

Hello! There is the following code that massively fills the property of the infoblock elements:

$resElements = CIBlockElement::GetList(
      	Array("SORT"=>"ASC"), 
      	Array("IBLOCK_ID"=>2,"ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y"), 
      	false, 
      	false, 
      	Array("ID", "IBLOCK_ID", "NAME")
      );
  
    if($resElements){  
    	while($obElements = $resElements->GetNextElement()){

    		$arFields = $obElements->GetFields();
 			$arProps = $obElements->GetProperties();
 			// если у элемента заполнено свойство
 			if (is_array($arProps[$NAME_PROPERTY_SNAP]['VALUE']) && !empty($arProps[$NAME_PROPERTY_SNAP]['VALUE'])) {
 				$SNAPPING_BY_PRODUCT_ARR = $arProps[$NAME_PROPERTY_SNAP]['VALUE'];
 				
 				// проверяем, есть ли уже привязка у элемента к желаемому значению свойства
 				if(in_array($SNAPPING_ID, $SNAPPING_BY_PRODUCT_ARR)){
 					// проверяем на отсутствие в выборке привязки, то есть это привязку надо удалить
 					if(in_array($SNAPPING_ID, $SNAPPING_BY_PRODUCT_ARR) && !in_array($arFields['ID'], $ARR_ELEMENT_ID) ){
   					if(($key_prop = array_search($SNAPPING_ID, $SNAPPING_BY_PRODUCT_ARR)) !== false){
                 unset($SNAPPING_BY_PRODUCT_ARR[$key_prop]);
                 $PROP = array($NAME_PROPERTY_SNAP =>$SNAPPING_BY_PRODUCT_ARR);
               $CIBlockElement->SetPropertyValuesEx($arFields['ID'], 2, $PROP);
            }
   				}
 				}else if(in_array($arFields['ID'], $ARR_ELEMENT_ID)){
 					$SNAPPING_BY_PRODUCT_ARR[] = $SNAPPING_ID;
 					$PROP = array($NAME_PROPERTY_SNAP =>$SNAPPING_BY_PRODUCT_ARR);
            $CIBlockElement->SetPropertyValuesEx($arFields['ID'], 2, $PROP);
 				}
 				
 			// если свойство не заполнено
 			}else if(in_array($arFields['ID'], $ARR_ELEMENT_ID)){
 				$PROP = array($NAME_PROPERTY_SNAP =>array($SNAPPING_ID));
        $CIBlockElement->SetPropertyValuesEx($arFields['ID'], 2, $PROP);
 			}	
    	} ?>

The trouble is that there are 13,000 elements in the infoblock. In the logs:
PHP Warning:  Unknown: Input variables exceeded 10000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0, referer: https://artameb.boxdev.ru/bitrix/admin/isvapp.iblockhelper_reson_offers.php

Increased max_input_vars to 100000 but didn't help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2018-05-20
Stifflera @PapaStifflera

500 error was invented specifically for shit code

Y
Yan-s, 2018-05-20
@Yan-s

I guess the wrong php.ini was edited.
And it is obligatory to push all this in request parameters? Send JSON and there will be no such problems.
UPD
there is also such a topic jbzoo.ru/docs/max-input-vars at the end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question