AOEpeople / TYPO3_Restler

restler (PHP REST-Framework) for TYPO3
GNU General Public License v3.0
30 stars 17 forks source link

v9 Create and Delete extbase Objects #42

Closed develth closed 3 years ago

develth commented 5 years ago

Hello!

I made some endpoints to my extbase extension. Creating Objects work - but no deletion. After checking the pid of the objects (that i created via the API), they are all set to 0. In the restler_examples Extension the 'old' (non v9) configuration is given and that sets a specific pageUid in the Controller (that creates or deletes). This way does not seems to exist anymore. How is it done now via the middleware? Should that be done by that feature?

Current Code for create and delete (removed the null / duplicate checks for better readability):

Create:

/**
   * Creates a EventFavorite for given Client
   *
   * @url POST /event/{eventUid}/{clientIdentifier}
   * @status 201
   *
   * @param integer $eventUid ID of the event to favorite
   * @param string $clientIdentifier ID of the client that owns the favorite
   *
   * @return void
*/
public function createFavorite($eventUid, $clientIdentifier): void
{
    $client = $this->clientRepository->findByClientIdentifier($clientIdentifier);
    $event = $this->eventRepository->findByIdentifier($eventUid);

    $favorite = new EventFavorite();
    $favorite->setEvent($event);
    $favorite->setClient($client);

    $this->eventFavoriteRepository->add($favorite);
    $this->persistenceManager->persistAll();
}

Delete:

/**
   * Removes a EventFavorite for given Client
   *
   * @url DELETE /event/{eventUid}/{clientIdentifier}
   *
   * @param integer $eventUid ID of the event to unfavorite
   * @param string $clientIdentifier ID of the client that owns the favorite
   *
   * @return void
*/
public function removeFavorite($eventUid, $clientIdentifier): void
{
    $client = $this->clientRepository->findByClientIdentifier($clientIdentifier);
    $this->eventFavoriteRepository->remove($favorite);
}

I already debugged the remove function of the Repository - the addedObjects is empty.

Thanks & Best Thomas

sven-carstens commented 4 years ago

There seems to be a problem with dtermining the default storagePid correctly. Could you check which typoscript configuration is loaded for your extension?

For testing you can put \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($GLOBALS['TSFE']->tmpl->setup['config.']);die; at about line 88 of \Aoe\Restler\System\Dispatcher.php and then call the desired api endpoint.

Please be aware that you are not inside of an extbase plugin context during restler operation and as such the settings from plugin.tx_PLUGIN.persistence do not apply.

You can see the applied settings inside of your repository after creating a query object. DebuggerUtility::var_dump($query->getQuerySettings()->getStoragePageIds());die;

develth commented 4 years ago

Thanks for your feedback @sven-carstens

What do you mean with Could you check which typoscript configuration is loaded for your extension? exactly? When doing the dump in the Dispatcher, i found nothing about the regarding extension

You can see the applied settings inside of your repository after creating a query object. DebuggerUtility::var_dump($query->getQuerySettings()->getStoragePageIds());die;

It is 0

Thanks!

develth commented 4 years ago

I tried to set the $defaultQuerySettings->setStoragePageIds(array($pid));, but it was ignored by the create process.

After debugging the Code, i found a check for config.tx_extbase.persistence.classes.CLASS.newRecordStoragePid

When i set this, it worked!

sven-carstens commented 4 years ago

We for sure need more documentation with all special cases for Typo3 V9 and up.