Ejemplo n.º 1
0
 /**
  * @return \Bitrix\Main\Entity\Base
  */
 public function getRefEntity()
 {
     if ($this->refEntity === null) {
         $this->refEntity = Base::getInstance($this->refEntityName);
     }
     return $this->refEntity;
 }
Ejemplo n.º 2
0
 /**
  * @static
  * @return Base
  */
 public static function getEntity()
 {
     $class = get_called_class();
     if (!isset(static::$entity[$class])) {
         static::$entity[$class] = Base::getInstance($class);
     }
     return static::$entity[$class];
 }
Ejemplo n.º 3
0
 function UnInstallDB()
 {
     Loader::includeModule($this->MODULE_ID);
     // Drop PersonTable
     Application::getConnection(\Adelshin\Person\PersonTable::getConnectionName())->queryExecute('drop table if exists ' . Base::getInstance('\\Adelshin\\Person\\PersonTable')->getDBTableName());
     // Drop GroupTable
     Application::getConnection(\Adelshin\Person\GroupsTable::getConnectionName())->queryExecute('drop table if exists ' . Base::getInstance('\\Adelshin\\Person\\GroupsTable')->getDBTableName());
     Option::delete($this->MODULE_ID);
 }
Ejemplo n.º 4
0
 /**
  * @param Base|Query|string $source
  * @throws Main\ArgumentException
  */
 public function __construct($source)
 {
     if ($source instanceof $this) {
         $this->init_entity = Base::getInstanceByQuery($source);
     } elseif ($source instanceof Base) {
         $this->init_entity = clone $source;
     } elseif (is_string($source)) {
         $this->init_entity = clone Base::getInstance($source);
     } else {
         throw new Main\ArgumentException(sprintf('Unknown source type "%s" for new %s', gettype($source), __CLASS__));
     }
 }
Ejemplo n.º 5
0
 /**
  * @param $iblockId
  * @return Entity\Base
  * @throws ArgumentException
  */
 public static function compileEntity($iblockId)
 {
     $iblock = IblockStructure::iblock($iblockId);
     if (!$iblock) {
         throw new ArgumentException('Указан несуществующий идентификатор инфоблока');
     }
     $entityName = "Iblock" . Entity\Base::snake2camel($iblockId) . "SectionTable";
     $fullEntityName = '\\' . __NAMESPACE__ . '\\' . $entityName;
     $code = "\n            namespace " . __NAMESPACE__ . ";\n            class {$entityName} extends SectionTable {\n                public static function getIblockId(){\n                    return {$iblock['ID']};\n                }\n                public static function getUfId(){\n                    return 'IBLOCK_{$iblock['ID']}_SECTION';\n                }\n            }\n        ";
     if (!class_exists($fullEntityName)) {
         eval($code);
     }
     return Entity\Base::getInstance($fullEntityName);
 }
Ejemplo n.º 6
0
 public static function init()
 {
     IncludeModuleLangFile(__FILE__);
     if (!self::$fInit) {
         self::$fInit = true;
         self::$siteCookieId = md5('SALE_REPORT_SITE_ID');
         // Initializing list of sites.
         $result = Bitrix\Main\SiteTable::getList(array('select' => array('LID', 'DEF', 'NAME')));
         $i = 0;
         while ($row = $result->fetch()) {
             self::$sitelist[$row['LID']] = $row['NAME'];
             if (++$i === 1) {
                 self::$defaultSiteId = $row['LID'];
             } else {
                 if ($row['DEF'] === 'Y') {
                     self::$defaultSiteId = $row['LID'];
                 }
             }
             self::$weightOptions[$row['LID']] = array('unit' => COption::GetOptionString('sale', 'weight_unit', null, $row['LID']), 'koef' => COption::GetOptionInt('sale', 'weight_koef', null, $row['LID']));
         }
         unset($i, $row, $result);
         // hack, add virtual ID field into StatusLang entity for filtering
         $statusEntity = Entity\Base::getInstance('\\Bitrix\\Sale\\Internals\\StatusLang');
         if ($statusEntity instanceof \Bitrix\Main\Entity\Base) {
             $statusEntity->addField(array('data_type' => 'string', 'expression' => array('%s', 'STATUS_ID')), 'ID');
         }
         unset($statusEntity);
         // hack, add virtual REPS_ORDER field into Shipment entity for filtering system records
         $shipmentEntity = Entity\Base::getInstance('\\Bitrix\\Sale\\Internals\\Shipment');
         if ($shipmentEntity instanceof \Bitrix\Main\Entity\Base) {
             $shipmentEntity->addField(array('data_type' => 'Order', 'reference' => array('=ref.ID' => 'this.ORDER_ID', '!=this.SYSTEM' => array('?', 'Y'))), 'REPS_ORDER');
         }
         unset($shipmentEntity);
         // Initializing list of statuses of orders.
         $result = Bitrix\Sale\Internals\StatusLangTable::getList(array('select' => array('STATUS_ID', 'NAME'), 'filter' => array('=LID' => LANGUAGE_ID)));
         while ($row = $result->fetch()) {
             self::$statuslist[$row['STATUS_ID']] = $row['NAME'];
         }
         unset($row, $result);
         self::$genders = array('M' => GetMessage('USER_MALE'), 'F' => GetMessage('USER_FEMALE'));
         // Initializing list of person types.
         $result = Bitrix\Sale\Internals\PersonTypeTable::getList(array('select' => array('ID', 'LID', 'NAME')));
         while ($row = $result->fetch()) {
             self::$personTypes[$row['ID']] = array('LID' => $row['LID'], 'NAME' => $row['NAME']);
         }
         unset($row, $result);
         // Initializing list of pay systems of orders.
         $result = Bitrix\Sale\PaySystemTable::getList(array('select' => array('ID', 'LID', 'NAME')));
         while ($row = $result->fetch()) {
             self::$paySystemList[$row['ID']] = array('value' => $row['NAME'], 'site_id' => $row['LID']);
         }
         unset($row, $result);
         // Initializing list of services and methods of delivery.
         $result = \Bitrix\Sale\Delivery\Services\Table::getList(array('select' => array('ID', 'NAME')));
         while ($row = $result->fetch()) {
             self::$deliveryList[$row['ID']] = array('value' => $row['NAME'], 'site_id' => '');
         }
         unset($row, $result);
         // Obtaining table of correspondences of iblocks to sites.
         $result = Bitrix\Iblock\IblockSiteTable::getList();
         while ($row = $result->fetch()) {
             self::$iblockSite[$row['SITE_ID']][] = $row['IBLOCK_ID'];
         }
         unset($row, $result);
         // Obtaining the list of iblocks which are directories and filling
         // a property $catalogSections with sections of these units.
         $ent = new CCatalog();
         $result = $ent->GetList();
         while ($ibRow = $result->Fetch()) {
             // Obtaining list of sections of the catalog.
             self::$catalogs[] = $ibRow;
             $path = array();
             $curLevel = $prevLevel = 0;
             $sections = CIBlockSection::GetTreeList(array('=IBLOCK_ID' => $ibRow['IBLOCK_ID']));
             $row = null;
             while ($row = $sections->GetNext()) {
                 // Formation of an array of identifiers of current and parent sections.
                 $curLevel = $row['DEPTH_LEVEL'];
                 for ($i = 0; $i <= $prevLevel - $curLevel; $i++) {
                     array_pop($path);
                 }
                 array_push($path, $row['ID']);
                 $prevLevel = $curLevel;
                 self::$catalogSections[$row['ID']] = array('name' => ltrim(str_repeat(' . ', $curLevel) . $row['NAME']), 'path' => $path, 'catalog' => array('ID' => $ibRow['ID'], 'NAME' => $ibRow['NAME']));
             }
         }
         unset($ent, $ibRow, $row, $sections, $result);
         // Initialization of the list of warehouses.
         $result = Bitrix\Catalog\StoreTable::getList(array('select' => array('ID', 'TITLE')));
         while ($row = $result->fetch()) {
             self::$productStores[$row['ID']] = $row['TITLE'];
         }
         unset($row, $result);
         // Getting currencies
         $obj = new CCurrency();
         $by = '';
         $order = '';
         $result = $obj->GetList($by, $order, LANGUAGE_ID);
         while ($row = $result->Fetch()) {
             self::$currencies[$row['CURRENCY']] = array('name' => $row['FULL_NAME']);
         }
         unset($row, $result, $obj, $by, $order);
         // Getting types of prices
         $obj = new CCatalogGroup();
         $result = $obj->GetListEx(array('SORT'), array(), false, false, array('ID', 'NAME', 'BASE', 'NAME_LANG'));
         while ($row = $result->Fetch()) {
             self::$priceTypes[$row['ID']] = array('name' => empty($row['NAME_LANG']) ? $row['NAME'] : $row['NAME_LANG'], 'base' => $row['BASE'] === 'Y' ? true : false);
         }
         unset($row, $result, $obj);
         // Getting option, which means, it is necessary to display a fractional quantity of goods of no.
         self::$fDecimalQuant = COption::GetOptionString('sale', 'QUANTITY_FACTORIAL') == 'Y';
         self::initOwners();
     }
 }
Ejemplo n.º 7
0
use Bitrix\Main\Entity;
// <editor-fold defaultstate="collapsed" desc="calc variations">
$calcVariations = $arResult['calcVariations'] = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getCalcVariations'));
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="filter compare variations">
$compareVariations = $arResult['compareVariations'] = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getCompareVariations'));
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="period types">
$periodTypes = $arResult['periodTypes'] = array('month', 'month_ago', 'week', 'week_ago', 'days', 'after', 'before', 'interval', 'all');
// </editor-fold>
try {
    // <editor-fold defaultstate="collapsed" desc="common initiazlize">
    $ownerId = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getOwnerId'));
    $entityName = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getEntityName'));
    $entityFields = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getColumnList'));
    $initEntity = Entity\Base::getInstance($entityName);
    $strChains = $entityFields;
    $chains = CReport::generateChains($strChains, $initEntity, '');
    $arResult['chains'] = $chains;
    $arResult['fieldsTree'] = CReport::generateColumnTree($chains, $initEntity, $arParams['REPORT_HELPER_CLASS']);
    $fieldList = CReport::getUniqueFieldsByTree($arResult['fieldsTree']);
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="validation">
    if ($arParams['ACTION'] == 'edit' || $arParams['ACTION'] == 'copy' || $arParams['ACTION'] == 'delete') {
        $result = Bitrix\Report\ReportTable::getById($arParams['REPORT_ID']);
        $report = $result->fetch();
        if (empty($report)) {
            throw new BXUserException(sprintf(GetMessage('REPORT_NOT_FOUND'), $arParams['REPORT_ID']));
        }
        if ($report['CREATED_BY'] != $USER->GetID()) {
            throw new BXUserException(GetMessage('REPORT_VIEW_PERMISSION_DENIED'));
Ejemplo n.º 8
0
 // </editor-fold>
 $runtime = array();
 $select = array();
 $group = array();
 $order = array();
 $limit = array();
 $options = array('SQL_TIME_INTERVAL' => $sqlTimeInterval);
 $excelView = isset($_GET["EXCEL"]) && $_GET["EXCEL"] == "Y";
 // <editor-fold defaultstate="collapsed" desc="parse entity">
 $entityName = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getEntityName'));
 $entityFields = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getColumnList'));
 $grcFields = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getGrcColumns'));
 //$arUFInfo = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getUFInfo'));
 $arUFEnumerations = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getUFEnumerations'));
 // customize entity
 $entity = clone Entity\Base::getInstance($entityName);
 call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'setRuntimeFields'), $entity, $sqlTimeInterval);
 $chains = CReport::generateChains($entityFields, $entity, '');
 $fieldsTree = CReport::generateColumnTree($chains, $entity, $arParams['REPORT_HELPER_CLASS']);
 unset($chains);
 // custom columns types
 $customColumnTypes = call_user_func(array($arParams['REPORT_HELPER_CLASS'], 'getCustomColumnTypes'));
 if (!is_array($customColumnTypes)) {
     $customColumnTypes = array();
 }
 // </editor-fold>
 // <editor-fold defaultstate="collapsed" desc="parse select columns">
 // <editor-fold defaultstate="collapsed" desc="collect fields">
 $fList = array();
 $fChainList = array();
 $bGroupingMode = false;
Ejemplo n.º 9
0
 public static function getChainByDefinition(Base $init_entity, $definition)
 {
     $chain = new QueryChain();
     $chain->addElement(new QueryChainElement($init_entity));
     $def_elements = explode('.', $definition);
     $def_elements_size = count($def_elements);
     $prev_entity = $init_entity;
     $i = 0;
     foreach ($def_elements as &$def_element) {
         $is_last_elem = ++$i == $def_elements_size;
         $not_found = false;
         // all elements should be a Reference field or Entity
         // normal (scalar) field can only be the last element
         if ($prev_entity->hasField($def_element)) {
             // field has been found at current entity
             $field = $prev_entity->getField($def_element);
             if ($field instanceof ReferenceField) {
                 $prev_entity = $field->getRefEntity();
             } elseif ($field instanceof ExpressionField) {
                 // expr can be in the middle too
             } elseif (!$is_last_elem) {
                 throw new SystemException(sprintf('Normal fields can be only the last in chain, `%s` %s is not the last.', $field->getName(), get_class($field)));
             }
             if ($is_last_elem && $field instanceof ExpressionField) {
                 // we should have own copy of build_from_chains to set join aliases there
                 $field = clone $field;
             }
             $chain->addElement(new QueryChainElement($field));
         } elseif ($prev_entity->hasUField($def_element) && false) {
             /** @deprecated */
             // extend chain with utm/uts entity
             $ufield = $prev_entity->getUField($def_element);
             if ($ufield->isMultiple()) {
                 // add utm entity  user.utm:source_object (1:N)
                 $utm_entity = Base::getInstance($prev_entity->getNamespace() . 'Utm' . $prev_entity->getName());
                 $chain->addElement(new QueryChainElement(array($utm_entity, $utm_entity->getField('SOURCE_OBJECT')), array('ufield' => $ufield)));
                 if ($ufield->getTypeId() == 'iblock_section' && substr($ufield->getName(), -3) == '_BY' && $prev_entity->hasUField(substr($ufield->getName(), 0, -3))) {
                     // connect next entity
                     $utm_fname = $ufield->getName();
                     $prev_entity = Base::getInstance('Bitrix\\Iblock\\Section');
                 } else {
                     $utm_fname = $ufield->getValueFieldName();
                 }
                 $chain->addElement(new QueryChainElement($utm_entity->getField($utm_fname), array('ufield' => $ufield)));
             } else {
                 // uts table - single value
                 // add uts entity user.uts (1:1)
                 $uts_entity = Base::getInstance($prev_entity->getNamespace() . 'Uts' . $prev_entity->getName());
                 $chain->addElement(new QueryChainElement($prev_entity->getField('UTS_OBJECT')));
                 // add `value` field
                 $chain->addElement(new QueryChainElement($uts_entity->getField($def_element)));
             }
         } elseif (Base::isExists($def_element) && Base::getInstance($def_element)->getReferencesCountTo($prev_entity->getName()) == 1) {
             // def_element is another entity with only 1 reference to current entity
             // need to identify Reference field
             $ref_entity = Base::getInstance($def_element);
             $field = end($ref_entity->getReferencesTo($prev_entity->getName()));
             $prev_entity = $ref_entity;
             $chain->addElement(new QueryChainElement(array($ref_entity, $field)));
         } elseif (($pos_wh = strpos($def_element, ':')) > 0) {
             $ref_entity_name = substr($def_element, 0, $pos_wh);
             if (strpos($ref_entity_name, '\\') === false) {
                 // if reference has no namespace, then it'is in the namespace of previous entity
                 $ref_entity_name = $prev_entity->getNamespace() . $ref_entity_name;
             }
             if (Base::isExists($ref_entity_name) && Base::getInstance($ref_entity_name)->hasField($ref_field_name = substr($def_element, $pos_wh + 1)) && Base::getInstance($ref_entity_name)->getField($ref_field_name) instanceof ReferenceField) {
                 /** @var ReferenceField $reference */
                 $reference = Base::getInstance($ref_entity_name)->getField($ref_field_name);
                 if ($reference->getRefEntity()->getFullName() == $prev_entity->getFullName()) {
                     // chain element is another entity with >1 references to current entity
                     // def like NewsArticle:AUTHOR, NewsArticle:LAST_COMMENTER
                     // NewsArticle - entity, AUTHOR and LAST_COMMENTER - Reference fields
                     $chain->addElement(new QueryChainElement(array(Base::getInstance($ref_entity_name), Base::getInstance($ref_entity_name)->getField($ref_field_name))));
                     $prev_entity = Base::getInstance($ref_entity_name);
                 } else {
                     $not_found = true;
                 }
             } else {
                 $not_found = true;
             }
         } elseif ($def_element == '*' && $is_last_elem) {
             continue;
         } else {
             // unknown chain
             $not_found = true;
         }
         if ($not_found) {
             throw new SystemException(sprintf('Unknown field definition `%s` (%s) for %s Entity.', $def_element, $definition, $prev_entity->getName()), 100);
         }
     }
     return $chain;
 }
Ejemplo n.º 10
0
 public static function prepareSelectViewElement($elem, $select, $is_init_entity_aggregated, $fList, $fChainList, $helper_class)
 {
     $result = null;
     $alias = null;
     $entity = Entity\Base::getInstance(call_user_func(array($helper_class, 'getEntityName')));
     if (empty($elem['aggr']) && !strlen($elem['prcnt'])) {
         $result = $elem['name'];
     } else {
         $dataType = '';
         $expression = '';
         $alias = Entity\QueryChain::getAliasByDefinition($entity, $elem['name']);
         $field = $fList[$elem['name']];
         $chain = $fChainList[$elem['name']];
         if (!empty($elem['aggr'])) {
             $alias = $elem['aggr'] . '_' . $alias;
             if ($field->getDataType() == 'boolean') {
                 // sum int for boolean
                 global $DB;
                 $trueValue = $field->normalizeValue(true);
                 $localDef = 'CASE WHEN %s = \'' . $DB->ForSql($trueValue) . '\' THEN 1 ELSE 0 END';
             } else {
                 $localDef = '%s';
             }
             if ($elem['aggr'] == 'COUNT_DISTINCT') {
                 $dataType = 'integer';
                 $expression = array('COUNT(DISTINCT ' . $localDef . ')', $elem['name']);
             } else {
                 if ($field->getDataType() == 'boolean') {
                     $dataType = 'integer';
                 } else {
                     $dataType = $field->getDataType();
                 }
                 if ($elem['aggr'] == 'GROUP_CONCAT') {
                     $expression = array($localDef, $elem['name']);
                 } else {
                     $expression = array($elem['aggr'] . '(' . $localDef . ')', $elem['name']);
                 }
             }
             // pack 1:N aggregations into subquery
             if ($chain->hasBackReference() && $elem['aggr'] != 'GROUP_CONCAT') {
                 $confirm = call_user_func_array(array($helper_class, 'confirmSelectBackReferenceRewrite'), array(&$elem, $chain));
                 if ($confirm) {
                     $filter = array();
                     foreach ($entity->GetPrimaryArray() as $primary) {
                         $filter['=' . $primary] = new CSQLWhereExpression('?#', ToLower($entity->getCode()) . '.' . $primary);
                     }
                     $query = new Entity\Query($entity);
                     $query->addSelect(array('data_type' => $dataType, 'expression' => $expression), 'X');
                     $query->setFilter($filter);
                     $query->setTableAliasPostfix('_sub');
                     $expression = array('(' . $query->getQuery() . ')');
                     // double aggregation if init entity aggregated
                     if ($is_init_entity_aggregated) {
                         if ($elem['aggr'] == 'COUNT_DISTINCT') {
                             $expression[0] = 'SUM(' . $expression[0] . ')';
                         } else {
                             $expression[0] = $elem['aggr'] . '(' . $expression[0] . ')';
                         }
                     }
                 }
                 // confirmed
             }
         }
         if (strlen($elem['prcnt'])) {
             $alias = $alias . '_PRCNT';
             $dataType = 'integer';
             if ($elem['prcnt'] == 'self_column') {
                 if (empty($expression)) {
                     $expression = array('%s', $elem['name']);
                 }
             } else {
                 if (empty($expression)) {
                     $localDef = '%s';
                     $localMembers = array($elem['name']);
                 } else {
                     $localDef = $expression[0];
                     $localMembers = array_slice($expression, 1);
                 }
                 list($remoteAlias, $remoteSelect) = self::prepareSelectViewElement($select[$elem['prcnt']], $select, $is_init_entity_aggregated, $fList, $fChainList, $helper_class);
                 if (is_array($remoteSelect) && !empty($remoteSelect['expression'])) {
                     // remote field is expression
                     $remoteDef = $remoteSelect['expression'][0];
                     $remoteMembers = array_slice($remoteSelect['expression'], 1);
                     $alias = $alias . '_FROM_' . $remoteAlias;
                 } else {
                     // remote field is usual field
                     $remoteDef = '%s';
                     $remoteMembers = array($remoteSelect);
                     $alias = $alias . '_FROM_' . $remoteSelect;
                 }
                 $exprDef = '(' . $localDef . ') / (' . $remoteDef . ') * 100';
                 $expression = array_merge(array($exprDef), $localMembers, $remoteMembers);
                 // 'ROUND(STATUS / ID * 100)'
                 // 'ROUND( (EX1(F1, F2)) / (EX2(F3, F1)) * 100)',
                 // F1, F2, F3, F1
             }
         }
         $result = array('data_type' => $dataType, 'expression' => $expression);
     }
     return array($alias, $result);
 }
Ejemplo n.º 11
0
    public static function compileEntity($hlblock)
    {
        // generate entity & data manager
        $fieldsMap = array();
        // add ID
        $fieldsMap['ID'] = array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true);
        // add other fields
        $fields = $GLOBALS['USER_FIELD_MANAGER']->getUserFields('HLBLOCK_' . $hlblock['ID']);
        foreach ($fields as $field) {
            $fieldsMap[$field['FIELD_NAME']] = array('data_type' => \Bitrix\Main\Entity\UField::convertBaseTypeToDataType($field['USER_TYPE']['BASE_TYPE']));
        }
        // build classes
        $entity_name = $hlblock['NAME'];
        $entity_data_class = $hlblock['NAME'];
        if (!class_exists($entity_data_class . 'Table')) {
            if (!preg_match('/^[a-z0-9_]+$/i', $entity_data_class)) {
                throw new \Exception(sprintf('Invalid entity name `%s`.', $entity_data_class));
            }
            $entity_table_name = $hlblock['TABLE_NAME'];
            $eval = '
				class ' . $entity_data_class . 'Table extends ' . __NAMESPACE__ . '\\DataManager
				{
					public static function getFilePath()
					{
						return __FILE__;
					}

					public static function getTableName()
					{
						return ' . var_export($entity_table_name, true) . ';
					}

					public static function getMap()
					{
						return ' . var_export($fieldsMap, true) . ';
					}
				}
			';
            eval($eval);
        }
        return \Bitrix\Main\Entity\Base::getInstance($entity_name);
    }
Ejemplo n.º 12
0
 public static function onAfterUserTypeAdd($field)
 {
     global $APPLICATION, $USER_FIELD_MANAGER;
     if (preg_match('/^HLBLOCK_(\\d+)$/', $field['ENTITY_ID'], $matches)) {
         $field['USER_TYPE'] = $USER_FIELD_MANAGER->getUserType($field['USER_TYPE_ID']);
         // get entity info
         $hlblock_id = $matches[1];
         $hlblock = HighloadBlockTable::getById($hlblock_id)->fetch();
         if (empty($hlblock)) {
             $APPLICATION->throwException(sprintf('Entity "HLBLOCK_%s" wasn\'t found.', $hlblock_id));
             return false;
         }
         // get usertype info
         $sql_column_type = $USER_FIELD_MANAGER->getUtsDBColumnType($field);
         // create field in db
         $connection = Application::getConnection();
         $sqlHelper = $connection->getSqlHelper();
         $connection->query(sprintf('ALTER TABLE %s ADD %s %s', $sqlHelper->quote($hlblock['TABLE_NAME']), $sqlHelper->quote($field['FIELD_NAME']), $sql_column_type));
         if ($field['MULTIPLE'] == 'Y') {
             // create table for this relation
             $hlentity = static::compileEntity($hlblock);
             $utmEntity = Entity\Base::getInstance(HighloadBlockTable::getUtmEntityClassName($hlentity, $field));
             $utmEntity->createDbTable();
             // add indexes
             $connection->query(sprintf('CREATE INDEX %s ON %s (%s)', $sqlHelper->quote('IX_UTM_HL' . $hlblock['ID'] . '_' . $field['ID'] . '_ID'), $sqlHelper->quote($utmEntity->getDBTableName()), $sqlHelper->quote('ID')));
             $connection->query(sprintf('CREATE INDEX %s ON %s (%s)', $sqlHelper->quote('IX_UTM_HL' . $hlblock['ID'] . '_' . $field['ID'] . '_VALUE'), $sqlHelper->quote($utmEntity->getDBTableName()), $sqlHelper->quote('VALUE')));
         }
         return array('PROVIDE_STORAGE' => false);
     }
     return true;
 }
Ejemplo n.º 13
0
 public function uninstallDB()
 {
     Loader::includeModule($this->MODULE_ID);
     Application::getConnection(\Shantilab\YandexDirect\AccountsTable::getConnectionName())->queryExecute('drop table if exists ' . Base::getInstance('\\Shantilab\\YandexDirect\\AccountsTable')->getDBTableName());
     Option::delete($this->MODULE_ID);
 }