Smile\ElasticsuiteVirtualCategory\Setup\UpgradeData::updateVirtualCategoryRootTypeToInt PHP Method

updateVirtualCategoryRootTypeToInt() private method

Migration from 1.0.0 to 1.1.0 : - Updating the attribute virtual_category_root from type varchar to type int - Updating the value of the attribute from 'category/13' to '13.
private updateVirtualCategoryRootTypeToInt ( Magento\Framework\Setup\ModuleDataSetupInterface $setup )
$setup Magento\Framework\Setup\ModuleDataSetupInterface Setup.
    private function updateVirtualCategoryRootTypeToInt(ModuleDataSetupInterface $setup)
    {
        /**
         * @var \Magento\Eav\Setup\EavSetup $eavSetup
         */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        // Fix the attribute type.
        $eavSetup->updateAttribute(Category::ENTITY, 'virtual_category_root', 'backend_type', 'int');
        // Retrieve information about the attribute and storage config.
        $virtualRootAttributeId = $eavSetup->getAttribute(Category::ENTITY, 'virtual_category_root', 'attribute_id');
        $originalTable = $setup->getTable('catalog_category_entity_varchar');
        $targetTable = $setup->getTable('catalog_category_entity_int');
        $baseFields = array_slice(array_keys($setup->getConnection()->describeTable($originalTable)), 1, -1);
        // Select old value.
        $valueSelect = $setup->getConnection()->select();
        $valueSelect->from($setup->getTable('catalog_category_entity_varchar'), $baseFields)->where('attribute_id = ?', $virtualRootAttributeId)->columns(['value' => new \Zend_Db_Expr('REPLACE(value, "category/", "")')]);
        // Insert old values into the new table.
        $query = $setup->getConnection()->insertFromSelect($valueSelect, $targetTable, array_merge($baseFields, ['value']), AdapterInterface::INSERT_IGNORE);
        $setup->getConnection()->query($query);
        // Delete old value.
        $setup->getConnection()->delete($originalTable, "attribute_id = {$virtualRootAttributeId}");
        return $this;
    }