当前位置: 首页 > 知识库问答 >
问题:

My TYPO3 CMS 6.2 Extbase扩展在多个控制器和操作方法之间传递对象以及持久性时崩溃

蔚宏大
2023-03-14

我正在使用TYPO3 CMS 6.2编写一个TYPO3扩展。x LTS和扩展生成器。扩展应将CSV文件导入域模型,并在导入期间填充另外两个模型。

CSV文件导入正常,但以下控制器方法正在崩溃,我在解决问题时遇到问题。我相信问题的根源可能隐藏在我的插件调用第一个方法的事实中,但是每个方法都直接转到下一个方法。Extbase文档让我相信forward()不会返回到调用方法,我需要返回到原始方法以继续处理更多导入记录。

我的插件URI激活重要的MemberControlller-

致命错误:对成员函数的调用在第157行的typo3conf\ext\my扩展名\类\控制器\HasRoleController.php中的null上保持All()

包括TCA在内的配置通常从扩展生成器构建时就保持不变。

下面是一些扩展代码。很抱歉这么长时间。

<?php
namespace MyNameSpace\Myextension\Controller;
/**
 * ImportMemberController
 */
class ImportMemberController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

    /**
     * importMemberRepository
     * 
     * @var \MyNameSpace\Myextension\Domain\Repository\ImportMemberRepository
     * @inject
     */
    protected $importMemberRepository = NULL;

    /**
     * personRepository
     *
     * @var \MyNameSpace\Myextension\Domain\Repository\PersonRepository
     * @inject
     */
    protected $personRepository = NULL;

    /**
     * @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
     * @inject
     */
    protected $persistenceManager;

    /**
     * action import
     *
     * @return void
     */
    public function importAction() {
        $importMembers = $this->importMemberRepository->findAll();
        foreach ($importMembers as $importMember) {

            // Assess the qualification of this import person.
            $newQualification = TRUE;
            if ($importMember->getEmail() == "") {
                $newQualification = FALSE;
            }
            elseif ($importMember->getFirstName() == "") {
                $newQualification = FALSE;
            }
            elseif ($importMember->getLastName() == "") {
                $newQualification = FALSE;
            }

            // Determine whether this person is already in the personRepository.
            $queryResult = $this->personRepository->findBySomeNumber($importMember->getSomeNumber());
            if ($queryResult->count() > 0) {
                $person = $queryResult->getFirst();
                // Update changes to an existing person's specified properties.
                if ($person->getFamilyName() != $importMember->getLastName()) {
                    $person->setFamilyName($importMember->getLastName());
                }
                if ($person->getFirstName() != $importMember->getFirstName()) {
                    $person->setFirstName($importMember->getFirstName());
                }
                if ($person->getEmailAddress() != $importMember->getEmail()) {
                    $person->setEmailAddress($importMember->getEmail());
                }
                $this->personRepository->update($person);
                // Obtain the qualification status of this existing person.
                $existingQualification = $person->getQualifiedUser();
                // Disenroll this existing person if they no longer qualify.
                if ($existingQualification && !$newQualification) {
                    $person->setQualifiedUser(FALSE);
                }
                // Else enroll this existing person if they qualify after being unqualified.
                elseif (!$existingQualification && $newQualification) {
                    $person->setQualifiedUser(TRUE); // @todo: Reevaluate the need for this instruction.
                }
                // Else act if this existing person qualifies but changed  Office.
                elseif ($existingQualification && $newQualification && 2==1) {
                    // @todo: Later.
                }
            }
            else {
                // Act if this new import person qualifies.
                if ($newQualification) {
                    // Enter this new import person into personRepository.
                    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
                    $newPerson = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Model\\Person');
                    $newPerson->setFamilyName($importMember->getLastName());
                    $newPerson->setFirstName($importMember->getFirstName());
                    $newPerson->setSomeNumber($importMember->getSomeNumber());
                    $newPerson->setEmailAddress($importMember->getEmail());
                    $this->personRepository->add($newPerson);
                    $this->persistenceManager->persistAll();
                    // Enroll this new import person.
                    if ($importMember->getDate()) {
                        $startTime = $importMember->getDate();
                    }
                    else {
                        $startTime = new \DateTime();
                    }
                    if ($importMember->getPaidThru()) {
                        $stopTime = $importMember->getPaidThru();
                    }
                    else {
                        $stopTime = new \DateTime();
                        $stopTime->modify('+100 years');
                    }
                    $parameters = array(
                        'title' => ' Office '.$importMember->getOffice().' Member',
                        'startTime' => $startTime,
                        'stopTime' => $stopTime
                    );
                    $newPersonController = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MyNameSpace\\Myextension\\Controller\\PersonController');
                    $newPersonController->enrollAction($newPerson, $parameters);
                }
            }
        }
        $this->redirect('list');
    }
}

<?php
namespace MyNameSpace\Myextension\Controller;
/**
 * PersonController
 */
class PersonController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

    /**
     * personRepository
     * 
     * @var \MyNameSpace\Myextension\Domain\Repository\PersonRepository
     * @inject
     */
    protected $personRepository = NULL;

    /**
     * roleRepository
     *
     * @var \MyNameSpace\Myextension\Domain\Repository\RoleRepository
     * @inject
     */
    protected $roleRepository = NULL;

    /**
     * action enroll
     *
     * @param \MyNameSpace\Myextension\Domain\Model\Person $person
     * @param mixed[] $parameters
     * @return void
     */
    public function enrollAction(\MyNameSpace\Myextension\Domain\Model\Person $person,
                                $parameters) {
        $person->setQualifiedUser(TRUE);
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
        $this->roleRepository = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Repository\\RoleRepository');
        if ($parameters['title']) {
            $queryResult = $this->roleRepository->findByTitle($parameters['title']);
            if ($queryResult->count() > 0) {
                $role = $queryResult->getFirst();
                if ($parameters['startTime']) {
                    $startTime = $parameters['startTime'];
                } else {
                    $startTime = new \DateTime();
                }
                if ($parameters['stopTime']) {
                    $stopTime = $parameters['stopTime'];
                } else {
                    $stopTime = new \DateTime();
                    $stopTime->modify('+100 years');
                }
                $newHasRoleController = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('MyNameSpace\\Myextension\\Controller\\HasRoleController');
                $newHasRoleController->commissionAction($person, $role, $startTime, $stopTime);
            }
        }
    }
}

<?php
namespace MyNameSpace\Myextension\Controller;
/**
 * HasRoleController
 */
class HasRoleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {

    /**
     * hasRoleRepository
     * 
     * @var \MyNameSpace\Myextension\Domain\Repository\HasRoleRepository
     * @inject
     */
    protected $hasRoleRepository = NULL;

    /**
     * @var \TYPO3\CMS\Extbase\Object\ObjectManager
     * @inject
     */
    protected $objectManager;

    /**
     * persistence manager
     *
     * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface
     * @inject
     */
    protected $persistenceManager;

    /**
     * action commission
     *
     * @param \MyNameSpace\Myextension\Domain\Model\Person $person
     * @param \MyNameSpace\Myextension\Domain\Model\Role $role
     * @param \DateTime $startTime
     * @param \DateTime $stopTime
     * @return void
     */
    public function commissionAction(\MyNameSpace\Myextension\Domain\Model\Person $person,
                                    \MyNameSpace\Myextension\Domain\Model\Role $role,
                                    $startTime, $stopTime) {
        //$newHasRole = new \MyNameSpace\Myextension\Domain\Model\HasRole(); // @todo: Remove this line.
        $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
        $objectManager->get(\TYPO3\CMS\Extbase\Mvc\Controller\Arguments::class);
        $newHasRole = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Model\\HasRole');
        //$newHasRole = $this->objectManager->get('MyNameSpace\\Myextension\\Domain\\Model\\HasRole');
        $newHasRole->setStartTime($startTime);
        $newHasRole->setStopTime($stopTime);
        $newHasRole->addPerson($person);
        //$newHasRole->setPerson($person); // @todo: Remove this line.
        $newHasRole->addRole($role);
        //$newHasRole->setRole($person); // @todo: Remove this line.
        $this->hasRoleRepository = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Repository\\HasRoleRepository');
        //$this->hasRoleRepository = $this->objectManager->get('MyNameSpace\\Myextension\\Domain\\Repository\\HasRoleRepository');
        $this->hasRoleRepository->add($newHasRole);
        $this->persistenceManager->persistAll();
    }
}

在崩溃点,本地范围中的变量是:

$newHasRole = object(MyNameSpace\Myextension\Domain\Model\HasRole)
  protected 'startTime' => 
    object(DateTime)[834]
      public 'date' => string '1993-11-29 19:00:00.000000' (length=26)
      public 'timezone_type' => int 3
      public 'timezone' => string 'America/New_York' (length=16)
  protected 'stopTime' => 
    object(DateTime)[982]
      public 'date' => string '2116-03-10 17:55:43.000000' (length=26)
      public 'timezone_type' => int 3
      public 'timezone' => string 'America/New_York' (length=16)
  protected 'person' => 
    object(TYPO3\CMS\Extbase\Persistence\ObjectStorage)[1008]
      private 'warning' => string 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\CMS\Extbase\Persistence\ObjectStorage. To retrieve the first result, you can use the rewind() and current() methods.' (length=228)
      protected 'storage' => 
        array (size=1)
          '000000007303096700000000080231e7' => 
            array (size=2)
              ...
      protected 'isModified' => boolean true
      protected 'addedObjectsPositions' => 
        array (size=1)
          '000000007303096700000000080231e7' => int 1
      protected 'removedObjectsPositions' => 
        array (size=0)
          empty
      protected 'positionCounter' => int 1
  protected 'role' => 
    object(TYPO3\CMS\Extbase\Persistence\ObjectStorage)[1045]
      private 'warning' => string 'You should never see this warning. If you do, you probably used PHP array functions like current() on the TYPO3\CMS\Extbase\Persistence\ObjectStorage. To retrieve the first result, you can use the rewind() and current() methods.' (length=228)
      protected 'storage' => 
        array (size=1)
          '0000000073030eea00000000080231e7' => 
            array (size=2)
              ...
      protected 'isModified' => boolean true
      protected 'addedObjectsPositions' => 
        array (size=1)
          '0000000073030eea00000000080231e7' => int 1
      protected 'removedObjectsPositions' => 
        array (size=0)
          empty
      protected 'positionCounter' => int 1
  protected 'uid' => null
  protected '_localizedUid' => null
  protected '_languageUid' => null
  protected '_versionedUid' => null
  protected 'pid' => null
  private '_isClone' (TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject) => boolean false
  private '_cleanProperties' (TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject) => 
    array (size=0)
      empty

$objectManager = object(TYPO3\CMS\Extbase\Object\ObjectManager)
$person = object(KeystoneResearchSolutions\Grouprole\Domain\Model\Person)
$role = object(KeystoneResearchSolutions\Grouprole\Domain\Model\Role)
$startTime = object(DateTime)
$stopTime = object(DateTime)

共有3个答案

轩辕风华
2023-03-14

您注入了持久性管理器,但未清除所有缓存。。。。您必须清除所有内容以反映新的注入。在某些情况下,甚至清除typo3temp文件夹。

要在BE中为所选用户添加Flush system caches图标,而无需使用安装工具,只需编辑所需帐户并将其添加到其TSConfig

options.clearCache.system = 1

保存用户并按F5刷新整个BE。

允许任何人清除系统缓存(尤其是在大型实例中)是一个相当糟糕的主意,所以只对开发人员和聪明的管理员保留这种可能性。

强才捷
2023-03-14

如果在每个操作结束时与存储库相关联,那么不需要手动持久化对象,因为extbase会自动持久化对象的更改。

邬宜然
2023-03-14

显式地从对象管理器获得持久性管理器解决了这个问题。尽管在类的头部已经存在持久性管理器注入。

解决方案的线索来自Arek van Schaijk在findAll发表的关于extbase中非对象的评论,该评论说“这里唯一可能发生的事情是,injectProductRepository()没有很好地注入您的存储库(对象)。”下一条评论说,“所以基本上所有注入都被缓存,没有检查是否有新注入。”显然,在某些情况下Extbase注入机制不起作用。

以下是有效的功能代码:

/**
 * action commission
 *
 * @param \MyNameSpace\Myextension\Domain\Model\Person $person
 * @param \MyNameSpace\Myextension\Domain\Model\Role $role
 * @param \DateTime $startTime
 * @param \DateTime $stopTime
 * @return void
 */
public function commissionAction(\MyNameSpace\Myextension\Domain\Model\Person $person,
                                 \MyNameSpace\Myextension\Domain\Model\Role $role,
                                 $startTime, $stopTime) {
    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
    $newHasRole = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Model\\HasRole');
    $newHasRole->setStartTime($startTime);
    $newHasRole->setStopTime($stopTime);
    $newHasRole->addPerson($person);
    $newHasRole->addRole($role);
    $this->hasRoleRepository = $objectManager->get('MyNameSpace\\Myextension\\Domain\\Repository\\HasRoleRepository');
    $this->hasRoleRepository->add($newHasRole);
    $this->persistenceManager = $objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
    $this->persistenceManager->persistAll();
}
 类似资料:
  • 问题内容: 我正在将一个对象传递给我的控制器,如下所示: 我的控制器将其视为它正在寻找的对象: 我的问题是我只想再传递一个字符串。我知道我可以制作特定于视图的模型,但我想知道是否可以执行以下操作: 我没有运气就尝试了以下方法: 但是复杂对象只是作为null来的。有没有办法我也可以传递对象和字符串? 问题答案: 尝试将字符串项添加到已有的JSON中。不要对其进行字符串化,否则它将发送一个大字符串,您

  • 问题内容: 我打算学习来自许多不同的MV *框架的AngularJS。我喜欢框架,但是在控制器之间传递数据时遇到了麻烦。 假设我有一个带有一些输入(input.html)的屏幕和一个控制器,比方说InputCtrl。 此视图上有一个按钮,可将您带到另一个屏幕,例如,使用控制器ApproveCtrl批准(approve.html)。 此ApproveCtrl需要来自InputCtrl的数据。在较大的

  • 问题内容: 我想单击一列并将单元格索引发送到新阶段。但是我无法将参数()传递给另一个控制器。我已经尝试了所有方法,但仍然无法正常工作。 主控制器 EditClientController 问题答案: 如果要在FXML文件中指定控制器(因此您不能使用Deepak的答案), 并且 要访问方法中的索引(因此您不能使用José的答案),则可以使用控制器工厂:

  • 我得到了异常org.hibernate.持久性对象异常:分离实体传递到持久性。从这个论坛和其他地方的许多帖子中,我知道这种情况发生在两种情况下(不考虑一对一注释等), 交易超出范围存在问题 在自动生成id的位置设置id 我在代码中没有看到这两种情况。我无法重现错误,因为我没有最初触发它的数据。在其他数据上,它运行得非常好。我提供了下面的SCCE: MyImportEJB。爪哇: 我的班级。JAVA

  • 本文向大家介绍c#进程之间对象传递方法,包括了c#进程之间对象传递方法的使用技巧和注意事项,需要的朋友参考一下 1. 起源 KV项目下载底层重构升级决定采用独立进程进行Media下载处理,以能做到模块复用之目的,因此涉及到了独立进程间的数据传递问题。 目前进程间数据传递,多用WM_COPYDATA、共享dll、内存映射、Remoting等方式。相对来说,WM_COPYDATA方式更为简便,网上更到

  • 我对沉香酒很陌生...有人能告诉如何在thymeleaf html和spring控制器之间传递值吗...请为Thymeleaf-Spring-MVC提供好的教程... @requestmapping(value=“/owners”,method=requestmethod.get)公共字符串processFindForm(Owner Owner,BindingResult result,Model