src/ImportCsvContentHandler.php
protected function _initElement($number, $row, $contentId = null, $className = null)
    {
        if (!$contentId)
        {
            $contentId    =   $this->content_id;
        }

        if (!$className)
        {
            $className = CmsContentElement::className();
        }

        if (!$this->unique_field)
        {
            $element                = new $className();
            $element->content_id    =   $contentId;
        } else
        {
            $uniqueValue = trim($this->getValue($this->unique_field, $row));
            if ($uniqueValue)
            {
                if (strpos("field_" . $this->unique_field, 'element.'))
                {
                    $realName = str_replace("element.", "", $this->unique_field);
                    $element = CmsContentElement::find()->where([$realName => $uniqueValue])->one();

                } else if (strpos("field_" . $this->unique_field, 'property.'))
                {
                    $realName = str_replace("property.", "", $this->unique_field);

                    /**
                     * @var $property CmsContentProperty
                     */
                    $property = CmsContentProperty::find()->where(['code' => $realName])->one();
                    $query = $className::find();
                    $className::filterByProperty($query, $property, $uniqueValue);

                    $element = $query->one();
                    //print_r($query->createCommand()->rawSql);die;

                    /*$element = $className::find()

                        ->joinWith('relatedElementProperties map')
                        ->joinWith('relatedElementProperties.property property')

                        ->andWhere(['property.code'     => $realName])
                        ->andWhere(['map.value'         => $uniqueValue])

                        ->joinWith('cmsContent as ccontent')
                        ->andWhere(['ccontent.id'        => $contentId])

                        ->one()
                    ;*/
                }
            } else
            {
                throw new Exception('Не задано уникальное значение');
            }

            if (!$element)
            {
                $element                = new $className();
                $element->content_id    =   $contentId;
            }
        }

        return $element;
    }
protected function _initElement($number, $row, $contentId = null, $className = null)
    {
        if (!$contentId)
        {
            $contentId    =   $this->content_id;
        }

        if (!$className)
        {
            $className = CmsContentElement::className();
        }

        if (!$this->unique_field)
        {
            $element                = new $className();
            $element->content_id    =   $contentId;
        } else
        {
            $uniqueValue = trim($this->getValue($this->unique_field, $row));
            if ($uniqueValue)
            {
                if (strpos("field_" . $this->unique_field, 'element.'))
                {
                    $realName = str_replace("element.", "", $this->unique_field);
                    $element = CmsContentElement::find()->where([$realName => $uniqueValue])->one();

                } else if (strpos("field_" . $this->unique_field, 'property.'))
                {
                    $realName = str_replace("property.", "", $this->unique_field);

                    /**
                     * @var $property CmsContentProperty
                     */
                    $property = CmsContentProperty::find()->where(['code' => $realName])->one();
                    $query = $className::find();
                    $className::filterByProperty($query, $property, $uniqueValue);

                    $element = $query->one();
                    //print_r($query->createCommand()->rawSql);die;

                    /*$element = $className::find()

                        ->joinWith('relatedElementProperties map')
                        ->joinWith('relatedElementProperties.property property')

                        ->andWhere(['property.code'     => $realName])
                        ->andWhere(['map.value'         => $uniqueValue])

                        ->joinWith('cmsContent as ccontent')
                        ->andWhere(['ccontent.id'        => $contentId])

                        ->one()
                    ;*/
                }
            } else
            {
                throw new Exception('Не задано уникальное значение');
            }

            if (!$element)
            {
                $element                = new $className();
                $element->content_id    =   $contentId;
            }
        }

        return $element;
    }
@param $number
@param $row

@return array|null|CmsContentElement|\yii\db\ActiveRecord
@throws Exception