[TYPO3-dam-devel] How to use DAM in an own extension

Lorenz Ulrich lorenz-typo3 at visol.ch
Thu Apr 12 23:41:50 CEST 2012


Hi Tim

If you read the dam_frontend code you will see that the DAM indexer is 
only used to gather the metadata, not to store it. See this line:

$indexer->setDryRun(true); // just getting metadata from the dock

DAM uses TCEmain to add new records and TCEmain needs a backend user 
which has rights to write to tx_dam and its fields. So just creating a 
backend object in frontend context doesn't mean that a backend user is 
actually authenticated.

The addDocument method in dam_frontend is the most simple way to achieve 
what you want... get the metadata from the indexer, but write it with 
t3lib_db ($GLOBALS['TYPO3_DB']).

I'm not familiar with t3lib_userAuth and its children so I can't help 
you in finding another way since I don't have the time to dig into it.

Best regards,

Lorenz


Am 12.04.2012 16:27, schrieb t.werdin:
> Dear developer Team,
>
>
>
> I'm building an extbase extension. The FE-User should be able to upload images.
>
> I move the images to the uploads/my_extension/ folder which is no problem.
>
> Then I want to index the file with dam so I can save the uid of the dam record
> in my model and save it to my table.
>
>
>
> I try to index the file with:
>
> $data = tx_dam::index_process($filename, array('doReindexing' =>  99));
>
>
>
> When I'm logged in as a BE-User this is no problem. But when I'm not logged in
> in BE (such as a normal visitor and logged in FE-User) I get an fatal error.
>
> This is because no BE_USER object is there. After reading through dam_frontend I
> inserted:
>
> if(empty($GLOBALS['BE_USER'])) {
>
>      $GLOBALS['BE_USER'] = t3lib_div::makeInstance('t3lib_tsfeBeUserAuth');
>
>      $GLOBALS['BE_USER']->start();
>
> }
>
>
>
> This helps to avoid the fatal error but the indexing is not working I get back
> an empty array.
>
>
>
> So I coppied another few code lines from dam_frontend:
>
> $indexer = t3lib_div::makeInstance('tx_dam_indexing');
>
> $indexer->init();
>
> $indexer->setDefaultSetup();
>
> $indexer->restoreSerializedSetup(array('doReindexing' =>  99));
>
> $indexer->initEnabledRules();
>
> $indexer->collectMeta = true;
>
> //$indexer->setDryRun(true);
>
> $indexer->setPid(tx_dam_db::getPid());
>
> $indexer->setRunType('man');
>
> $data = $indexer->indexFile($filename);
>
>
>
> This is similar to what index_process does.
>
> But now I get an array which contains an failure message:
>
> "Meta record could not be inserted: Attempt to modify table 'tx_dam' without
> permission".
>
>
>
> I'm working on this for over a weak now and our customer is waiting for his
> extension.
>
> Could you please tell me what is necessary to add a file to the index with dam?
>
> Am I missing some parameters? What function do I have to user when a logged in
> FE-User should be able to upload and index a file?
>
>
>
> Please give me all mandatory settings etc so I can index a already uploaded file
> and get back the uid.
>
>
>
> Kind regards
>
> Tim Werdin
>
> --
> web-vision GmbH
> schlossstr. 527                41238 mönchengladbach
> fon: +49 [0] 2166 . 94 04 54   fax: +49 [0] 2166 . 94 03 70
>
> web design | content management | secure hosting



More information about the TYPO3-team-dam mailing list