0

I'm trying to add new filemounts for newly created user. Is it possible to use the Datahandler from Typo3? I tried the following but, it doesn't work:

$file_data['sys_filemounts']['NEW'] = array(
    'base' => 2,
    'description' => '',
    'hidden' => 0,
    'read_only' => 0,
    'title' => strtolower($userName[0]."-".$userName[1]),
    'path' => '/user_upload/MPL-People/'.strtolower($userName[0]."-".$userName[1].'/'),
    'tx_gdemployeeimport_adid' => $adid
);
$this->createDir($userName);

$this->datahandler->start($file_data,array());

$this->datahandler->process_datamap();
$this->datahandler->clear_cacheCmd('all');
Blue
  • 22,608
  • 7
  • 62
  • 92
hrdyy
  • 1
  • in the creation of $file_data you use `$userName[0]."-".$userName[1]`, then you use `$userName` as a string: `createDir($userName)`. one of them will break. be sure to have clean data for the records. – Bernd Wilke πφ Jan 16 '18 at 13:51
  • UserName ist a explode Function $userName = explode(" ", $json['cn']); the CreateDir function only create the dir. Cause these needs to be done before create a filemount.. – hrdyy Jan 16 '18 at 13:54
  • have you checked what is executed? is the folder created? is the record created? are the values ok? ... – Bernd Wilke πφ Jan 16 '18 at 13:59
  • Yes, ich checked the datamap form the datahandler, the folder is there and the values are ok.. the only thing is that the filemount is not created. – hrdyy Jan 16 '18 at 14:22
  • I think there was a problem using the Datahandler if you are not logged in to the backend. – Paul Beck Jan 16 '18 at 18:39
  • Im using the Datahandler for creating a BE & FE User... this works perfect.. but with the Filemount... i have no idea why not.. Now i use the Repo & Model to create a new Filemount. – hrdyy Jan 17 '18 at 07:50

2 Answers2

0
    $userName = explode(" ", $json['cn']);
    $formatedName = strtolower($userName[0]."-".$userName[1]);
    $extbaseObjectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
    $newfileMountModel = $extbaseObjectManager->get('Graphodata\Gdemployeeimport\Domain\Model\GdFileMount');
    $fileMountRepository = $extbaseObjectManager->get('Graphodata\Gdemployeeimport\Domain\Repository\GdFileMountRepository');

    $newfileMountModel->setBase(2);
    $newfileMountModel->setPid(0);
    $newfileMountModel->setDescription('');
    $newfileMountModel->setPath('/user_upload/MPL-People/'.$formatedName.'/');
    $newfileMountModel->setReadOnly(0);
    $newfileMountModel->setTitle($formatedName);
    $newfileMountModel->setTitle($formatedName);
    $newfileMountModel->setTxGdemployeeimportAdid($adid);

    $fileMountRepository->add($newfileMountModel);
    unset($newfileMountModel);

This works... Anyway thanks :)

hrdyy
  • 1
0

You have provide set the pid when creating a new record with the DataHandler.

In your case, setting the pid to 0 (like you are doing in your Repo example) should work:

$file_data['sys_filemounts']['NEW'] = array(
    'pid' => 0,
    'base' => 2,
    'description' => '',
    'hidden' => 0,
    'read_only' => 0,
    'title' => strtolower($userName[0]."-".$userName[1]),
    'path' => '/user_upload/MPL-People/'.strtolower($userName[0]."-".$userName[1].'/'),
    'tx_gdemployeeimport_adid' => $adid
);
daiwai
  • 71
  • 3