/** * tx_dam::index_check() */ public function test_index_check() { $this->removeFixturesFromIndex(); $this->addFixturePathToFilemount(); $filepath = $this->getFixtureFilename('iptc'); $hash = tx_dam::file_calcHash($filepath); $status = tx_dam::index_check($filepath); self::assertEquals($status['__status'], TXDAM_file_unknown, 'File: ' . $filepath); $status = tx_dam::index_check($filepath, $hash); self::assertEquals($status['__status'], TXDAM_file_unknown, 'File: ' . $filepath); $status = tx_dam::index_check('', $hash); self::assertEquals($status['__status'], TXDAM_file_unknown, 'File: ' . $filepath); // todo: check index_check for indexed file $this->removeFixturePathFromFilemount(); }
/** * Do the file indexing * Read files from a directory index them and output a result table * * @return string HTML content */ function checkUploads($indexSessionID) { global $LANG, $TYPO3_CONF_VARS; // makes sense? Was a hint on php.net ob_end_flush(); // get session data - which might have left files stored $indexSession = $this->indexSessionFetch(); $where = array(); if ($age = intval($this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.age'])) { $where['tstamp'] = 'tstamp<' . (time() - $age); } if ($indexSessionID == '' or !isset($indexSession['ID']) or !($indexSession['ID'] == $indexSessionID) or $indexSession['currentCount'] == 0) { $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_file_tracking', ''); $files = array(); $files = $this->getFilesInDir(PATH_site . 'uploads/', true, $files); $countTotal = count($files); $indexSession = $this->indexSessionNew($countTotal, $files); } if (is_array($indexSession['data'])) { $damIndexing = t3lib_div::makeInstance('tx_dam_indexing'); $damIndexing->init(); $damIndexing->dryRun = TRUE; foreach ($indexSession['data'] as $key => $file) { // increase progress bar $indexSession['currentCount']++; $fileHash = tx_dam::file_calcHash($file); $fileInfo = tx_dam::file_compileInfo($file); $fields_values = array('tstamp' => time(), 'file_name' => $fileInfo['file_name'], 'file_path' => $fileInfo['file_path'], 'file_size' => $fileInfo['file_size'], 'file_ctime' => min($fileInfo['file_ctime'], $fileInfo['file_mtime']), 'file_hash' => $fileHash); $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_file_tracking', $fields_values); $fileInfo = array_merge($fileInfo, $damIndexing->getFileMimeType($file)); $fileInfo['media_type'] = tx_dam::convert_mediaType($fileInfo['file_mime_type']); $ctable = array(); $ctable[] = ' '; $ctable[] = tx_dam::icon_getFileTypeImgTag($fileInfo, 'align="top"') . ' ' . htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_name'], 30)); $ctable[] = htmlspecialchars(t3lib_div::fixed_lgd_cs($fileInfo['file_path'], -30)); $this->indexing_addTableRow($ctable); $msg = $LANG->getLL('tx_dam_tools_indexupdate.updatedMessage', 1); $code = sprintf($msg, $indexSession['currentCount'], $indexSession['totalFilesCount']); $this->indexing_setMessage($code); $this->indexing_progressBar($indexSession['currentCount'], $indexSession['totalFilesCount']); $this->indexing_flushNow(); $this->indexSessionWrite($indexSession); if ($this->indexEndtime < time() and $indexSession['currentCount'] < $indexSession['totalFilesCount']) { $params = $this->pObj->addParams; $params['indexSessionID'] = $indexSession['ID']; echo ' <script type="text/javascript"> window.location.href = unescape("' . t3lib_div::rawUrlEncodeJS(tx_dam_SCbase::linkThisScriptStraight($params)) . '"); </script>'; exit; } } } elseif ($indexSession['totalFilesCount'] == 0) { $code = $LANG->getLL('tx_dam_tools_indexupdate.no_files'); $this->indexing_setMessage($code); } $this->indexing_finished(); // finished - clear session $this->indexSessionClear(); }
/** * Checks if a file was changed or if it's missing and updates the status accordingly * * @param array $row Meta data record array with 'uid' field * @param boolean $markMissingDeleted If set (default) a record will be marked deleted if a file is missing * @return integer New status value eg. TXDAM_status_file_changed, TXDAM_status_file_missing */ function meta_updateStatus($meta, $markMissingDeleted = true) { $status = TXDAM_status_file_ok; if (!$meta['uid']) { return false; } $filepath = tx_dam::file_absolutePath($meta); $fileInfo = tx_dam::file_compileInfo($filepath); if ($fileInfo['__exists']) { $hash = tx_dam::file_calcHash($fileInfo); if (!($fileInfo['file_mtime'] == $meta['file_mtime']) or !($hash == $meta['file_hash'])) { $status = TXDAM_status_file_changed; tx_dam_db::updateStatus($meta['uid'], $status, $fileInfo, $hash); } } else { $status = TXDAM_status_file_missing; tx_dam_db::updateStatus($meta['uid'], $status, NULL, NULL, $markMissingDeleted ? 1 : NULL); } return $status; }
/** * tx_dam::file_calcHash() */ public function test_file_calcHash() { $filename = $this->getFixtureFilename(); $hash = array(); $hash['file_calcHash'] = tx_dam::file_calcHash($filename); $compareHash = '4e231415019b6593f0266b99b7704bc2'; if (function_exists('md5_file')) { $hash['md5_file'] = @md5_file($filename); } $cmd = t3lib_exec::getCommand('md5sum'); $output = array(); $retval = ''; exec($cmd . ' -b ' . escapeshellcmd($filename), $output, $retval); $output = explode(' ', $output[0]); $match = array(); if (preg_match('#[0-9a-f]{32}#', $output[0], $match)) { $hash['md5sum'] = $match[0]; } $file_string = t3lib_div::getUrl($filename); $hash['md5'] = md5($file_string); foreach ($hash as $key => $value) { self::assertEquals($compareHash, $value, 'Wrong hash: ' . $value . ' (' . $key . ')'); } }
/** * Add an uploads file to the tracking table of the DAM. * This is needed to make it possible to identify files copied to uploads/ * */ function trackingUploadsFile($fileInfo, $hash = '') { $fileInfo = is_array($fileInfo) ? $fileInfo : tx_dam::file_compileInfo($fileInfo); if ($fileInfo['__exists'] and t3lib_div::isFirstPartOfStr($fileInfo['file_path'], 'uploads/')) { $hash = $hash ? $hash : tx_dam::file_calcHash($fileInfo); $where = 'file_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_name'], 'tx_dam_file_tracking') . ' AND file_path=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_path'], 'tx_dam_file_tracking'); $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dam_file_tracking', $where); $fields_values = array('tstamp' => time(), 'file_name' => $fileInfo['file_name'], 'file_path' => $fileInfo['file_path'], 'file_size' => $fileInfo['file_size'], 'file_ctime' => max($fileInfo['file_ctime'], $fileInfo['file_mtime']), 'file_hash' => $hash); $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_file_tracking', $fields_values); } }
/** * get basic file meta info * * @param string $pathname absolute path to file * @param boolean $calcHash if true a hash of the file will be created * @return array file information */ function getFileNodeInfo($pathname, $calcHash = false) { $meta = false; $fileInfo = tx_dam::file_compileInfo($pathname); if (is_array($fileInfo) && $fileInfo['__exists']) { $meta = array(); if ($calcHash) { $fileInfo['file_hash'] = tx_dam::file_calcHash($fileInfo); } $meta['fields'] = $fileInfo; $meta['file'] = $fileInfo; } if ($this->writeDevLog and $meta) { t3lib_div::devLog('getFileNodeInfo()', 'tx_dam_indexing', 0, $fileInfo); } if ($this->writeDevLog and !$meta) { t3lib_div::devLog('getFileNodeInfo() failed', 'tx_dam_indexing', 1, $fileInfo); } return $meta; }
/** * Calculates a hash value from a file and updates the database. * The hash is used to identify file changes. * * @return void */ function updateHash() { if ($hash = tx_dam::file_calcHash($this->getPathAbsolute())) { $this->metaUpdated['file_hash'] = $hash; } $this->updateIndex(); }