- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/classes/general/iblock.php
- Класс: CAllIBlock
- Вызов: CAllIBlock::CheckFields
function CheckFields(&$arFields, $ID=false)
{
/** @global CMain $APPLICATION */
global $APPLICATION;
$this->LAST_ERROR = "";
$NAME = $arFields["NAME"] ?? "";
if(
($ID===false || array_key_exists("NAME", $arFields))
&& (string)$NAME === ''
)
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_NAME")."
";
if($ID===false && !is_set($arFields, "IBLOCK_TYPE_ID"))
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE")."
";
if($ID===false)
{
//For new record take default values
$WORKFLOW = array_key_exists("WORKFLOW", $arFields)? $arFields["WORKFLOW"]: "Y";
$BIZPROC = array_key_exists("BIZPROC", $arFields)? $arFields["BIZPROC"]: "N";
}
else
{
//For existing one read old values
$arIBlock = CIBlock::GetArrayByID($ID);
$WORKFLOW = array_key_exists("WORKFLOW", $arFields)? $arFields["WORKFLOW"]: $arIBlock["WORKFLOW"];
$BIZPROC = array_key_exists("BIZPROC", $arFields)? $arFields["BIZPROC"]: $arIBlock["BIZPROC"];
if($BIZPROC != "Y") $BIZPROC = "N";//This is cache compatibility issue
}
if($WORKFLOW == "Y" && $BIZPROC == "Y")
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_WORKFLOW_AND_BIZPROC")."
";
if(is_set($arFields, "IBLOCK_TYPE_ID"))
{
$r = CIBlockType::GetByID($arFields["IBLOCK_TYPE_ID"]);
if(!$r->Fetch())
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_TYPE_ID")."
";
}
if(
isset($arFields["PICTURE"])
&& is_array($arFields["PICTURE"])
&& array_key_exists("bucket", $arFields["PICTURE"])
&& is_object($arFields["PICTURE"]["bucket"])
)
{
//This is trusted image from xml import
}
elseif(
isset($arFields["PICTURE"])
&& is_array($arFields["PICTURE"])
&& isset($arFields["PICTURE"]["name"])
)
{
$error = CFile::CheckImageFile($arFields["PICTURE"]);
if ($error <> '')
$this->LAST_ERROR .= $error."
";
}
if(
($ID===false && !is_set($arFields, "LID")) ||
(is_set($arFields, "LID")
&& (
(is_array($arFields["LID"]) && count($arFields["LID"])<=0)
||
(!is_array($arFields["LID"]) && $arFields["LID"] == '')
)
)
)
{
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_SITE_ID_NA")."
";
}
elseif(is_set($arFields, "LID"))
{
if(!is_array($arFields["LID"]))
$arFields["LID"] = Array($arFields["LID"]);
foreach($arFields["LID"] as $v)
{
$r = CSite::GetByID($v);
if(!$r->Fetch())
$this->LAST_ERROR .= "'".$v."' - ".GetMessage("IBLOCK_BAD_SITE_ID")."
";
}
}
if (is_set($arFields, "API_CODE"))
{
if ($arFields['API_CODE'] == '')
{
$arFields['API_CODE'] = false;
}
else
{
if (!preg_match('/^[a-z][a-z0-9]{0,49}$/i', $arFields['API_CODE']))
{
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_FIELD_API_CODE_FORMAT_ERROR").'
';
}
else
{
// check for uniqueness
$count = IblockIblockTable::getCount(MainORMQueryQuery::filter()
->where('API_CODE', $arFields['API_CODE'])
->whereNot('ID', $ID)
);
if ($count > 0)
{
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_FIELD_API_CODE_UNIQUE_ERROR").'
';
}
}
}
}
if (is_set($arFields, "REST_ON"))
{
if ($arFields['REST_ON'] !== 'Y')
{
$arFields['REST_ON'] = 'N';
}
else
{
if (!$arFields['API_CODE'])
{
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_REST_ON_WO_API_CODE").'
';
}
}
}
$APPLICATION->ResetException();
if($ID===false)
$db_events = GetModuleEvents("iblock", "OnBeforeIBlockAdd", true);
else
{
$arFields["ID"] = $ID;
$db_events = GetModuleEvents("iblock", "OnBeforeIBlockUpdate", true);
}
foreach($db_events as $arEvent)
{
$bEventRes = ExecuteModuleEventEx($arEvent, array(&$arFields));
if($bEventRes===false)
{
if($err = $APPLICATION->GetException())
$this->LAST_ERROR .= $err->GetString()."
";
else
{
$APPLICATION->ThrowException("Unknown error");
$this->LAST_ERROR .= "Unknown error.
";
}
break;
}
}
/****************************** QUOTA ******************************/
if(empty($this->LAST_ERROR) && (COption::GetOptionInt("main", "disk_space") > 0))
{
$quota = new CDiskQuota();
if(!$quota->checkDiskQuota($arFields))
$this->LAST_ERROR = $quota->LAST_ERROR;
}
/****************************** QUOTA ******************************/
if($this->LAST_ERROR <> '')
return false;
return true;
}