[TYPO3-dam] FE file upload to a DAM category

Andreas Schaeffer andreas at schaeffernet.de
Wed Aug 30 05:21:22 CEST 2006


R. van Twisk schrieb:
> i am trying to do the same, but I run across
> the problem of the BE user not initialized.

now we are three persons with the same problem, ...
BUT now after long hours of hard research here is a mini-HOWTO.

Greets,
Andreas




miniHOWTO indexing with dam in frontend
=======================================


1. In your Extension Class you need following libraries:


require_once(PATH_t3lib.'class.t3lib_userauth.php');
require_once(PATH_t3lib.'class.t3lib_userauthgroup.php');
require_once(PATH_t3lib.'class.t3lib_beuserauth.php');
require_once(PATH_t3lib.'class.t3lib_befunc.php');

require_once(t3lib_extMgm::extPath('dam').'lib/class.tx_dam.php');
require_once(t3lib_extMgm::extPath('dam').'lib/class.tx_dam_db.php');



2. A function is needed to simulate a backend user



function simulate_backend_user($uid) {
	global $BE_USER;

	// BACKEND USER SIMULIEREN
	unset($BE_USER);
	$BE_USER = t3lib_div::makeInstance('t3lib_beUserAuth');
	$BE_USER->OS = TYPO3_OS;
	$BE_USER->setBeUserByUid($uid);
	$BE_USER->fetchGroupData();
	$BE_USER->backendSetUC();

	$GLOBALS['BE_USER'] = $BE_USER;
}



3. Optionally you can use something like this to unset the backend user



function kill_backend_user() {
	global $BE_USER;

	// BACKEND USER KILLEN
	unset($BE_USER);
}



4. Now you need a function which indexes the file by a given filename. 
Note, that you have to use a valid backend-user-id (not 4895837!)


function index_by_filename($filename) {

	// BE_USER SIMULIEREN
	$this->simulate_backend_user(4895837);

	// METADATEN HOLEN
	$index = t3lib_div::makeInstance('tx_dam');
	$meta = $index->index_autoProcess($filename);

	// DATENSATZ IN DIE DATENBANK SCHREIBEN
	$damdb = t3lib_div::makeInstance('tx_dam_db');
	$uid = $damdb->insertRecordRaw($meta[fields]);


	// BE_USER WIEDER KILLEN
	$this->kill_backend_user();

}



5. Thats it. Works for me :-)



More information about the TYPO3-project-dam mailing list