0
votes

I'm doing a query on a really simple table in a typo 3 task. However, only the fields "uid" and "pid" are returned, the other fields are NULL.

My Entity:

<?php
namespace Name\SampleExtension\Domain\Model;

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

class MailAgent extends AbstractEntity
{

    /**
     * @var integer
     */
    protected $uid;

    /**
     * @var string
     */
    protected $customeremail;

    /**
     * @var string
     */
    protected $searchparameters;

    /**
     * @var string
     */
    protected $resultlist;


    public function getUid()
    {
        return $this->uid;
    }

    public function setCustomerEmail($customeremail)
    {
        $this->customeremail = $customeremail;
    }
    public function getCustomerEmail()
    {
        return $this->customeremail;
    }

    public function setSearchParameters($searchparameters)
    {
        $this->searchparameters = $searchparameters;
    }
    public function getSearchParameters()
    {
        return $this->searchparameters;
    }

    public function setResultList($resultlist)
    {
        $this->resultlist = $resultlist;
    }
    public function getResultList()
    {
        return $this->resultlist;
    }
}

?>

The Repository:

<?php

namespace Name\SampleExtension\Domain\Repository;

use TYPO3\CMS\Extbase\Persistence\Repository;

class MailAgentRepository extends Repository
{

    public function findByUids($uids)
    {
        $query = $this->createQuery();
        foreach ($uids as $uid) {
            $constraints[] =  $query->equals('uid', $uid);
        }

        return $query->matching(
            $query->logicalOr(
                $constraints
            )
        )->execute();
    }
}

?>

And the query inside the task:

<?php

namespace Name\SampleExtension\Task;

use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use Name\SampleExtension\Domain\Model\MailAgent;
use Name\SampleExtension\Domain\Repository\MailAgentRepository;

class MailAgentCheckup extends AbstractTask
{
    public function execute() {

        $objectManager              = GeneralUtility::makeInstance(ObjectManager::class);
        $this->MailAgentRepository = $objectManager->get(MailAgentRepository::class);
        $query = $this->MailAgentRepository->createQuery();

        $allCustomers = $this->MailAgentRepository->findAll();

        foreach ($allCustomers as $customer) {
            var_dump($customer);
        }

        return true;
    }
}

?>

I have no idea why the other fields are not returned, but the uid and the pid are. My guess is that I need to declare the mapping somewhere else.

EDIT: Heres the content of my TCA, which is probably wrong or not enough, but since I'm working on a existing extension I was copying from the TCA's of the tables that work.

tx_sampleextension_domain_model_mailagent.php

return [
    'columns' => [
        'uid' => [],
        'customer_email' => [],
        'search_parameters' => [],
        'result_list' => [],
    ],
    'types' => [],
];

This is from another table for which querys etc work

return [
    'columns' => [
        'immovable' => [],
        'type' => [],
        'title' => [],
        'path' => [],
        'mark_to_delete' => [],
    ],
];
1
How does your file Configuration/TCA/MailAgent.php look like?Jay Dinse
Also, it is advisable to define the task using a CommandController, which gives you a fully initialized extbase environment. It can still be executed using the scheduler, and it's much easier to implement.Jost
How did you create these fields? Do the columns exist and are they configured accordingly in table? Next, as Jay said, check your TCA for these fields. And most importantly, completely flush your cache or delete the cached TCA manually.j4k3
Thanks for the responses. I'm working on an existing extension and added the table manually using phpmyadmin. The weird part is that the existing extension has two other tables for which I cant find any mapping information, but querys to those work. I will edit my question and add the tca content.Stuffy

1 Answers

0
votes

Give a try to inject your repository

<?php

namespace Name\SampleExtension\Task;

use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use Name\SampleExtension\Domain\Model\MailAgent;
use Name\SampleExtension\Domain\Repository\MailAgentRepository;

use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

class MailAgentCheckup extends AbstractTask
{
    /**
     * mailAgentRepository
     *
     * @var \Name\SampleExtension\Domain\Repository\MailAgentRepository
     * @inject
     */
    protected $mailAgentRepository = NULL;

    public function injectMailAgentRepository(\Name\SampleExtension\Domain\Repository\MailAgentRepository $mailAgentRepository) {
        $this->mailAgentRepository = $mailAgentRepository;
    }

    public function execute() {

        $allCustomers = $this->mailAgentRepository->findAll();
        DebuggerUtility::var_dump($allCustomers);exit;

        // OR

        $arguments = $this->request->getArguments();

        $uid = $arguments['uid'];
        $singleCustomer = $this->mailAgentRepository->findByUid(intval($uid));
        DebuggerUtility::var_dump($singleCustomer);exit;

        /*foreach ($allCustomers as $customer) {
            var_dump($customer);
        }*/

        return true;
    }
}

?>