[TYPO3-mvc] Stored Domain Model within Scheduler Task is always empty
Alfred Bez
alfred.bez at googlemail.com
Thu Jun 25 14:31:45 CEST 2015
Hi folks,
I'm currently developing an Extbase Extension which should have a scheduler task. This scheduler task should store a domain model. A new row in the database is generated, but it's always empty (except uid and pid = 1).
Here's some code:
ext_tables.sql
############### start ##############
CREATE TABLE tx_myext_domain_model_simple (
uid int(11) unsigned DEFAULT '0' NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL,
titel varchar(255) DEFAULT '' NOT NULL,
PRIMARY KEY (uid),
KEY parent (pid),
);
############### end ###############
Classes/Domain/Model/Simple.php
############### start ##############
<?php
namespace Vendor\Myext\Domain\Model;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
class Simple extends AbstractEntity {
/**
* Titel
* @var string
*/
protected $titel = '';
public function __construct() {
}
public function setTitel($titel) {
$this->titel = $titel;
}
public function getTitel() {
return $this->titel;
}
}
############### end ###############
Classes/Domain/Repository/SimpleRepository.php
############### start ##############
<?php
namespace Vendor\Myext\Domain\Repository;
use TYPO3\CMS\Extbase\Persistence\Repository;
class SimpleRepository extends Repository {
}
############### end ###############
Classes/Task/LoadXml.php
############### start ##############
<?php
namespace Vendor\Myext\Task;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use Vendor\Myext\Domain\Model\Simple;
use Vendor\Myext\Domain\Repository\SimpleRepository;
class LoadXml extends AbstractTask {
public function execute() {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$persistenceManager = $objectManager->get(PersistenceManager::class);
$simpleRepository= $objectManager->get(SimpleRepository::class);
$simple = new Simple;
$simple->setTitel('Titel');
$simpleRepository->add($simple);
$persistenceManager->persistAll();
// send notification mail
return true;
}
}
############### end ###############
A very basic mail is sent after the Model is stored.
What Am I Doing Wrong?
More information about the TYPO3-project-typo3v4mvc
mailing list