简体   繁体   中英

typo3 ignores storagePid

I try to build an importer with a scheduler task.

The task creates an object manager which creates my import service. This import service has dependencies to the repository.

I simply create instances and add them to the repository.

It works well until i tried to specify on which pid my records are supposed to be saved. I tried to configure it in setup.txt.

plugin.tx_extkey {
    view {
        templateRootPath = {$plugin.tx_extkey.view.templateRootPath}
        partialRootPath = {$plugin.tx_extkey.view.partialRootPath}
        layoutRootPath = {$plugin.tx_extkey.view.layoutRootPath}
    }
    persistence {
        storagePid = {$plugin.tx_extkey.persistence.storagePid}
        classes {
            EXTNAME\EXTNAME\Domain\Model\MODELNAME {
                newRecordStoragePid = {$plugin.tx_extkey.persistence.storagePid}
            }
        }
    }
    features {
        # uncomment the following line to enable the new Property Mapper.
        # rewrittenPropertyMapper = 1
    }
}

module.tx_extkey {
    persistence < plugin.tx_extkey.persistence
}

But that didn't work. Everything is still saved to pid 1 .

Are there any pitfalls that I might have overlooked?

I found an ugly way. The BackendConfigurationManager does not get the extensionName when the service is executed though the scheduler. Manually setting it in the task resolves this.

$objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');

/** @var BackendConfigurationManager $configurationManager */
$configurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager');
$configurationManager->setConfiguration(array(
    'extensionName' => 'hnsenvionjob'
));

I use an ImportCommandController as recommended by lorenz in In an extbase extension, how to access the persistence layer from a scheduler task? (my actual code has changed in the meantime, let me know if you want it)

and I have to set the pid manually:

$item->setPid($storagePid);

There is an easy trick for that

add in your ts something like that

plugin.tx_extkey.settings.storagePid = {$plugin.tx_extkey.persistence.storagePid}

That will allow you to have access to your storage pid everywhere in your code where you have access to your ts. For example in controller

$this->settings['storagePid']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM