%PDF- %PDF-
Server IP : 37.220.80.31 / Your IP : 3.15.29.248 Web Server : Apache/2.4.52 (Ubuntu) System : Linux 3051455-guretool.twc1.net 5.15.0-107-generic #117-Ubuntu SMP Fri Apr 26 12:26:49 UTC 2024 x86_64 User : www-root ( 1010) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/www-root/data/www/dev.artlot24.ru/bitrix/modules/iblock/lib/orm/ |
Upload File : |
<?php /** * Bitrix Framework * @package bitrix * @subpackage iblock * @copyright 2001-2018 Bitrix */ namespace Bitrix\Iblock\ORM; use Bitrix\Iblock\ElementTable; use Bitrix\Iblock\ORM\Fields\PropertyOneToMany; use Bitrix\Iblock\ORM\Fields\PropertyReference; use Bitrix\Iblock\PropertyIndex\Manager; use Bitrix\Main\Localization\Loc; use Bitrix\Main\ORM\Data\DataManager; use Bitrix\Main\ORM\Entity; use Bitrix\Main\ORM\Event; use Bitrix\Main\ORM\EventResult; use Bitrix\Main\ORM\Fields\FieldError; use CIBlock; use CIBlockProperty; /** * @package bitrix * @subpackage iblock */ abstract class CommonElementTable extends DataManager { /** * @return Entity|string */ public static function getEntityClass() { return ElementEntity::class; } public static function getQueryClass() { return Query::class; } public static function setDefaultScope($query) { return $query->where("IBLOCK_ID", static::getEntity()->getIblock()->getId()); } public static function getTableName() { return ElementTable::getTableName(); } public static function getMap() { return ElementTable::getMap(); } /** * Clones specific Element entity for inherited Tables * * @return Entity * @throws \Bitrix\Main\ArgumentException * @throws \Bitrix\Main\SystemException */ public static function getEntity() { $class = static::getEntityClass()::normalizeEntityClass(get_called_class()); if (!isset(static::$entity[$class])) { /** @var DataManager $parentClass */ $parentClass = get_parent_class(get_called_class()); if (!in_array( $parentClass, [ElementV1Table::class, ElementV2Table::class] )) { static::$entity[$class] = clone $parentClass::getEntity(); static::$entity[$class]->reinitialize($class); } else { static::$entity[$class] = parent::getEntity(); } } return static::$entity[$class]; } public static function onBeforeAdd(Event $event) { $object = $event->getParameter('object'); $fields = static::getEntity()->getFields(); $result = new EventResult; foreach ($fields as $field) { // check required properties $hasEmptyRequiredValue = false; if ($field instanceof PropertyReference || $field instanceof PropertyOneToMany) { $property = $field->getIblockElementProperty(); if ($property->getIsRequired()) { /** @var ValueStorage $valueContainer */ $valueContainer = $object->get($field->getName()); if (empty($valueContainer)) { $hasEmptyRequiredValue = true; } // check with GetLength if ($valueContainer instanceof ValueStorage) { $userType = CIBlockProperty::GetUserType($property->getUserType()); if(array_key_exists("GetLength", $userType)) { $length = call_user_func_array( $userType["GetLength"], [ $property->collectValues(), ["VALUE" => $valueContainer->getValue()] ] ); } else { $length = mb_strlen($valueContainer->getValue()); } $hasEmptyRequiredValue = ($length <= 0); } if ($hasEmptyRequiredValue) { $result->addError(new FieldError( $field, Loc::getMessage( "MAIN_ENTITY_FIELD_REQUIRED", ["#FIELD#" => $property->getName()] ), FieldError::EMPTY_REQUIRED )); } } } } return $result; } public static function onAfterAdd(Event $event) { $elementId = (int) end($event->getParameters()['primary']); $iblockId = static::getEntity()->getIblock()->getId(); // clear tag cache CIBlock::clearIblockTagCache($iblockId); // update index Manager::updateElementIndex($iblockId, $elementId); } public static function onAfterUpdate(Event $event) { $elementId = (int) end($event->getParameters()['primary']); $iblockId = static::getEntity()->getIblock()->getId(); // clear tag cache CIBlock::clearIblockTagCache($iblockId); // update index Manager::updateElementIndex($iblockId, $elementId); } public static function onAfterDelete(Event $event) { parent::onAfterDelete($event); $elementId = (int) end($event->getParameters()['primary']); $iblockId = static::getEntity()->getIblock()->getId(); $connection = static::getEntity()->getConnection(); // delete property values $tables = [static::getEntity()->getSingleValueTableName(), static::getEntity()->getMultiValueTableName()]; foreach (array_unique($tables) as $table) { $connection->query("DELETE FROM {$table} WHERE IBLOCK_ELEMENT_ID = {$elementId}"); } // clear tag cache CIBlock::clearIblockTagCache($iblockId); // delete index Manager::deleteElementIndex($iblockId, $elementId); } }