升级 Magento 2.2 > 2.3.2 - 创建对象时发生类型错误:Magento\Framework\Communication\Config\Data

Chr*_*ers 0 php magento2

在 Magento 2 升级 2.2.x -> 2.3.2 后,运行部署命令后php bin/magento setup:upgrade,出现以下错误:

......
Module 'Magento_AdvancedPricingImportExport':
Module 'Magento_Directory':
Module 'Magento_Amqp':
Type Error occurred when creating object: Magento\Framework\Communication\Config\Data
Run Code Online (Sandbox Code Playgroud)

此类存在,并且没有被插件或首选项覆盖。为什么这个核心课程会引发问题?

Chr*_*ers 5

所以我发现这篇文章概述了其他人的挣扎,我觉得你们所有人。幸运的是,googla提供了对我有用的修复程序,我把它变成了一个带有偏好的不错的模块:

<preference for="Magento\Framework\Reflection\TypeProcessor" type="MY\MODULE\Framework\Reflection\TypeProcessor" />
Run Code Online (Sandbox Code Playgroud)

覆盖方法getParamType

<?php

/**
 * Fix Magento 2.3.2 upgrade setup:upgrade
 * 
 * @see https://github.com/magento/magento2/issues/22773 
 * @author Chris Rogers
 * @since 1.0.0 <2019-08-30>
 */

namespace MY\MODULE\Framework\Reflection;

use Magento\Framework\Reflection\TypeProcessor as Original;
use Zend\Code\Reflection\ParameterReflection;
use Zend\Code\Reflection\DocBlock\Tag\ParamTag;


class TypeProcessor extends Original
{
    /**
     * Get the parameter type
     *
     * @param ParameterReflection $param
     * @return string
     * @throws \LogicException
     */
    public function getParamType(ParameterReflection $param)
    {
        $type = $param->detectType();
        if ($type === 'null') {
            throw new \LogicException(sprintf(
                '@param annotation is incorrect for the parameter "%s" in the method "%s:%s".'
                    . ' First declared type should not be null. E.g. string|null',
                $param->getName(),
                $param->getDeclaringClass()->getName(),
                $param->getDeclaringFunction()->name
            ));
        }
        if ($type === 'array') {
            // try to determine class, if it's array of objects
            $paramDocBlock = $this->getParamDocBlockTag($param);
            $paramTypes = $paramDocBlock->getTypes();
            $paramType = array_shift($paramTypes);

            $paramType = $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $paramType);

            return strpos($paramType, '[]') !== false ? $paramType : "{$paramType}[]";
        }

        return $type;
    }

    /**
     * Gets method's param doc block.
     *
     * @param ParameterReflection $param
     * @return ParamTag
     */
    private function getParamDocBlockTag(ParameterReflection $param): ParamTag
    {
        $docBlock = $param->getDeclaringFunction()
            ->getDocBlock();
        $paramsTag = $docBlock->getTags('param');
        return $paramsTag[$param->getPosition()];
    }
}
Run Code Online (Sandbox Code Playgroud)

主要区别在于回报:

原来的:

返回 $this->resolveFullyQualifiedClassName($param->getDeclaringClass(), $type);

对比:

返回 $type;

Magento 的受害者,您可以继续您的日常生活。