Smile\ElasticsuiteCatalog\Setup\InstallData::updateAttributeDefaultValue PHP Method

updateAttributeDefaultValue() private method

All existing values are erased by the new value.
private updateAttributeDefaultValue ( integer | string $entityTypeId, integer | string $attributeId, mixed $value, array $excludedIds = [] ) : void
$entityTypeId integer | string Target entity id.
$attributeId integer | string Target attribute id.
$value mixed Value to be set.
$excludedIds array List of categories that should not be updated during the process.
return void
    private function updateAttributeDefaultValue($entityTypeId, $attributeId, $value, $excludedIds = [])
    {
        $setup = $this->eavSetup->getSetup();
        $entityTable = $setup->getTable($this->eavSetup->getEntityType($entityTypeId, 'entity_table'));
        $attributeTable = $this->eavSetup->getAttributeTable($entityTypeId, $attributeId);
        if (!is_int($attributeId)) {
            $attributeId = $this->eavSetup->getAttributeId($entityTypeId, $attributeId);
        }
        // Retrieve the primary key name. May differs if the staging module is activated or not.
        $linkField = $this->metadataPool->getMetadata(CategoryInterface::class)->getLinkField();
        $entitySelect = $this->getConnection()->select();
        $entitySelect->from($entityTable, [new \Zend_Db_Expr("{$attributeId} as attribute_id"), $linkField, new \Zend_Db_Expr("{$value} as value")]);
        if (!empty($excludedIds)) {
            $entitySelect->where("entity_id NOT IN(?)", $excludedIds);
        }
        $insertQuery = $this->getConnection()->insertFromSelect($entitySelect, $attributeTable, ['attribute_id', $linkField, 'value'], AdapterInterface::INSERT_ON_DUPLICATE);
        $this->getConnection()->query($insertQuery);
    }