[TYPO3-dam] Manually indexing files from own extension without BE-user
Franz Koch
typo at fx-graefix.de
Wed Sep 20 18:19:55 CEST 2006
>> I'm currently writing an extension like dam_downloads, but with
>> upload functionality. For this, I want to use the indexing features
>> of DAM. So I tried uploading a file into the fileadmin-folder and
>> then index this file via DAM with the following code:
>> ...
>> But when I'm not logged into the backend, I always get the error
>> in the log
>>
>> "Attempt to modify table 'tx_dam' without permission"
I just managed it with a little workaround. I'm using the "dryrun" option and the function "indexFile" to get the meta-data for the file and insert the data manually into the database like that:
------
// initiate DAM indexing-object
if(!is_object($this->damIndexing)) {
$this->damIndexing = t3lib_div::makeInstance('tx_dam_indexing');
}
$this->damIndexing->init();
$this->damIndexing->setDefaultSetup();
$this->damIndexing->initEnabledRules();
$this->damIndexing->setPid(0);
$this->damIndexing->setRunType("man");
$this->damIndexing->setDryRun(true);
$this->damIndexing->collectMeta = true;
// define some data that should override any dam-generated indexing-data
$overrideData = array(
"fields" => array(
"category" => count(explode(",",$this->piVars["entry_category"])),
"description" => $this->piVars["entry_description"],
"fe_user" => $this->user_uid,
"creator" => $GLOBALS['TSFE']->fe_user->user["name"],
"copyright" => $GLOBALS['TSFE']->fe_user->user["name"],
"cruser_id" => 1,
),
);
// get the meta-data and all other fields of the dam-table
$data = $this->damIndexing->indexFile($fileconf['uploadFolder']."/".$this->piVars[$shortcut],0, NULL, NULL, NULL, $overrideData);
// if we got meta-data, let's proceed and insert the data into the database
if(is_array($data)) {
$pid = $this->damIndexing->pid;
unset($data["fields"]["uid"],$data["fields"]["pid"]);
$values = array();
// stripping of fields that not supposed to be inserted
// fieldlist is set in typoscript of extension
foreach($data["fields"] as $dbfield => $value) {
if(t3lib_div::inList($this->conf['db_insertFields'],$dbfield)) {
$values[$dbfield] = $value;
}
}
$fields = implode(",",array_keys($values));
$query = $this->cObj->DBgetInsert($this->entryTable,$pid,$values,$fields,true);
// and now update the category-mm-table. Don't know a better way right now
if($query) {
$this->entry_uid = $GLOBALS['TYPO3_DB']->sql_insert_id();
if($this->entry_uid) {
$proceed = true;
foreach(explode(",",$this->piVars["entry_category"]) as $catid) {
$mmdata = array(
'uid_local' => $this->entry_uid,
'uid_foreign' => $catid,
'sorting' => ++$i,
);
if(!$GLOBALS['TYPO3_DB']->exec_INSERTquery("tx_dam_mm_cat",$mmdata)) {
$proceed = false;
}
}
}
if($proceed) {
# do some stuff
}else{
return $this->display_error();
}
}
}
------
Maybe that helps anybody. It seems to be sufficient for my current needs, but any improvements are very welcome :)
--
Kind regards,
Franz Koch
More information about the TYPO3-project-dam
mailing list