/** * tx_dam::index_process() */ public function test_index_process() { $this->removeIndexSetup(); $this->removeFixturesFromIndex(); $this->addFixturePathToFilemount(); $filepath = $this->getFixtureFilename('iptc'); $uid = tx_dam::file_isIndexed($filepath); self::assertFalse($uid, 'File index found, but shouldn\'t'); $indexed = tx_dam::index_process($filepath); $indexed = current($indexed); self::assertTrue(isset($indexed['uid']), 'File not indexed'); $meta = tx_dam::meta_getDataByUid($indexed['uid'], '*'); $date = date('d.m.Y', $meta['date_cr']); self::assertEquals($date, '04.07.2006', 'Wrong date: ' . $date); self::assertEquals($meta['title'], 'Hummelflug', 'Wrong title: ' . $meta['title']); self::assertEquals($meta['file_hash'], '184e454250f6f606a1dba14b5c7b38c5', 'Wrong file_hash: ' . $meta['file_hash']); self::assertEquals(intval($meta['media_type']), TXDAM_mtype_image, 'Wrong media_type: ' . $meta['media_type']); self::assertEquals($meta['file_type'], 'jpg', 'Wrong file_type: ' . $meta['file_type']); self::assertEquals($meta['file_mime_type'], 'image', 'Wrong file_mime_type: ' . $meta['file_mime_type']); self::assertEquals($meta['file_mime_subtype'], 'jpeg', 'Wrong file_mime_subtype: ' . $meta['file_mime_subtype']); self::assertTrue((bool) $meta['hpixels'], 'Missing value'); self::assertTrue((bool) $meta['vpixels'], 'Missing value'); self::assertTrue((bool) $meta['hres'], 'Missing value'); self::assertTrue((bool) $meta['vres'], 'Missing value'); self::assertTrue((bool) $meta['width'], 'Missing value'); self::assertTrue((bool) $meta['height'], 'Missing value'); self::assertTrue((bool) $meta['height_unit'], 'Missing value'); $this->removeFixturePathFromFilemount(); $this->removeFixturesFromIndex(); }
/** * Replace a file with an uploaded file and process indexing and DB update * Important: $meta['uid'] have to be used in the upload data like this $upload_data['upload'][$meta['uid']] * * @param array $meta Meta data array * @param array $upload_data Form upload data for $TCEfile->setCmdmap($upload_data) * @return mixed error message or error array * @see tx_dam_tce_file::getLastError() */ function process_replaceFile($meta, $upload_data, $getFullErrorLogEntry = FALSE) { global $TYPO3_CONF_VARS; $error = false; require_once PATH_txdam . 'lib/class.tx_dam_tce_file.php'; $TCEfile = t3lib_div::makeInstance('tx_dam_tce_file'); $TCEfile->init(); // allow overwrite $TCEfile->fileProcessor->dontCheckForUnique = true; // FIXME overwrite only original file not others // dontCheckForUnique=true allow overwriting any file // dontCheckForUnique have to be false and the file have to be replaced afterwards? if ($id = $meta['uid'] and is_array($upload_data['upload'][$id])) { // Processing uploads $TCEfile->setCmdmap($upload_data); $log = $TCEfile->process(); if ($TCEfile->errors()) { $error = $TCEfile->getLastError(); } else { $newFile = $log['cmd']['upload'][$id]['target_file']; $newFile = tx_dam::file_absolutePath($newFile); $new_filename = tx_dam::file_basename($newFile); // new file name - so we need to update some stuff if ($new_filename !== $meta['file_name']) { // rename meta data fields $fields_values = array(); $fields_values['file_name'] = $new_filename; $fields_values['file_dl_name'] = $new_filename; $fields_values['uid'] = $meta['uid']; tx_dam_db::insertUpdateData($fields_values); // delete the old file $oldFile = tx_dam::file_absolutePath($meta); @unlink($oldFile); if (@is_file($oldFile)) { $error = 'File ' . $meta['file_name'] . ' could not be deleted.'; if ($getFullErrorLogEntry) { $error = array('msg' => $error); } } } // reindex the file $setup = array('recursive' => false, 'doReindexing' => tx_dam::config_checkValueEnabled('setup.indexing.replaceFile.reindexingMode', 2)); tx_dam::index_process($newFile, $setup); } } else { $error = true; } if (!$error) { $info = array('uid' => $meta['uid'], 'new_file' => $newFile, 'old_file' => $oldFile); tx_dam::_callProcessPostTrigger('replaceFile', $info); } return $error; }
/** * Indiziert eine Datei mit DAM. * * ACHTUNG: wenn die Feld Collation der DB-Felder file_name und file_path * in der tx_dam Tabelle auf *_ci (utf8_general_ci) stehen, * wird bei der Prüfung Gruß-/Kleinschreibung ignoriert, * was bei unix-Systemen zu Fehlern führt! * Die einfache Lösung ist, die Collation der beiden Felder * auf *_bin (utf8_bin) zu setzen! * * @param string $file * @param int $beUserId * @return uid */ public static function indexProcess($file, $beUserId) { if (!tx_rnbase_util_Extensions::isLoaded('dam')) { return 0; } require_once tx_rnbase_util_Extensions::extPath('dam', 'lib/class.tx_dam.php'); $mediaUid = tx_dam::file_isIndexed($file); if (!$mediaUid) { // process file indexing self::initBE4DAM($beUserId); $damData = tx_dam::index_process($file); $mediaUid = $damData[0]['uid']; } return $mediaUid; }
/** * Indiziert eine Datei mit DAM. * * @param string $sFile * @param int $iBeUserId * @return uid */ public static function indexProcess($sFile, $iBeUserId = false) { if (!self::isLoaded()) { return 0; } if (!$iBeUserId) { tx_rnbase::load('tx_mklib_util_MiscTools'); $iBeUserId = tx_mklib_util_MiscTools::getProxyBeUserId(); } // process file indexing self::initBE4DAM($iBeUserId); $damData = tx_dam::index_process($sFile); return $damData[0]['uid']; }