Update
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
use Bitrix\Main;
|
||||
use Bitrix\Iblock;
|
||||
use Bitrix\Main\Application;
|
||||
use Bitrix\Main\Data\Cache;
|
||||
|
||||
class CIBlockRights
|
||||
{
|
||||
@@ -25,6 +27,8 @@ class CIBlockRights
|
||||
protected static $arLetterToTask = null;
|
||||
protected static $arLetterToOperations = null;
|
||||
|
||||
protected static string $tagCacheStartWith = '/iblock/rights/';
|
||||
|
||||
function __construct($IBLOCK_ID)
|
||||
{
|
||||
$this->IBLOCK_ID = (int)$IBLOCK_ID;
|
||||
@@ -267,34 +271,36 @@ class CIBlockRights
|
||||
function GetRights($arOptions = array())
|
||||
{
|
||||
global $DB;
|
||||
$arResult = array();
|
||||
$arResult = [];
|
||||
|
||||
if(
|
||||
if (
|
||||
!isset($arOptions["operations"])
|
||||
|| !is_array($arOptions["operations"])
|
||||
|| empty($arOptions["operations"])
|
||||
)
|
||||
{
|
||||
$rs = $DB->Query("
|
||||
SELECT
|
||||
BR.ID
|
||||
,BR.GROUP_CODE
|
||||
,BR.TASK_ID
|
||||
,BR.DO_INHERIT
|
||||
,'N' IS_INHERITED
|
||||
,BR.XML_ID
|
||||
,BR.ENTITY_TYPE
|
||||
,BR.ENTITY_ID
|
||||
FROM
|
||||
b_iblock_right BR
|
||||
WHERE
|
||||
BR.IBLOCK_ID = ".$this->IBLOCK_ID."
|
||||
AND BR.ENTITY_TYPE = 'iblock'
|
||||
ORDER BY
|
||||
BR.ID
|
||||
");
|
||||
$rs = Iblock\IblockRightTable::getList([
|
||||
"select" => [
|
||||
"ID",
|
||||
"GROUP_CODE",
|
||||
"TASK_ID",
|
||||
"DO_INHERIT",
|
||||
"IS_INHERITED",
|
||||
"XML_ID",
|
||||
"ENTITY_TYPE",
|
||||
"ENTITY_ID",
|
||||
],
|
||||
"filter" => [
|
||||
"=IBLOCK_ID" => $this->IBLOCK_ID,
|
||||
"=ENTITY_TYPE" => "iblock",
|
||||
],
|
||||
"runtime" => [
|
||||
new Bitrix\Main\ORM\Fields\ExpressionField('IS_INHERITED', "'N'")
|
||||
],
|
||||
"order" => ["ID"],
|
||||
]);
|
||||
}
|
||||
elseif(
|
||||
elseif (
|
||||
isset($arOptions["operations_mode"])
|
||||
&& $arOptions["operations_mode"] == CIBlockRights::ALL_OPERATIONS
|
||||
&& count($arOptions["operations"]) > 1
|
||||
@@ -302,41 +308,41 @@ class CIBlockRights
|
||||
{
|
||||
$arOperations = array_map(array($DB, "ForSQL"), $arOptions["operations"]);
|
||||
$rs = $DB->Query("
|
||||
SELECT
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
|
||||
FROM
|
||||
b_iblock_right BR
|
||||
INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
|
||||
INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
|
||||
WHERE
|
||||
BR.IBLOCK_ID = ".$this->IBLOCK_ID."
|
||||
AND BR.ENTITY_TYPE = 'iblock'
|
||||
AND O.NAME IN ('".implode("', '", $arOperations)."')
|
||||
GROUP BY
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT
|
||||
HAVING
|
||||
COUNT(DISTINCT O.ID) = ".count($arOperations)."
|
||||
ORDER BY
|
||||
BR.ID
|
||||
");
|
||||
SELECT
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
|
||||
FROM
|
||||
b_iblock_right BR
|
||||
INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
|
||||
INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
|
||||
WHERE
|
||||
BR.IBLOCK_ID = " . $this->IBLOCK_ID . "
|
||||
AND BR.ENTITY_TYPE = 'iblock'
|
||||
AND O.NAME IN ('" . implode("', '", $arOperations) . "')
|
||||
GROUP BY
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT
|
||||
HAVING
|
||||
COUNT(DISTINCT O.ID) = " . count($arOperations) . "
|
||||
ORDER BY
|
||||
BR.ID
|
||||
");
|
||||
}
|
||||
else//if($opMode == CIBlockRights::ANY_OPERATION)
|
||||
{
|
||||
$arOperations = array_map(array($DB, "ForSQL"), $arOptions["operations"]);
|
||||
$rs = $DB->Query("
|
||||
SELECT DISTINCT
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
|
||||
FROM
|
||||
b_iblock_right BR
|
||||
INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
|
||||
INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
|
||||
WHERE
|
||||
BR.IBLOCK_ID = ".$this->IBLOCK_ID."
|
||||
AND BR.ENTITY_TYPE = 'iblock'
|
||||
AND O.NAME IN ('".implode("', '", $arOperations)."')
|
||||
ORDER BY
|
||||
BR.ID
|
||||
");
|
||||
SELECT DISTINCT
|
||||
BR.ID, BR.GROUP_CODE, BR.TASK_ID, BR.DO_INHERIT, 'N' IS_INHERITED, BR.XML_ID
|
||||
FROM
|
||||
b_iblock_right BR
|
||||
INNER JOIN b_task_operation T ON T.TASK_ID = BR.TASK_ID
|
||||
INNER JOIN b_operation O ON O.ID = T.OPERATION_ID
|
||||
WHERE
|
||||
BR.IBLOCK_ID = " . $this->IBLOCK_ID . "
|
||||
AND BR.ENTITY_TYPE = 'iblock'
|
||||
AND O.NAME IN ('" . implode("', '", $arOperations) . "')
|
||||
ORDER BY
|
||||
BR.ID
|
||||
");
|
||||
}
|
||||
|
||||
$obStorage = $this->_storage_object();
|
||||
@@ -346,14 +352,46 @@ class CIBlockRights
|
||||
"GROUP_CODE" => $ar["GROUP_CODE"],
|
||||
"DO_INHERIT" => $ar["DO_INHERIT"],
|
||||
"IS_INHERITED" => $ar["IS_INHERITED"],
|
||||
"OVERWRITED" => isset($arOptions["count_overwrited"]) && $arOptions["count_overwrited"]? $obStorage->CountOverWrited($ar["GROUP_CODE"]): 0,
|
||||
"OVERWRITED" => (isset($arOptions["count_overwrited"]) && $arOptions["count_overwrited"]) ? $obStorage->CountOverWrited($ar["GROUP_CODE"]) : 0,
|
||||
"TASK_ID" => $ar["TASK_ID"],
|
||||
"XML_ID" => $ar["XML_ID"],
|
||||
);
|
||||
if(isset($ar["ENTITY_TYPE"]))
|
||||
if (isset($ar["ENTITY_TYPE"]))
|
||||
{
|
||||
$arResult[$ar["ID"]]["ENTITY_TYPE"] = $ar["ENTITY_TYPE"];
|
||||
if(isset($ar["ENTITY_ID"]))
|
||||
}
|
||||
if (isset($ar["ENTITY_ID"]))
|
||||
{
|
||||
$arResult[$ar["ID"]]["ENTITY_ID"] = $ar["ENTITY_ID"];
|
||||
}
|
||||
}
|
||||
|
||||
return $arResult;
|
||||
}
|
||||
|
||||
protected function getCachedRights(): array
|
||||
{
|
||||
$cache = Cache::createInstance();
|
||||
$cacheTtl = 86400;
|
||||
$cachePath = $this->getTagCachePath();
|
||||
$cacheId = $this->getTagCacheTitle();
|
||||
|
||||
if ($cache->initCache($cacheTtl, $cacheId, $cachePath))
|
||||
{
|
||||
[$arResult] = $cache->getVars();
|
||||
}
|
||||
else
|
||||
{
|
||||
$cache->startDataCache();
|
||||
$taggedCache = Application::getInstance()->getTaggedCache();
|
||||
$taggedCache->startTagCache($cachePath);
|
||||
|
||||
$arResult = $this->GetRights();
|
||||
|
||||
$this->registerTagCache();
|
||||
$taggedCache->endTagCache();
|
||||
|
||||
$cache->endDataCache([$arResult]);
|
||||
}
|
||||
|
||||
return $arResult;
|
||||
@@ -363,6 +401,8 @@ class CIBlockRights
|
||||
{
|
||||
$stor = $this->_storage_object();
|
||||
$stor->CleanUp(/*$bFull=*/true);
|
||||
|
||||
$this->clearTagCache();
|
||||
}
|
||||
|
||||
function Recalculate()
|
||||
@@ -405,9 +445,9 @@ class CIBlockRights
|
||||
$arRights = $ob->GetRights();
|
||||
foreach($arRights as $RIGHT_ID => $arRight)
|
||||
{
|
||||
if(
|
||||
$arRight["DO_INHERIT"] === "Y"
|
||||
&& !array_key_exists($arRight["GROUP_CODE"], $arOwnGroupCodes)
|
||||
if (
|
||||
$arRight['DO_INHERIT'] === 'Y'
|
||||
&& !isset($arOwnGroupCodes[$arRight['GROUP_CODE']])
|
||||
)
|
||||
{
|
||||
$obStorage->_set_section($id);
|
||||
@@ -545,6 +585,7 @@ class CIBlockRights
|
||||
$obStorage->CleanUp();
|
||||
|
||||
CIBlock::clearIblockTagCache($this->IBLOCK_ID);
|
||||
$this->clearTagCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -802,6 +843,48 @@ class CIBlockRights
|
||||
}
|
||||
unset($rightsMode, $iblockId, $iblock, $queryObject);
|
||||
}
|
||||
|
||||
protected function getTagCacheTitle(): string
|
||||
{
|
||||
return 'iblock_rights_' . $this->GetIBlockID() . '_' . $this->_entity_type() . '_' . $this->GetID();
|
||||
}
|
||||
|
||||
protected function getTagCachePath(): string
|
||||
{
|
||||
return static::$tagCacheStartWith . $this->getTagCacheTitle();
|
||||
}
|
||||
|
||||
protected function registerTagCache(): void
|
||||
{
|
||||
global $CACHE_MANAGER;
|
||||
|
||||
$tagTitle = $this->getTagCacheTitle();
|
||||
if (defined("BX_COMP_MANAGED_CACHE") && !empty($tagTitle))
|
||||
{
|
||||
$CACHE_MANAGER->RegisterTag($tagTitle);
|
||||
}
|
||||
}
|
||||
|
||||
protected function clearTagCache(): void
|
||||
{
|
||||
global $CACHE_MANAGER;
|
||||
|
||||
$tagTitle = $this->getTagCacheTitle();
|
||||
if (defined("BX_COMP_MANAGED_CACHE") && !empty($tagTitle))
|
||||
{
|
||||
$CACHE_MANAGER->ClearByTag($tagTitle);
|
||||
}
|
||||
}
|
||||
|
||||
static public function clearAllTagCache(): void
|
||||
{
|
||||
global $CACHE_MANAGER;
|
||||
|
||||
if (defined("BX_COMP_MANAGED_CACHE"))
|
||||
{
|
||||
$CACHE_MANAGER->CleanDir(static::$tagCacheStartWith);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CIBlockSectionRights extends CIBlockRights
|
||||
@@ -879,12 +962,14 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
function GetRights($arOptions = array())
|
||||
{
|
||||
global $DB;
|
||||
$arResult = array();
|
||||
$arResult = [];
|
||||
|
||||
if($this->id <= 0)
|
||||
if ($this->id <= 0)
|
||||
{
|
||||
return parent::GetRights($arOptions);
|
||||
}
|
||||
|
||||
if(
|
||||
if (
|
||||
!isset($arOptions["operations"])
|
||||
|| !is_array($arOptions["operations"])
|
||||
|| empty($arOptions["operations"])
|
||||
@@ -910,7 +995,7 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
BR.ID
|
||||
");
|
||||
}
|
||||
elseif(
|
||||
elseif (
|
||||
isset($arOptions["operations_mode"])
|
||||
&& $arOptions["operations_mode"] == CIBlockRights::ALL_OPERATIONS
|
||||
&& count($arOptions["operations"]) > 1
|
||||
@@ -957,7 +1042,7 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
");
|
||||
}
|
||||
|
||||
if(isset($arOptions["parent"]))
|
||||
if (isset($arOptions["parent"]))
|
||||
{
|
||||
$obParentRights = new CIBlockSectionRights($this->IBLOCK_ID, $arOptions["parent"]);
|
||||
$arParentRights = $obParentRights->GetRights();
|
||||
@@ -972,9 +1057,13 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
"XML_ID" => $arRight["XML_ID"],
|
||||
);
|
||||
if(isset($arRight["ENTITY_TYPE"]))
|
||||
{
|
||||
$arResult[$RIGHT_ID]["ENTITY_TYPE"] = $arRight["ENTITY_TYPE"];
|
||||
}
|
||||
if(isset($arRight["ENTITY_ID"]))
|
||||
{
|
||||
$arResult[$RIGHT_ID]["ENTITY_ID"] = $arRight["ENTITY_ID"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -989,10 +1078,14 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
"TASK_ID" => $ar["TASK_ID"],
|
||||
"XML_ID" => $ar["XML_ID"],
|
||||
);
|
||||
if(isset($ar["ENTITY_TYPE"]))
|
||||
if (isset($ar["ENTITY_TYPE"]))
|
||||
{
|
||||
$arResult[$ar["ID"]]["ENTITY_TYPE"] = $ar["ENTITY_TYPE"];
|
||||
if(isset($ar["ENTITY_ID"]))
|
||||
}
|
||||
if (isset($ar["ENTITY_ID"]))
|
||||
{
|
||||
$arResult[$ar["ID"]]["ENTITY_ID"] = $ar["ENTITY_ID"];
|
||||
}
|
||||
}
|
||||
|
||||
return $arResult;
|
||||
@@ -1003,6 +1096,8 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
$stor = $this->_storage_object();
|
||||
$stor->DeleteRights();
|
||||
$stor->CleanUp(/*$bFull=*/false);
|
||||
|
||||
$this->clearTagCache();
|
||||
}
|
||||
|
||||
public static function UserHasRightTo($IBLOCK_ID, $ID, $permission, $flags = 0)
|
||||
@@ -1074,6 +1169,16 @@ class CIBlockSectionRights extends CIBlockRights
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getTagCacheTitle(): string
|
||||
{
|
||||
if ($this->GetID() === 0)
|
||||
{
|
||||
return $this->_get_parent_object(0)->getTagCacheTitle();
|
||||
}
|
||||
|
||||
return 'iblock_rights_' . $this->GetIBlockID() . '_' . $this->_entity_type() . '_' . $this->GetID();
|
||||
}
|
||||
}
|
||||
|
||||
class CIBlockElementRights extends CIBlockRights
|
||||
@@ -1107,7 +1212,7 @@ class CIBlockElementRights extends CIBlockRights
|
||||
|
||||
function _storage_object()
|
||||
{
|
||||
return new CIBlockRightsStorage($this->IBLOCK_ID, 0, $this->id);
|
||||
return new CIBlockElementRightsStorage($this->IBLOCK_ID, 0, $this->id);
|
||||
}
|
||||
|
||||
function GetList($arFilter)
|
||||
@@ -1279,6 +1384,8 @@ class CIBlockElementRights extends CIBlockRights
|
||||
$stor = $this->_storage_object();
|
||||
$stor->DeleteRights();
|
||||
$stor->CleanUp(/*$bFull=*/false);
|
||||
|
||||
$this->clearTagCache();
|
||||
}
|
||||
|
||||
public static function UserHasRightTo($IBLOCK_ID, $ID, $permission, $flags = 0)
|
||||
@@ -1362,6 +1469,75 @@ class CIBlockElementRights extends CIBlockRights
|
||||
else
|
||||
return array();
|
||||
}
|
||||
|
||||
public function addRightsByRootSection(array $elementRightsTaskList = []): void
|
||||
{
|
||||
$this->addRightsBySection([0], $elementRightsTaskList);
|
||||
}
|
||||
|
||||
public function addRightsBySection(array $newParents, array $elementRightsTaskList = []): void
|
||||
{
|
||||
$rightToAddList = [];
|
||||
|
||||
foreach ($newParents as $id)
|
||||
{
|
||||
$id = (int)$id;
|
||||
|
||||
if ($id < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$parentObject = $this->_get_parent_object($id);
|
||||
|
||||
if (is_object($parentObject))
|
||||
{
|
||||
$parentRights = $parentObject->getCachedRights();
|
||||
foreach ($parentRights as $rightId => $arRight)
|
||||
{
|
||||
$rightToAddList[$id][$arRight['GROUP_CODE']] = [
|
||||
'id' => $rightId,
|
||||
'isInherited' => true,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($elementRightsTaskList as $rightId => $arRightSet)
|
||||
{
|
||||
$groupCode = $arRightSet["GROUP_CODE"];
|
||||
if (strncmp((string)$rightId, 'n', 1) === 0)
|
||||
{
|
||||
$newRightId = $this->_add(
|
||||
$groupCode,
|
||||
true,
|
||||
$arRightSet["TASK_ID"],
|
||||
$arRightSet["XML_ID"] ?? false
|
||||
);
|
||||
|
||||
if (!empty($rightToAddList))
|
||||
{
|
||||
foreach (array_keys($rightToAddList) as $key)
|
||||
{
|
||||
unset($rightToAddList[$key][$groupCode]);
|
||||
}
|
||||
}
|
||||
|
||||
$rightToAddList[0][$groupCode] = [
|
||||
'id' => $newRightId,
|
||||
'isInherited' => false,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($rightToAddList))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$elementStorage = $this->_storage_object();
|
||||
$elementStorage->addSelfSetInRoot($rightToAddList);
|
||||
}
|
||||
}
|
||||
|
||||
class CIBlockRightsStorage
|
||||
@@ -1999,16 +2175,34 @@ class CIBlockRightsStorage
|
||||
{
|
||||
global $DB;
|
||||
$TASK_ID = (int)$TASK_ID;
|
||||
$isNeedToCleanCache = false;
|
||||
|
||||
if(!in_array("element_read", $arOld) && in_array("element_read", $arNew))
|
||||
{
|
||||
$DB->Query("UPDATE b_iblock_right SET OP_EREAD = 'Y' WHERE TASK_ID = ".$TASK_ID);
|
||||
$isNeedToCleanCache = true;
|
||||
}
|
||||
elseif(in_array("element_read", $arOld) && !in_array("element_read", $arNew))
|
||||
{
|
||||
$DB->Query("UPDATE b_iblock_right SET OP_EREAD = 'N' WHERE TASK_ID = ".$TASK_ID);
|
||||
$isNeedToCleanCache = true;
|
||||
}
|
||||
|
||||
if(!in_array("section_read", $arOld) && in_array("section_read", $arNew))
|
||||
{
|
||||
$DB->Query("UPDATE b_iblock_right SET OP_SREAD = 'Y' WHERE TASK_ID = ".$TASK_ID);
|
||||
$isNeedToCleanCache = true;
|
||||
}
|
||||
elseif(in_array("section_read", $arOld) && !in_array("section_read", $arNew))
|
||||
{
|
||||
$DB->Query("UPDATE b_iblock_right SET OP_SREAD = 'N' WHERE TASK_ID = ".$TASK_ID);
|
||||
$isNeedToCleanCache = true;
|
||||
}
|
||||
|
||||
if ($isNeedToCleanCache)
|
||||
{
|
||||
CIBlockRights::clearAllTagCache();
|
||||
}
|
||||
}
|
||||
|
||||
public static function OnGroupDelete($GROUP_ID)
|
||||
@@ -2064,5 +2258,60 @@ class CIBlockRightsStorage
|
||||
delete from b_iblock_right where GROUP_CODE = '" . $ownerId . "'
|
||||
");
|
||||
unset($conn);
|
||||
|
||||
CIBlockRights::clearAllTagCache();
|
||||
}
|
||||
}
|
||||
|
||||
class CIBlockElementRightsStorage extends CIBlockRightsStorage
|
||||
{
|
||||
function AddSelfSet($RIGHT_ID, $bInherited = false): void
|
||||
{
|
||||
if ($this->SECTION_ID === 0)
|
||||
{
|
||||
$this->addSelfSetInRoot([
|
||||
0 => [
|
||||
[
|
||||
'id' => $RIGHT_ID,
|
||||
'isInherited' => $bInherited,
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent::AddSelfSet($RIGHT_ID, $bInherited);
|
||||
}
|
||||
}
|
||||
|
||||
public function addSelfSetInRoot(array $rightList): void
|
||||
{
|
||||
if (empty($rightList))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$conn = Main\Application::getConnection();
|
||||
$helper = $conn->getSqlHelper();
|
||||
|
||||
$tableName = $helper->quote('b_iblock_element_right');
|
||||
$insertFields = "IBLOCK_ID, SECTION_ID, ELEMENT_ID, RIGHT_ID, IS_INHERITED";
|
||||
$insertData = [];
|
||||
|
||||
$iblockId = (int)$this->IBLOCK_ID;
|
||||
$elementId = (int)$this->ELEMENT_ID;
|
||||
|
||||
foreach ($rightList as $sectionId => $params)
|
||||
{
|
||||
foreach ($params as $param)
|
||||
{
|
||||
$rightId = (int)$param['id'];
|
||||
$sectionId = (int)$sectionId;
|
||||
$isInherited = $param['isInherited'] ? "Y" : "N";
|
||||
$insertData[] = "({$iblockId}, {$sectionId}, {$elementId}, {$rightId}, '{$isInherited}')";
|
||||
}
|
||||
}
|
||||
|
||||
$conn->queryExecute("INSERT INTO {$tableName} ({$insertFields}) VALUES " . implode(',', $insertData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<?php
|
||||
|
||||
use Bitrix\Iblock\PropertyEnumerationTable;
|
||||
use Bitrix\Iblock\PropertyTable;
|
||||
use Bitrix\Main\Config\Option;
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
if (!CModule::IncludeModule("bizproc"))
|
||||
return;
|
||||
|
||||
class CIBlockDocument
|
||||
class CIBlockDocument implements \IBPWorkflowDocument
|
||||
{
|
||||
public static function getEntityName()
|
||||
{
|
||||
@@ -1104,7 +1108,17 @@ class CIBlockDocument
|
||||
$arResult = null;
|
||||
if (!empty($select))
|
||||
{
|
||||
$select = array_filter($select, fn($field) => !str_starts_with($field, 'PROPERTY_'));
|
||||
$select = array_merge(['ID', 'IBLOCK_ID'], $select);
|
||||
|
||||
if (in_array('CREATED_BY', $select) && !in_array('CREATED_USER_NAME', $select))
|
||||
{
|
||||
$select[] = 'CREATED_USER_NAME';
|
||||
}
|
||||
if (in_array('MODIFIED_BY', $select) && !in_array('USER_NAME', $select))
|
||||
{
|
||||
$select[] = 'USER_NAME';
|
||||
}
|
||||
}
|
||||
|
||||
$userNameFields = [
|
||||
@@ -1288,11 +1302,30 @@ class CIBlockDocument
|
||||
return "iblock_$iblockId";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $documentType - Really document type is string. Mixed only for compatibility.
|
||||
* @return int
|
||||
* @throws CBPArgumentOutOfRangeException
|
||||
*/
|
||||
public static function getIblockIdByDocumentType(mixed $documentType): int
|
||||
{
|
||||
$documentType = (string)$documentType;
|
||||
if ($documentType === '' || !str_starts_with($documentType, 'iblock_'))
|
||||
{
|
||||
throw new CBPArgumentOutOfRangeException('documentType', $documentType);
|
||||
}
|
||||
$iblockId = (int)(substr($documentType, 7)); // length 'iblock_' - 7
|
||||
if ($iblockId <= 0)
|
||||
{
|
||||
throw new CBPArgumentOutOfRangeException('documentType', $documentType);
|
||||
}
|
||||
|
||||
return $iblockId;
|
||||
}
|
||||
|
||||
public static function GetDocumentFields($documentType)
|
||||
{
|
||||
$iblockId = intval(mb_substr($documentType, mb_strlen("iblock_")));
|
||||
if ($iblockId <= 0)
|
||||
throw new CBPArgumentOutOfRangeException("documentType", $documentType);
|
||||
$iblockId = static::getIblockIdByDocumentType($documentType);
|
||||
|
||||
$arDocumentFieldTypes = self::GetDocumentFieldTypes($documentType);
|
||||
|
||||
@@ -1465,16 +1498,38 @@ class CIBlockDocument
|
||||
foreach ($arKeys as $key)
|
||||
$arResult[$key]["Multiple"] = false;
|
||||
|
||||
$dbProperties = CIBlockProperty::GetList(
|
||||
array("sort" => "asc", "name" => "asc"),
|
||||
array("IBLOCK_ID" => $iblockId, 'ACTIVE' => 'Y')
|
||||
);
|
||||
while ($arProperty = $dbProperties->Fetch())
|
||||
$employeeNotCompatible = Option::get('bizproc', 'employee_compatible_mode', 'N') !== 'Y';
|
||||
$enumSelect = [
|
||||
'VALUE',
|
||||
'INDEX' => (self::GetVersion() > 1 ? 'XML_ID' : 'ID'),
|
||||
];
|
||||
|
||||
$iterator = PropertyTable::getList([
|
||||
'select' => ['*'],
|
||||
'filter' => [
|
||||
'=IBLOCK_ID' => $iblockId,
|
||||
'=ACTIVE' => 'Y',
|
||||
],
|
||||
'order' => [
|
||||
'SORT' => 'ASC',
|
||||
'NAME' => 'ASC',
|
||||
],
|
||||
'cache' => [
|
||||
'ttl' => 86400,
|
||||
],
|
||||
]);
|
||||
PropertyTable::fillOldCoreFetchModifiers($iterator);
|
||||
|
||||
while ($arProperty = $iterator->fetch())
|
||||
{
|
||||
if (trim($arProperty["CODE"]) <> '')
|
||||
$key = "PROPERTY_".$arProperty["CODE"];
|
||||
else
|
||||
$key = "PROPERTY_".$arProperty["ID"];
|
||||
$arProperty['CODE'] = (string)$arProperty['CODE'];
|
||||
$arProperty['USER_TYPE'] = (string)$arProperty['USER_TYPE'];
|
||||
|
||||
$key =
|
||||
$arProperty['CODE']
|
||||
? 'PROPERTY_'.$arProperty['CODE']
|
||||
: 'PROPERTY_'.$arProperty['ID']
|
||||
;
|
||||
|
||||
$arResult[$key] = array(
|
||||
"Name" => $arProperty["NAME"],
|
||||
@@ -1482,15 +1537,22 @@ class CIBlockDocument
|
||||
"Editable" => true,
|
||||
"Required" => ($arProperty["IS_REQUIRED"] == "Y"),
|
||||
"Multiple" => ($arProperty["MULTIPLE"] == "Y"),
|
||||
'IblockPropertyId' => (int)$arProperty['ID'],
|
||||
);
|
||||
|
||||
if(trim($arProperty["CODE"]) <> '')
|
||||
$arResult[$key]["Alias"] = "PROPERTY_".$arProperty["ID"];
|
||||
|
||||
if ($arProperty["USER_TYPE"] <> '')
|
||||
if ($arProperty['CODE'])
|
||||
{
|
||||
if ($arProperty["USER_TYPE"] == "UserID"
|
||||
|| $arProperty["USER_TYPE"] == "employee" && (COption::GetOptionString("bizproc", "employee_compatible_mode", "N") != "Y"))
|
||||
$arResult[$key]['Alias'] = 'PROPERTY_' . $arProperty['ID'];
|
||||
}
|
||||
|
||||
if ($arProperty['USER_TYPE'] !== '')
|
||||
{
|
||||
if (
|
||||
$arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_USER
|
||||
|| (
|
||||
$arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_EMPLOYEE && $employeeNotCompatible
|
||||
)
|
||||
)
|
||||
{
|
||||
$arResult[$key]["Type"] = "user";
|
||||
$arResult[$key."_PRINTABLE"] = array(
|
||||
@@ -1498,24 +1560,24 @@ class CIBlockDocument
|
||||
"Filterable" => false,
|
||||
"Editable" => false,
|
||||
"Required" => false,
|
||||
"Multiple" => ($arProperty["MULTIPLE"] == "Y"),
|
||||
"Multiple" => ($arProperty["MULTIPLE"] === "Y"),
|
||||
"Type" => "string",
|
||||
);
|
||||
}
|
||||
elseif ($arProperty["USER_TYPE"] == "DateTime")
|
||||
elseif ($arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_DATETIME)
|
||||
{
|
||||
$arResult[$key]["Type"] = "datetime";
|
||||
}
|
||||
elseif ($arProperty["USER_TYPE"] == "Date")
|
||||
elseif ($arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_DATE)
|
||||
{
|
||||
$arResult[$key]["Type"] = "date";
|
||||
}
|
||||
elseif ($arProperty["USER_TYPE"] == "EList")
|
||||
elseif ($arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_ELEMENT_LIST)
|
||||
{
|
||||
$arResult[$key]["Type"] = "E:EList";
|
||||
$arResult[$key]["Options"] = $arProperty["LINK_IBLOCK_ID"];
|
||||
}
|
||||
elseif($arProperty["USER_TYPE"] == "DiskFile")
|
||||
elseif ($arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_DISK)
|
||||
{
|
||||
$arResult[$key]["Type"] = "S:DiskFile";
|
||||
$arResult[$key."_PRINTABLE"] = array(
|
||||
@@ -1527,7 +1589,7 @@ class CIBlockDocument
|
||||
"Type" => "int",
|
||||
);
|
||||
}
|
||||
elseif ($arProperty["USER_TYPE"] == "HTML")
|
||||
elseif ($arProperty['USER_TYPE'] === PropertyTable::USER_TYPE_HTML)
|
||||
{
|
||||
$arResult[$key]["Type"] = "S:HTML";
|
||||
}
|
||||
@@ -1536,20 +1598,35 @@ class CIBlockDocument
|
||||
$arResult[$key]["Type"] = "string";
|
||||
}
|
||||
}
|
||||
elseif ($arProperty["PROPERTY_TYPE"] == "L")
|
||||
elseif ($arProperty['PROPERTY_TYPE'] === PropertyTable::TYPE_LIST)
|
||||
{
|
||||
$arResult[$key]["Type"] = "select";
|
||||
|
||||
$arResult[$key]["Options"] = array();
|
||||
$dbPropertyEnums = CIBlockProperty::GetPropertyEnum($arProperty["ID"]);
|
||||
while ($arPropertyEnum = $dbPropertyEnums->GetNext())
|
||||
$arResult[$key]["Options"][(self::GetVersion() > 1) ? $arPropertyEnum["XML_ID"] : $arPropertyEnum["ID"]] = $arPropertyEnum["VALUE"];
|
||||
$arResult[$key]["Options"] = [];
|
||||
|
||||
$enumIterator = PropertyEnumerationTable::getList([
|
||||
'select' => $enumSelect,
|
||||
'filter' => [
|
||||
'=PROPERTY_ID' => (int)$arProperty['ID'],
|
||||
],
|
||||
'cache' => [
|
||||
'ttl' => 86400,
|
||||
],
|
||||
]);
|
||||
while ($enumRow = $enumIterator->fetch())
|
||||
{
|
||||
$arResult[$key]["Options"][htmlspecialcharsEx($enumRow['INDEX'])] = htmlspecialcharsEx($enumRow['VALUE']);
|
||||
}
|
||||
unset(
|
||||
$enumRow,
|
||||
$enumIterator,
|
||||
);
|
||||
}
|
||||
elseif ($arProperty["PROPERTY_TYPE"] == "N")
|
||||
elseif ($arProperty['PROPERTY_TYPE'] === PropertyTable::TYPE_NUMBER)
|
||||
{
|
||||
$arResult[$key]["Type"] = "int";
|
||||
}
|
||||
elseif ($arProperty["PROPERTY_TYPE"] == "F")
|
||||
elseif ($arProperty['PROPERTY_TYPE'] === PropertyTable::TYPE_FILE)
|
||||
{
|
||||
$arResult[$key]["Type"] = "file";
|
||||
$arResult[$key."_printable"] = array(
|
||||
@@ -1561,7 +1638,7 @@ class CIBlockDocument
|
||||
"Type" => "string",
|
||||
);
|
||||
}
|
||||
elseif ($arProperty["PROPERTY_TYPE"] == "S")
|
||||
elseif ($arProperty['PROPERTY_TYPE'] === PropertyTable::TYPE_STRING)
|
||||
{
|
||||
$arResult[$key]["Type"] = "string";
|
||||
}
|
||||
@@ -1570,12 +1647,16 @@ class CIBlockDocument
|
||||
$arResult[$key]["Type"] = "string";
|
||||
}
|
||||
}
|
||||
unset(
|
||||
$arProperty,
|
||||
$iterator,
|
||||
);
|
||||
|
||||
$arKeys = array_keys($arResult);
|
||||
foreach ($arKeys as $k)
|
||||
{
|
||||
$arResult[$k]["BaseType"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["BaseType"];
|
||||
$arResult[$k]["Complex"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["Complex"];
|
||||
$arResult[$k]["Complex"] = $arDocumentFieldTypes[$arResult[$k]["Type"]]["Complex"] ?? false;
|
||||
}
|
||||
|
||||
return $arResult;
|
||||
@@ -1587,30 +1668,76 @@ class CIBlockDocument
|
||||
if ($iblockId <= 0)
|
||||
throw new CBPArgumentOutOfRangeException("documentType", $documentType);
|
||||
|
||||
$arResult = array(
|
||||
"string" => array("Name" => GetMessage("BPCGHLP_PROP_STRING"), "BaseType" => "string"),
|
||||
"text" => array("Name" => GetMessage("BPCGHLP_PROP_TEXT"), "BaseType" => "text"),
|
||||
"int" => array("Name" => GetMessage("BPCGHLP_PROP_INT"), "BaseType" => "int"),
|
||||
"double" => array("Name" => GetMessage("BPCGHLP_PROP_DOUBLE"), "BaseType" => "double"),
|
||||
"select" => array("Name" => GetMessage("BPCGHLP_PROP_SELECT"), "BaseType" => "select", "Complex" => true),
|
||||
"bool" => array("Name" => GetMessage("BPCGHLP_PROP_BOOL"), "BaseType" => "bool"),
|
||||
"date" => array("Name" => GetMessage("BPCGHLP_PROP_DATA"), "BaseType" => "date"),
|
||||
"datetime" => array("Name" => GetMessage("BPCGHLP_PROP_DATETIME"), "BaseType" => "datetime"),
|
||||
"user" => array("Name" => GetMessage("BPCGHLP_PROP_USER"), "BaseType" => "user"),
|
||||
"file" => array("Name" => GetMessage("BPCGHLP_PROP_FILE"), "BaseType" => "file"),
|
||||
);
|
||||
$arResult = [
|
||||
'string' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_STRING'),
|
||||
'BaseType' => 'string',
|
||||
'Complex' => false,
|
||||
],
|
||||
'text' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_TEXT'),
|
||||
'BaseType' => 'text',
|
||||
'Complex' => false,
|
||||
],
|
||||
'int' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_INT'),
|
||||
'BaseType' => 'int',
|
||||
'Complex' => false,
|
||||
],
|
||||
'double' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_DOUBLE'),
|
||||
'BaseType' => 'double',
|
||||
'Complex' => false,
|
||||
],
|
||||
'select' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_SELECT'),
|
||||
'BaseType' => 'select',
|
||||
'Complex' => true,
|
||||
],
|
||||
'bool' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_BOOL'),
|
||||
'BaseType' => 'bool',
|
||||
'Complex' => false,
|
||||
],
|
||||
'date' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_DATA'),
|
||||
'BaseType' => 'date',
|
||||
'Complex' => false,
|
||||
],
|
||||
'datetime' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_DATETIME'),
|
||||
'BaseType' => 'datetime',
|
||||
'Complex' => false,
|
||||
],
|
||||
'user' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_USER'),
|
||||
'BaseType' => 'user',
|
||||
'Complex' => false,
|
||||
],
|
||||
'file' => [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_FILE'),
|
||||
'BaseType' => 'file',
|
||||
'Complex' => false,
|
||||
],
|
||||
];
|
||||
|
||||
$ignoredTypes = array('map_yandex', 'directory', 'SectionAuto', 'SKU', 'EAutocomplete');
|
||||
$ignoredTypes = [
|
||||
PropertyTable::USER_TYPE_YANDEX_MAP => true,
|
||||
PropertyTable::USER_TYPE_DIRECTORY => true,
|
||||
PropertyTable::USER_TYPE_SECTION_AUTOCOMPLETE => true,
|
||||
PropertyTable::USER_TYPE_SKU => true,
|
||||
PropertyTable::USER_TYPE_ELEMENT_AUTOCOMPLETE => true,
|
||||
];
|
||||
|
||||
$arResult[\Bitrix\Bizproc\FieldType::INTERNALSELECT] = array(
|
||||
"Name" => GetMessage("BPCGHLP_PROP_SELECT_INTERNAL"),
|
||||
"BaseType" => "string",
|
||||
"Complex" => true,
|
||||
);
|
||||
$arResult[\Bitrix\Bizproc\FieldType::INTERNALSELECT] = [
|
||||
'Name' => GetMessage('BPCGHLP_PROP_SELECT_INTERNAL'),
|
||||
'BaseType' => 'string',
|
||||
'Complex' => true,
|
||||
];
|
||||
|
||||
foreach (CIBlockProperty::GetUserType() as $ar)
|
||||
foreach (CIBlockProperty::GetUserType() as $ar)
|
||||
{
|
||||
if(in_array($ar["USER_TYPE"], $ignoredTypes))
|
||||
if(isset($ignoredTypes[$ar['USER_TYPE']]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -1626,7 +1753,12 @@ class CIBlockDocument
|
||||
&& !array_key_exists("GetPublicEditHTML", $ar) || $t == "S:UserID" || $t == "S:DateTime" || $t == "S:Date")
|
||||
continue;
|
||||
|
||||
$arResult[$t] = array("Name" => $ar["DESCRIPTION"], "BaseType" => "string", 'typeClass' => '\Bitrix\Iblock\BizprocType\UserTypeProperty');
|
||||
$arResult[$t] = [
|
||||
'Name' => $ar['DESCRIPTION'],
|
||||
'BaseType' => 'string',
|
||||
'typeClass' => '\Bitrix\Iblock\BizprocType\UserTypeProperty',
|
||||
'Complex' => false,
|
||||
];
|
||||
if ($t == "S:employee")
|
||||
{
|
||||
$arResult[$t]['typeClass'] = '\Bitrix\Iblock\BizprocType\UserTypePropertyEmployee';
|
||||
@@ -2409,10 +2541,12 @@ class CIBlockDocument
|
||||
*/
|
||||
public static function CreateDocument($parentDocumentId, $arFields)
|
||||
{
|
||||
if (!array_key_exists("IBLOCK_ID", $arFields) || intval($arFields["IBLOCK_ID"]) <= 0)
|
||||
if ((int)($arFields['IBLOCK_ID'] ?? 0) <= 0)
|
||||
{
|
||||
throw new Exception("IBlock ID is not found");
|
||||
}
|
||||
|
||||
$arFieldsPropertyValues = array();
|
||||
$arFieldsPropertyValues = [];
|
||||
$complexDocumentId = ['iblock', get_called_class(), $parentDocumentId];
|
||||
|
||||
$arDocumentFields = static::GetDocumentFields("iblock_".$arFields["IBLOCK_ID"]);
|
||||
@@ -2420,12 +2554,20 @@ class CIBlockDocument
|
||||
$arKeys = array_keys($arFields);
|
||||
foreach ($arKeys as $key)
|
||||
{
|
||||
if (!array_key_exists($key, $arDocumentFields))
|
||||
if (!isset($arDocumentFields[$key]))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$arFields[$key] = (is_array($arFields[$key]) &&
|
||||
!CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
|
||||
$realKey = ((mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")? mb_substr($key, mb_strlen("PROPERTY_")) : $key);
|
||||
|
||||
$isPropertyKey = str_starts_with($key, 'PROPERTY_');
|
||||
$realKey =
|
||||
$isPropertyKey
|
||||
? substr($key, 9)
|
||||
: $key
|
||||
;
|
||||
|
||||
if ($arDocumentFields[$key]["Type"] == "user")
|
||||
{
|
||||
@@ -2512,7 +2654,7 @@ class CIBlockDocument
|
||||
|
||||
if (!$arDocumentFields[$key]["Multiple"] && is_array($arFields[$key]))
|
||||
{
|
||||
if (count($arFields[$key]) > 0)
|
||||
if (!empty($arFields[$key]))
|
||||
{
|
||||
$a = array_values($arFields[$key]);
|
||||
$arFields[$key] = $a[0];
|
||||
@@ -2523,27 +2665,30 @@ class CIBlockDocument
|
||||
}
|
||||
}
|
||||
|
||||
if (mb_substr($key, 0, mb_strlen("PROPERTY_")) == "PROPERTY_")
|
||||
if ($isPropertyKey)
|
||||
{
|
||||
$realKey = mb_substr($key, mb_strlen("PROPERTY_"));
|
||||
$arFieldsPropertyValues[$realKey] = (is_array($arFields[$key]) &&
|
||||
!CBPHelper::IsAssociativeArray($arFields[$key])) ? $arFields[$key] : array($arFields[$key]);
|
||||
unset($arFields[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
if (count($arFieldsPropertyValues) > 0)
|
||||
if (!empty($arFieldsPropertyValues))
|
||||
{
|
||||
$arFields["PROPERTY_VALUES"] = $arFieldsPropertyValues;
|
||||
}
|
||||
|
||||
if (isset($arFields['SORT']))
|
||||
{
|
||||
$arFields['SORT'] = (int) $arFields['SORT'];
|
||||
$arFields['SORT'] = (int)$arFields['SORT'];
|
||||
}
|
||||
|
||||
$iblockElement = new CIBlockElement();
|
||||
$id = $iblockElement->Add($arFields, false, true, true);
|
||||
if (!$id || $id <= 0)
|
||||
throw new Exception($iblockElement->LAST_ERROR);
|
||||
{
|
||||
throw new Exception($iblockElement->getLastError());
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
use Bitrix\Iblock\FullIndex\FullText;
|
||||
use Bitrix\Main;
|
||||
use Bitrix\Main\Loader;
|
||||
use Bitrix\Main\Localization\Loc;
|
||||
use Bitrix\Main\ModuleManager;
|
||||
use Bitrix\Iblock;
|
||||
use Bitrix\Iblock\ElementTable;
|
||||
@@ -10,8 +11,6 @@ use Bitrix\Iblock\IblockTable;
|
||||
use Bitrix\Catalog;
|
||||
use Bitrix\Main\ORM\Query\Filter\Helper;
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
global $IBLOCK_ACTIVE_DATE_FORMAT;
|
||||
$IBLOCK_ACTIVE_DATE_FORMAT = Array();
|
||||
global $BX_IBLOCK_PROP_CACHE;
|
||||
@@ -239,7 +238,7 @@ class CAllIBlockElement
|
||||
///////////////////////////////////////////////////////////////////
|
||||
public static function WF_CleanUpHistory()
|
||||
{
|
||||
if (CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
global $DB;
|
||||
|
||||
@@ -282,7 +281,7 @@ class CAllIBlockElement
|
||||
///////////////////////////////////////////////////////////////////
|
||||
public function WF_SetMove($NEW_ID, $OLD_ID = 0)
|
||||
{
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
global $DB, $USER;
|
||||
|
||||
@@ -505,7 +504,7 @@ class CAllIBlockElement
|
||||
///////////////////////////////////////////////////////////////////
|
||||
public static function WF_CleanUpHistoryCopies($ELEMENT_ID=false, $HISTORY_COPIES=false)
|
||||
{
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
global $DB;
|
||||
if($HISTORY_COPIES===false)
|
||||
@@ -549,7 +548,7 @@ class CAllIBlockElement
|
||||
|
||||
public static function WF_GetSqlLimit($PS="BE.", $SHOW_NEW="N")
|
||||
{
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
$limit = " and ((".$PS."WF_STATUS_ID=1 and ".$PS."WF_PARENT_ELEMENT_ID is null)";
|
||||
if($SHOW_NEW=="Y") $limit .= " or ".$PS."WF_NEW='Y' ";
|
||||
@@ -629,7 +628,7 @@ class CAllIBlockElement
|
||||
$zr = array(
|
||||
'TITLE' => null
|
||||
);
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
$STATUS_ID = (int)$STATUS_ID;
|
||||
if($STATUS_ID>0)
|
||||
@@ -647,7 +646,7 @@ class CAllIBlockElement
|
||||
global $DB;
|
||||
$STATUS_ID = 0;
|
||||
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
$ELEMENT_ID = (int)$ELEMENT_ID;
|
||||
|
||||
@@ -678,7 +677,7 @@ class CAllIBlockElement
|
||||
{
|
||||
global $DB, $USER;
|
||||
$result = false;
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
{
|
||||
if(CWorkflow::IsAdmin())
|
||||
return 2;
|
||||
@@ -3988,7 +3987,7 @@ class CAllIBlockElement
|
||||
elseif($arDef["IGNORE_ERRORS"] !== "Y")
|
||||
{
|
||||
unset($arFields["PREVIEW_PICTURE"]);
|
||||
$strWarning .= GetMessage("IBLOCK_FIELD_PREVIEW_PICTURE").": ".$arNewPicture."<br>";
|
||||
$strWarning .= Loc::getMessage("IBLOCK_FIELD_PREVIEW_PICTURE").": ".$arNewPicture."<br>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4074,7 +4073,7 @@ class CAllIBlockElement
|
||||
elseif($arDef["IGNORE_ERRORS"] !== "Y")
|
||||
{
|
||||
unset($arFields["DETAIL_PICTURE"]);
|
||||
$strWarning .= GetMessage("IBLOCK_FIELD_DETAIL_PICTURE").": ".$arNewPicture."<br>";
|
||||
$strWarning .= Loc::getMessage("IBLOCK_FIELD_DETAIL_PICTURE").": ".$arNewPicture."<br>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4359,22 +4358,44 @@ class CAllIBlockElement
|
||||
}
|
||||
unset($updateFields);
|
||||
|
||||
if(is_set($arFields, "IBLOCK_SECTION"))
|
||||
CIBlockElement::SetElementSection($ID, $arFields["IBLOCK_SECTION"], true, $arIBlock["RIGHTS_MODE"] === "E"? $arIBlock["ID"]: 0, $IBLOCK_SECTION_ID);
|
||||
if (isset($arFields["IBLOCK_SECTION"]))
|
||||
{
|
||||
CIBlockElement::setNewElementSection(
|
||||
(int)$ID,
|
||||
$arFields["IBLOCK_SECTION"],
|
||||
(int)$IBLOCK_SECTION_ID
|
||||
);
|
||||
}
|
||||
|
||||
if ($arIBlock["RIGHTS_MODE"] === Iblock\IblockTable::RIGHTS_EXTENDED)
|
||||
{
|
||||
$obElementRights = new CIBlockElementRights($arIBlock["ID"], $ID);
|
||||
if(!is_set($arFields, "IBLOCK_SECTION") || empty($arFields["IBLOCK_SECTION"]))
|
||||
$obElementRights->ChangeParents(array(), array(0));
|
||||
if(array_key_exists("RIGHTS", $arFields) && is_array($arFields["RIGHTS"]))
|
||||
$obElementRights->SetRights($arFields["RIGHTS"]);
|
||||
|
||||
$arFields['RIGHTS'] = isset($arFields['RIGHTS']) && is_array($arFields['RIGHTS']) ? $arFields['RIGHTS'] : [];
|
||||
|
||||
if (empty($arFields["IBLOCK_SECTION"]))
|
||||
{
|
||||
$obElementRights->addRightsByRootSection($arFields['RIGHTS']);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (is_array($arFields["IBLOCK_SECTION"]))
|
||||
{
|
||||
$newParents = $arFields["IBLOCK_SECTION"];
|
||||
}
|
||||
else
|
||||
{
|
||||
$newParents = [(int)$arFields["IBLOCK_SECTION"]];
|
||||
}
|
||||
|
||||
$obElementRights->addRightsBySection($newParents, $arFields['RIGHTS']);
|
||||
}
|
||||
}
|
||||
|
||||
if (array_key_exists("IPROPERTY_TEMPLATES", $arFields))
|
||||
if (isset($arFields['IPROPERTY_TEMPLATES']))
|
||||
{
|
||||
$ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arIBlock["ID"], $ID);
|
||||
$ipropTemplates->set($arFields["IPROPERTY_TEMPLATES"]);
|
||||
$ipropTemplates = new Iblock\InheritedProperty\ElementTemplates($arIBlock['ID'], $ID);
|
||||
$ipropTemplates->set($arFields['IPROPERTY_TEMPLATES']);
|
||||
}
|
||||
|
||||
if ($bUpdateSearch && $this->searchIncluded)
|
||||
@@ -4502,56 +4523,76 @@ class CAllIBlockElement
|
||||
global $DB;
|
||||
|
||||
$FILE_ID = (int)$FILE_ID;
|
||||
if($FILE_ID <= 0)
|
||||
return;
|
||||
if ($FILE_ID <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if($ELEMENT_ID !== false)
|
||||
if ($ELEMENT_ID !== false)
|
||||
{//ELEMENT_ID may be false when we are going to check for a valid file from CheckFields
|
||||
$ELEMENT_ID = (int)$ELEMENT_ID;
|
||||
if($ELEMENT_ID <= 0)
|
||||
return;
|
||||
if ($ELEMENT_ID <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
$IBLOCK_ID = (int)$IBLOCK_ID;
|
||||
if($IBLOCK_ID <= 0 || $PARENT_ID===-1)
|
||||
if ($IBLOCK_ID <= 0 || $PARENT_ID === -1)
|
||||
{
|
||||
if($ELEMENT_ID===false)
|
||||
return; //This is an error in API call
|
||||
if($ELEMENT_ID === false)
|
||||
{
|
||||
return null; //This is an error in API call
|
||||
}
|
||||
$rsElement = $DB->Query("SELECT IBLOCK_ID, WF_PARENT_ELEMENT_ID from b_iblock_element WHERE ID = ".$ELEMENT_ID);
|
||||
$arElement = $rsElement->Fetch();
|
||||
unset($rsElement);
|
||||
if(!$arElement)
|
||||
return;
|
||||
$IBLOCK_ID = $arElement["IBLOCK_ID"];
|
||||
{
|
||||
return null;
|
||||
}
|
||||
$IBLOCK_ID = (int)$arElement["IBLOCK_ID"];
|
||||
$PARENT_ID = $arElement["WF_PARENT_ELEMENT_ID"];
|
||||
}
|
||||
|
||||
if($TYPE === false)
|
||||
if ($TYPE === false)
|
||||
{
|
||||
$CNT = CIBlockElement::DeleteFile($FILE_ID, $ELEMENT_ID, "PREVIEW", $PARENT_ID, $IBLOCK_ID);
|
||||
$CNT += CIBlockElement::DeleteFile($FILE_ID, $ELEMENT_ID, "DETAIL", $PARENT_ID, $IBLOCK_ID);
|
||||
$CNT += CIBlockElement::DeleteFile($FILE_ID, $ELEMENT_ID, "PROPERTY", $PARENT_ID, $IBLOCK_ID);
|
||||
|
||||
return $CNT;
|
||||
}
|
||||
|
||||
$VERSION = CIBlockElement::GetIBVersion($IBLOCK_ID);
|
||||
|
||||
$arProps = array();
|
||||
if($TYPE === "PROPERTY" && $VERSION==2)
|
||||
$arProps = [];
|
||||
if ($TYPE === 'PROPERTY' && $VERSION === Iblock\IblockTable::PROPERTY_STORAGE_SEPARATE)
|
||||
{
|
||||
$strSQL = "
|
||||
SELECT P.ID
|
||||
FROM
|
||||
b_iblock_property P
|
||||
WHERE P.IBLOCK_ID = ".$IBLOCK_ID."
|
||||
AND P.PROPERTY_TYPE = 'F'
|
||||
AND P.MULTIPLE = 'N'
|
||||
";
|
||||
$rs = $DB->Query($strSQL);
|
||||
while($ar = $rs->Fetch())
|
||||
$arProps[] = " V.PROPERTY_".(int)$ar["ID"]." = ".$FILE_ID;
|
||||
$iterator = Iblock\PropertyTable::getList([
|
||||
'select' => [
|
||||
'ID',
|
||||
],
|
||||
'filter' => [
|
||||
'=IBLOCK_ID' => $IBLOCK_ID,
|
||||
'=PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE,
|
||||
'=MULTIPLE' => 'N',
|
||||
],
|
||||
'cache' => [
|
||||
'ttl' => 86400,
|
||||
],
|
||||
]);
|
||||
while ($ar = $iterator->fetch())
|
||||
{
|
||||
$arProps[] = " V.PROPERTY_" . (int)$ar["ID"] . " = " . $FILE_ID;
|
||||
}
|
||||
unset(
|
||||
$ar,
|
||||
$iterator,
|
||||
);
|
||||
}
|
||||
|
||||
if($ELEMENT_ID === false)
|
||||
if ($ELEMENT_ID === false)
|
||||
{
|
||||
//It is new historical record so we'' check original
|
||||
//and all over history already there
|
||||
@@ -4560,7 +4601,7 @@ class CAllIBlockElement
|
||||
"E.WF_PARENT_ELEMENT_ID=".(int)$PARENT_ID
|
||||
);
|
||||
}
|
||||
elseif((int)$PARENT_ID)
|
||||
elseif ((int)$PARENT_ID)
|
||||
{
|
||||
//It's an historical record so we will check original
|
||||
// and all history except deleted one
|
||||
@@ -4579,9 +4620,9 @@ class CAllIBlockElement
|
||||
}
|
||||
|
||||
$CNT = 0;
|
||||
foreach($arWhere as $strWhere)
|
||||
foreach ($arWhere as $strWhere)
|
||||
{
|
||||
if($TYPE === "PREVIEW")
|
||||
if ($TYPE === "PREVIEW")
|
||||
{
|
||||
$strSQL = "
|
||||
SELECT COUNT(1) CNT
|
||||
@@ -4591,7 +4632,7 @@ class CAllIBlockElement
|
||||
";
|
||||
|
||||
}
|
||||
elseif($TYPE === "DETAIL")
|
||||
elseif ($TYPE === "DETAIL")
|
||||
{
|
||||
$strSQL = "
|
||||
SELECT COUNT(1) CNT
|
||||
@@ -4600,9 +4641,9 @@ class CAllIBlockElement
|
||||
AND DETAIL_PICTURE = ".$FILE_ID."
|
||||
";
|
||||
}
|
||||
elseif($TYPE === "PROPERTY")
|
||||
elseif ($TYPE === "PROPERTY")
|
||||
{
|
||||
if($VERSION==2)
|
||||
if ($VERSION === Iblock\IblockTable::PROPERTY_STORAGE_SEPARATE)
|
||||
{
|
||||
$strSQL = "
|
||||
SELECT COUNT(1) CNT
|
||||
@@ -4640,13 +4681,16 @@ class CAllIBlockElement
|
||||
|
||||
$rs = $DB->Query($strSQL);
|
||||
$ar = $rs->Fetch();
|
||||
unset($rs);
|
||||
|
||||
$CNT += (int)$ar["CNT"];
|
||||
if($CNT > 0)
|
||||
if ($CNT > 0)
|
||||
{
|
||||
return $CNT;
|
||||
}
|
||||
|
||||
//Check VERSION 2 SINGLE PROPERTIES
|
||||
if(!empty($arProps))
|
||||
if (!empty($arProps))
|
||||
{
|
||||
//This SQL potentially wrong
|
||||
//in case when file may be saved in
|
||||
@@ -4666,16 +4710,23 @@ class CAllIBlockElement
|
||||
";
|
||||
$rs = $DB->Query($strSQL);
|
||||
$ar = $rs->Fetch();
|
||||
unset($rs);
|
||||
$CNT += (int)$ar["CNT"];
|
||||
if($CNT > 0)
|
||||
if ($CNT > 0)
|
||||
{
|
||||
return $CNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($bCheckOnly)
|
||||
if ($bCheckOnly)
|
||||
{
|
||||
return $CNT;
|
||||
}
|
||||
elseif($CNT === 0)
|
||||
{
|
||||
CFile::Delete($FILE_ID);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -4684,7 +4735,11 @@ class CAllIBlockElement
|
||||
public static function Delete($ID)
|
||||
{
|
||||
global $DB, $APPLICATION, $USER;
|
||||
$USER_ID = is_object($USER)? (int)$USER->GetID() : 0;
|
||||
$USER_ID = 0;
|
||||
if (isset($USER) && $USER instanceof CUser)
|
||||
{
|
||||
$USER_ID = (int)$USER->GetID();
|
||||
}
|
||||
$ID = (int)$ID;
|
||||
if ($ID <= 0)
|
||||
{
|
||||
@@ -4773,8 +4828,14 @@ class CAllIBlockElement
|
||||
foreach (GetModuleEvents("iblock", "OnIBlockElementDelete", true) as $arEvent)
|
||||
ExecuteModuleEventEx($arEvent, array($elementId, $zr));
|
||||
|
||||
while($res = $db_res->Fetch())
|
||||
while ($res = $db_res->Fetch())
|
||||
{
|
||||
CIBlockElement::DeleteFile($res["VALUE"], $zr["ID"], "PROPERTY", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
|
||||
}
|
||||
unset(
|
||||
$res,
|
||||
$db_res,
|
||||
);
|
||||
|
||||
if($VERSION==2)
|
||||
{
|
||||
@@ -4790,7 +4851,7 @@ class CAllIBlockElement
|
||||
}
|
||||
|
||||
static $arDelCache = array();
|
||||
if(!is_set($arDelCache, $zr["IBLOCK_ID"]))
|
||||
if (!isset($arDelCache[$zr["IBLOCK_ID"]]))
|
||||
{
|
||||
$arDelCache[$zr["IBLOCK_ID"]] = [];
|
||||
$db_ps = $DB->Query("SELECT ID,IBLOCK_ID,VERSION,MULTIPLE FROM b_iblock_property WHERE PROPERTY_TYPE='E' AND (LINK_IBLOCK_ID=".$zr["IBLOCK_ID"]." OR LINK_IBLOCK_ID=0 OR LINK_IBLOCK_ID IS NULL)");
|
||||
@@ -4809,9 +4870,13 @@ class CAllIBlockElement
|
||||
}
|
||||
$arDelCache[$zr["IBLOCK_ID"]][$strTable][] = $ar_ps["ID"];
|
||||
}
|
||||
unset(
|
||||
$ar_ps,
|
||||
$db_ps,
|
||||
);
|
||||
}
|
||||
|
||||
if($arDelCache[$zr["IBLOCK_ID"]])
|
||||
if ($arDelCache[$zr["IBLOCK_ID"]])
|
||||
{
|
||||
foreach($arDelCache[$zr["IBLOCK_ID"]] as $strTable=>$arProps)
|
||||
{
|
||||
@@ -4862,11 +4927,13 @@ class CAllIBlockElement
|
||||
|
||||
$obIBlockElementRights = new CIBlockElementRights($zr["IBLOCK_ID"], $zr["ID"]);
|
||||
$obIBlockElementRights->DeleteAllRights();
|
||||
unset($obIBlockElementRights);
|
||||
|
||||
$ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($zr["IBLOCK_ID"], $zr["ID"]);
|
||||
$ipropTemplates->delete();
|
||||
unset($ipropTemplates);
|
||||
|
||||
if((int)$zr["WF_PARENT_ELEMENT_ID"]<=0 && $zr["WF_STATUS_ID"]==1 && CModule::IncludeModule("search"))
|
||||
if((int)$zr["WF_PARENT_ELEMENT_ID"]<=0 && $zr["WF_STATUS_ID"]==1 && Loader::includeModule('search'))
|
||||
{
|
||||
CSearch::DeleteIndex("iblock", $elementId);
|
||||
}
|
||||
@@ -4874,7 +4941,7 @@ class CAllIBlockElement
|
||||
CIBlockElement::DeleteFile($zr["PREVIEW_PICTURE"], $zr["ID"], "PREVIEW", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
|
||||
CIBlockElement::DeleteFile($zr["DETAIL_PICTURE"], $zr["ID"], "DETAIL", $zr["WF_PARENT_ELEMENT_ID"], $zr["IBLOCK_ID"]);
|
||||
|
||||
if(CModule::IncludeModule("workflow"))
|
||||
if (Loader::includeModule('workflow'))
|
||||
$DB->Query("DELETE FROM b_workflow_move WHERE IBLOCK_ELEMENT_ID=".$elementId);
|
||||
|
||||
$DB->Query("DELETE FROM b_iblock_element_lock WHERE IBLOCK_ELEMENT_ID=".$elementId);
|
||||
@@ -4894,7 +4961,7 @@ class CAllIBlockElement
|
||||
|
||||
\Bitrix\Iblock\PropertyIndex\Manager::deleteElementIndex($zr["IBLOCK_ID"], $piId);
|
||||
|
||||
if(CModule::IncludeModule("bizproc"))
|
||||
if (Loader::includeModule('bizproc'))
|
||||
{
|
||||
$arErrorsTmp = [];
|
||||
CBPDocument::OnDocumentDelete(["iblock", "CIBlockDocument", $zr["ID"]], $arErrorsTmp);
|
||||
@@ -4909,6 +4976,10 @@ class CAllIBlockElement
|
||||
|
||||
unset($elementId);
|
||||
}
|
||||
unset(
|
||||
$zr,
|
||||
$z,
|
||||
);
|
||||
}
|
||||
/************* QUOTA *************/
|
||||
CDiskQuota::recalculateDb();
|
||||
@@ -5012,21 +5083,21 @@ class CAllIBlockElement
|
||||
}
|
||||
|
||||
if(($ID===false || array_key_exists("NAME", $arFields)) && (string)$arFields["NAME"] === '')
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ELEMENT_NAME")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_ELEMENT_NAME")."<br>";
|
||||
|
||||
if(
|
||||
isset($arFields["ACTIVE_FROM"])
|
||||
&& $arFields["ACTIVE_FROM"] != ''
|
||||
&& !$DB->IsDate($arFields["ACTIVE_FROM"], false, LANG, "FULL")
|
||||
)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_FROM")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_ACTIVE_FROM")."<br>";
|
||||
|
||||
if(
|
||||
isset($arFields["ACTIVE_TO"])
|
||||
&& $arFields["ACTIVE_TO"] != ''
|
||||
&& !$DB->IsDate($arFields["ACTIVE_TO"], false, LANG, "FULL")
|
||||
)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_ACTIVE_TO")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_ACTIVE_TO")."<br>";
|
||||
|
||||
if(is_set($arFields, "PREVIEW_PICTURE"))
|
||||
{
|
||||
@@ -5044,7 +5115,7 @@ class CAllIBlockElement
|
||||
if($error <> '')
|
||||
$this->LAST_ERROR .= $error."<br>";
|
||||
elseif(($error = CFile::checkForDb($arFields, "PREVIEW_PICTURE")) !== "")
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE")."<br>".$error."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_ERR_PREVIEW_PICTURE")."<br>".$error."<br>";
|
||||
}
|
||||
elseif((int)$arFields["PREVIEW_PICTURE"] > 0)
|
||||
{
|
||||
@@ -5060,7 +5131,7 @@ class CAllIBlockElement
|
||||
) <= 0
|
||||
)
|
||||
{
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_ERR_PREVIEW_PICTURE")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_ERR_PREVIEW_PICTURE")."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5081,7 +5152,7 @@ class CAllIBlockElement
|
||||
if($error <> '')
|
||||
$this->LAST_ERROR .= $error."<br>";
|
||||
elseif(($error = CFile::checkForDb($arFields, "DETAIL_PICTURE")) !== "")
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE")."<br>".$error."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_ERR_DETAIL_PICTURE")."<br>".$error."<br>";
|
||||
}
|
||||
elseif((int)$arFields["DETAIL_PICTURE"] > 0)
|
||||
{
|
||||
@@ -5097,18 +5168,18 @@ class CAllIBlockElement
|
||||
) <= 0
|
||||
)
|
||||
{
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_ERR_DETAIL_PICTURE")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_ERR_DETAIL_PICTURE")."<br>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("TAGS", $arFields) && CModule::IncludeModule('search'))
|
||||
if(array_key_exists("TAGS", $arFields) && Loader::includeModule('search'))
|
||||
{
|
||||
$arFields["TAGS"] = implode(", ", tags_prepare($arFields["TAGS"]));
|
||||
}
|
||||
|
||||
if($ID===false && !is_set($arFields, "IBLOCK_ID"))
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
|
||||
|
||||
//Find out IBLOCK_ID from fields or from element
|
||||
$IBLOCK_ID = (int)($arFields["IBLOCK_ID"] ?? 0);
|
||||
@@ -5133,7 +5204,7 @@ class CAllIBlockElement
|
||||
if($IBLOCK_CACHE[$IBLOCK_ID])
|
||||
$arFields["IBLOCK_ID"] = $IBLOCK_ID;
|
||||
else
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_BLOCK_ID")."<br>";
|
||||
|
||||
if (is_set($arFields,'IBLOCK_SECTION') && !empty($arFields['IBLOCK_SECTION']))
|
||||
{
|
||||
@@ -5168,7 +5239,7 @@ class CAllIBlockElement
|
||||
AND ID <> ".(int)$ID
|
||||
);
|
||||
if($res->Fetch())
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_DUP_ELEMENT_CODE")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_DUP_ELEMENT_CODE")."<br>";
|
||||
}
|
||||
|
||||
|
||||
@@ -5204,7 +5275,7 @@ class CAllIBlockElement
|
||||
$sum = intval($arFields[$FIELD_ID]);
|
||||
}
|
||||
if($sum <= 0)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
break;
|
||||
case "PREVIEW_PICTURE":
|
||||
@@ -5221,13 +5292,13 @@ class CAllIBlockElement
|
||||
&& is_array($arFields[$FIELD_ID])
|
||||
&& $arFields[$FIELD_ID]["del"] === "Y"
|
||||
)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
else
|
||||
{//There was NO picture so it MUST be present
|
||||
if(!array_key_exists($FIELD_ID, $arFields))
|
||||
{
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
elseif(is_array($arFields[$FIELD_ID]))
|
||||
{
|
||||
@@ -5236,12 +5307,12 @@ class CAllIBlockElement
|
||||
|| (array_key_exists("error", $arFields[$FIELD_ID]) && $arFields[$FIELD_ID]["error"] !== 0)
|
||||
|| $arFields[$FIELD_ID]["size"] <= 0
|
||||
)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
if(intval($arFields[$FIELD_ID]) <= 0)
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -5250,7 +5321,7 @@ class CAllIBlockElement
|
||||
{
|
||||
$val = $arFields[$FIELD_ID];
|
||||
if($val == '')
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -5261,7 +5332,7 @@ class CAllIBlockElement
|
||||
else
|
||||
$val = $arFields[$FIELD_ID];
|
||||
if($val == '')
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_BAD_FIELD", array("#FIELD_NAME#" => $field["NAME"]))."<br>";
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -5466,7 +5537,7 @@ class CAllIBlockElement
|
||||
if ($bError)
|
||||
{
|
||||
$this->LAST_ERROR .=
|
||||
GetMessage(
|
||||
Loc::getMessage(
|
||||
'IBLOCK_BAD_PROPERTY',
|
||||
array('#PROPERTY#' => $arProperty['NAME'])
|
||||
)
|
||||
@@ -5476,7 +5547,7 @@ class CAllIBlockElement
|
||||
if (!$correctValue)
|
||||
{
|
||||
$this->LAST_ERROR .=
|
||||
GetMessage(
|
||||
Loc::getMessage(
|
||||
'IBLOCK_BAD_REQUIRED_PROPERTY_VALUE',
|
||||
array('#PROPERTY#' => $arProperty['NAME'])
|
||||
)
|
||||
@@ -5515,7 +5586,7 @@ class CAllIBlockElement
|
||||
if (CIBlockElement::DeleteFile($property_value, $ID, "PROPERTY",
|
||||
(int)$arFields["WF_PARENT_ELEMENT_ID"], $arFields["IBLOCK_ID"], true) <= 0)
|
||||
{
|
||||
$this->LAST_ERROR .= GetMessage("IBLOCK_ERR_FILE_PROPERTY")."<br>";
|
||||
$this->LAST_ERROR .= Loc::getMessage("IBLOCK_ERR_FILE_PROPERTY")."<br>";
|
||||
}
|
||||
}
|
||||
elseif(is_array($property_value))
|
||||
@@ -5542,7 +5613,7 @@ class CAllIBlockElement
|
||||
{
|
||||
if(HasScriptExtension($property_value["name"]))
|
||||
{
|
||||
$error = GetMessage("FILE_BAD_TYPE")." (".$property_value["name"].").";
|
||||
$error = Loc::getMessage("FILE_BAD_TYPE")." (".$property_value["name"].").";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5964,6 +6035,56 @@ class CAllIBlockElement
|
||||
return !empty($arToDelete) || !empty($arToInsert);
|
||||
}
|
||||
|
||||
protected static function setNewElementSection(
|
||||
int $ID,
|
||||
array|string|int|bool $sections,
|
||||
int $iblockSectionId
|
||||
): bool
|
||||
{
|
||||
$listToInsert = [];
|
||||
|
||||
if (is_array($sections))
|
||||
{
|
||||
foreach ($sections as $sectionId)
|
||||
{
|
||||
$sectionId = (int)$sectionId;
|
||||
if ($sectionId > 0)
|
||||
{
|
||||
$listToInsert[$sectionId] = $sectionId;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$singleValue = (int)$sections;
|
||||
if ($singleValue > 0)
|
||||
{
|
||||
$listToInsert[$singleValue] = $singleValue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($listToInsert))
|
||||
{
|
||||
$conn = Main\Application::getConnection();
|
||||
|
||||
$conn->queryExecute("
|
||||
INSERT INTO b_iblock_section_element(IBLOCK_SECTION_ID, IBLOCK_ELEMENT_ID)
|
||||
SELECT S.ID, E.ID
|
||||
FROM b_iblock_section S, b_iblock_element E
|
||||
WHERE S.IBLOCK_ID = E.IBLOCK_ID
|
||||
AND S.ID IN (" . implode(", ", $listToInsert) . ")
|
||||
AND E.ID = " . $ID . "
|
||||
");
|
||||
}
|
||||
|
||||
if ($iblockSectionId > 0 || !empty($listToInsert))
|
||||
{
|
||||
CIBlockElement::RecalcSections($ID, $iblockSectionId);
|
||||
}
|
||||
|
||||
return !empty($listToInsert);
|
||||
}
|
||||
|
||||
function __InitFile($old_id, &$arFields, $fname)
|
||||
{
|
||||
if($old_id>0
|
||||
|
||||
@@ -1135,26 +1135,31 @@ class CAllIBlockProperty
|
||||
");
|
||||
}
|
||||
|
||||
function UpdateEnum($ID, $arVALUES, $bForceDelete = true)
|
||||
public function UpdateEnum($ID, $arVALUES, $bForceDelete = true)
|
||||
{
|
||||
global $DB, $CACHE_MANAGER;
|
||||
$ID = intval($ID);
|
||||
$ID = (int)$ID;
|
||||
|
||||
if(!is_array($arVALUES) || (empty($arVALUES) && $bForceDelete))
|
||||
if (!is_array($arVALUES) || (empty($arVALUES) && $bForceDelete))
|
||||
{
|
||||
CIBlockPropertyEnum::DeleteByPropertyID($ID);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
$ar_XML_ID = array();
|
||||
$ar_XML_ID = [];
|
||||
$db_res = $this->GetPropertyEnum($ID);
|
||||
while($res = $db_res->Fetch())
|
||||
while ($res = $db_res->Fetch())
|
||||
{
|
||||
$ar_XML_ID[rtrim($res["XML_ID"], " ")] = $res["ID"];
|
||||
}
|
||||
unset(
|
||||
$res,
|
||||
$db_res,
|
||||
);
|
||||
|
||||
$sqlWhere = "";
|
||||
if(!$bForceDelete)
|
||||
if (!$bForceDelete)
|
||||
{
|
||||
$rsProp = CIBlockProperty::GetByID($ID);
|
||||
if($arProp = $rsProp->Fetch())
|
||||
@@ -1187,7 +1192,7 @@ class CAllIBlockProperty
|
||||
{
|
||||
$VALUE = $arVALUES[$res["ID"]];
|
||||
$VAL = is_array($VALUE)? $VALUE["VALUE"]: $VALUE;
|
||||
UnSet($arVALUES[$res["ID"]]);
|
||||
unset($arVALUES[$res["ID"]]);
|
||||
|
||||
if((string)$VAL == '')
|
||||
{
|
||||
@@ -1244,6 +1249,10 @@ class CAllIBlockProperty
|
||||
$DB->Query($strSql);
|
||||
}
|
||||
}
|
||||
unset(
|
||||
$res,
|
||||
$db_res,
|
||||
);
|
||||
|
||||
foreach($arVALUES as $id => $VALUE)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Bitrix\Iblock;
|
||||
|
||||
class CIBlockPropertyEnumResult extends CDBResult
|
||||
{
|
||||
function Fetch()
|
||||
@@ -151,6 +153,8 @@ class CIBlockPropertyEnum
|
||||
if (defined("BX_COMP_MANAGED_CACHE"))
|
||||
$CACHE_MANAGER->ClearByTag("iblock_property_enum_".$arFields["PROPERTY_ID"]);
|
||||
|
||||
Iblock\PropertyEnumerationTable::cleanCache();
|
||||
|
||||
return $ID;
|
||||
}
|
||||
|
||||
@@ -178,6 +182,8 @@ class CIBlockPropertyEnum
|
||||
if (defined("BX_COMP_MANAGED_CACHE") && intval($arFields["PROPERTY_ID"]) > 0)
|
||||
$CACHE_MANAGER->ClearByTag("iblock_property_enum_".$arFields["PROPERTY_ID"]);
|
||||
|
||||
Iblock\PropertyEnumerationTable::cleanCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -191,6 +197,8 @@ class CIBlockPropertyEnum
|
||||
if (defined("BX_COMP_MANAGED_CACHE"))
|
||||
$CACHE_MANAGER->ClearByTag("iblock_property_enum_".$PROPERTY_ID);
|
||||
|
||||
Iblock\PropertyEnumerationTable::cleanCache();
|
||||
|
||||
return $DB->Query("
|
||||
DELETE FROM b_iblock_property_enum
|
||||
WHERE PROPERTY_ID=".intval($PROPERTY_ID)."
|
||||
@@ -211,6 +219,8 @@ class CIBlockPropertyEnum
|
||||
"
|
||||
);
|
||||
|
||||
Iblock\PropertyEnumerationTable::cleanCache();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -153,25 +153,9 @@ class CIBlockPropertyTools
|
||||
switch($code)
|
||||
{
|
||||
case self::CODE_MORE_PHOTO:
|
||||
$name = Loc::getMessage('IBPT_PROP_TITLE_MORE_PHOTO');
|
||||
if (isset($fields['IBLOCK_ID']))
|
||||
{
|
||||
if (Loader::includeModule('catalog'))
|
||||
{
|
||||
$catalog = CCatalogSku::GetInfoByIBlock($fields['IBLOCK_ID']);
|
||||
if (!empty($catalog))
|
||||
{
|
||||
$name =
|
||||
$catalog['CATALOG_TYPE'] === CCatalogSku::TYPE_OFFERS
|
||||
? Loc::getMessage('IBPT_PROP_TITLE_PRODUCT_VARIATION_MORE_PHOTO')
|
||||
: Loc::getMessage('IBPT_PROP_TITLE_PRODUCT_MORE_PHOTO')
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
$property = [
|
||||
'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_FILE,
|
||||
'NAME' => $name,
|
||||
'NAME' => Loc::getMessage('IBPT_PROP_TITLE_MORE_PHOTO_MSGVER_1'),
|
||||
'CODE' => self::CODE_MORE_PHOTO,
|
||||
'XML_ID' => self::XML_MORE_PHOTO,
|
||||
'MULTIPLE' => 'Y',
|
||||
|
||||
@@ -699,8 +699,10 @@ class CAllIBlockSection
|
||||
|
||||
$GLOBALS["USER_FIELD_MANAGER"]->Update("IBLOCK_".$IBLOCK_ID."_SECTION", $ID, $arFields);
|
||||
|
||||
if($bUpdateSearch)
|
||||
CIBlockSection::UpdateSearch($ID);
|
||||
if ($bUpdateSearch)
|
||||
{
|
||||
$this->UpdateSearch($ID);
|
||||
}
|
||||
|
||||
if(
|
||||
CIBlock::GetArrayByID($IBLOCK_ID, "SECTION_PROPERTY") === "Y"
|
||||
@@ -1222,8 +1224,10 @@ class CAllIBlockSection
|
||||
Iblock\PropertyIndex\Manager::markAsInvalid($db_record["IBLOCK_ID"]);
|
||||
}
|
||||
|
||||
if($bUpdateSearch)
|
||||
CIBlockSection::UpdateSearch($ID);
|
||||
if ($bUpdateSearch)
|
||||
{
|
||||
$this->UpdateSearch($ID);
|
||||
}
|
||||
|
||||
if($arIBlock["FIELDS"]["LOG_SECTION_EDIT"]["IS_REQUIRED"] == "Y")
|
||||
{
|
||||
@@ -1825,15 +1829,22 @@ class CAllIBlockSection
|
||||
return $cnt;
|
||||
}
|
||||
|
||||
public function UpdateSearch($ID, $bOverWrite=false)
|
||||
public function UpdateSearch($ID, $bOverWrite = false)
|
||||
{
|
||||
if(!CModule::IncludeModule("search")) return;
|
||||
if (!Loader::includeModule('search'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
global $DB;
|
||||
$ID = intval($ID);
|
||||
$ID = (int)$ID;
|
||||
if ($ID <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static $arGroups = array();
|
||||
static $arSITE = array();
|
||||
static $arGroups = [];
|
||||
static $arSITE = [];
|
||||
|
||||
$strSql = "
|
||||
SELECT BS.ID, BS.NAME, BS.DESCRIPTION_TYPE, BS.DESCRIPTION, BS.XML_ID as EXTERNAL_ID,
|
||||
@@ -1848,8 +1859,12 @@ class CAllIBlockSection
|
||||
AND BS.ID=".$ID;
|
||||
|
||||
$dbrIBlockSection = $DB->Query($strSql);
|
||||
$arIBlockSection = $dbrIBlockSection->Fetch();
|
||||
unset(
|
||||
$dbrIBlockSection,
|
||||
);
|
||||
|
||||
if($arIBlockSection = $dbrIBlockSection->Fetch())
|
||||
if ($arIBlockSection)
|
||||
{
|
||||
$IBLOCK_ID = $arIBlockSection["IBLOCK_ID"];
|
||||
$SECTION_URL =
|
||||
@@ -1864,6 +1879,7 @@ class CAllIBlockSection
|
||||
if($arIBlockSection["ACTIVE1"]!="Y" || $arIBlockSection["ACTIVE2"]!="Y" || $arIBlockSection["INDEX_SECTION"]!="Y")
|
||||
{
|
||||
CSearch::DeleteIndex("iblock", "S".$arIBlockSection["ID"]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Bitrix\Main\Loader;
|
||||
use Bitrix\Main\Localization\Loc;
|
||||
use Bitrix\Iblock;
|
||||
|
||||
@@ -10,6 +11,11 @@ class CIBlockPropertySKU extends CIBlockPropertyElementAutoComplete
|
||||
|
||||
public static function GetUserTypeDescription()
|
||||
{
|
||||
if (!Loader::includeModule('catalog'))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'PROPERTY_TYPE' => Iblock\PropertyTable::TYPE_ELEMENT,
|
||||
'USER_TYPE' => Iblock\PropertyTable::USER_TYPE_SKU,
|
||||
|
||||
Reference in New Issue
Block a user