/**
  * Gibt DAM Records von definierten UIDs zurück.
  *
  * @param int 			$iUid
  * @return array|null
  */
 public static function getRecords($aUid)
 {
     if (!self::isLoaded()) {
         return array('files' => array(), 'rows' => array());
     }
     if (!is_array($aUid)) {
         $aUid = array($aUid);
     }
     $aRes = tx_dam_db::getDataWhere(false, array('uid' => 'tx_dam.uid IN (' . implode(',', $aUid) . ')'));
     $aFiles = $aRows = array();
     if (count($aRes)) {
         foreach ($aRes as $aRow) {
             $aFiles[$aRow['uid']] = $aRow['file_path'] . $aRow['file_name'];
             $aRows[$aRow['uid']] = $aRow;
         }
     }
     return array('files' => $aFiles, 'rows' => $aRows);
 }
    /**
     * Do the file indexing
     * Read files from a directory index them and output a result table
     *
     * @return	string		HTML content
     */
    function checkIndex($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) {
            $rows = tx_dam_db::getDataWhere('COUNT(uid) as count', $where);
            reset($rows);
            $row = current($rows);
            $countTotal = $row['count'];
            $indexSession = $this->indexSessionNew($countTotal);
        }
        $files_at_a_time = 200;
        $rows = tx_dam_db::getDataWhere('', $where, '', '', intval($indexSession['currentCount']) . ',' . $files_at_a_time);
        if ($rows) {
            $c = 0;
            foreach ($rows as $meta) {
                $c++;
                // increase progress bar
                $indexSession['currentCount']++;
                if (is_array($meta)) {
                    $status = tx_dam::meta_updateStatus($meta, $this->pObj->MOD_SETTINGS['tx_dam_tools_indexupdate.deleteMissing']);
                    $ctable = array();
                    switch ($status) {
                        case TXDAM_status_file_changed:
                            $ctable[] = $this->infoIcon(2);
                            break;
                        case TXDAM_status_file_missing:
                            $ctable[] = $this->infoIcon(3);
                            break;
                        default:
                            $ctable[] = $this->infoIcon(-1);
                            break;
                    }
                    $ctable[] = tx_dam::icon_getFileTypeImgTag($meta, 'align="top"') . '&nbsp;' . htmlspecialchars(t3lib_div::fixed_lgd_cs($meta['file_name'], 30));
                    $ctable[] = htmlspecialchars(t3lib_div::fixed_lgd_cs($meta['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() or $c == $files_at_a_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();
    }
 /**
  * Finds all the DAM-records within a specific path.
  *
  * @var string $path The file path.
  * @var string $orderBy Any ordering that should be applied.
  * @var int $limit The maximum amount of objects to return.
  * @var string $additionalWhere Query string you can append to the default WHERE statement, which matches the path.
  * @return array Array of Dam objects.
  */
 public static function getByPath($path, $orderBy = '', $limit = 1000, $additionalWhere = '')
 {
     // check if this exact function call has been made before and give the cached result
     if (isset(self::$objectStorage['path'][$path][$orderBy][$limit])) {
         return self::$objectStorage['path'][$path][$orderBy][$limit];
     }
     // removes the absolute path and adds a trailing '/' if there is none
     $path = preg_replace('/' . str_replace('/', '\\/', PATH_site) . '/', '', $path);
     if (!$path) {
         return array();
         // If the path is destroyed by the preg_replace call, don't return all records globally
     }
     $rows = \tx_dam_db::getDataWhere('*', 'file_path LIKE \'' . $path . '%\'' . $additionalWhere, '', $orderBy, $limit);
     if (count($rows) > 0) {
         // dataMapper is a singleton
         $dataMapper = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper');
         $objects = $dataMapper->map('CIC\\Cicbase\\Domain\\Model\\DigitalAsset', $rows);
         // cache the function call
         self::$objectStorage['path'][$path][$orderBy][$limit] = $objects;
         return $objects;
     }
     self::$objectStorage['path'][$path][$orderBy][$limit] = array();
     // no records found
     return array();
 }
예제 #4
0
 /**
  * Do a check if a file is already indexed and have an entry in the DAM table
  * This function return a status value and the meta data array, while file_isIndexed() just returns the uid.
  *
  * @param	mixed		$fileInfo Is a file path or an array containing a file info from tx_dam::file_compileInfo().
  * @param	string		$hash The hash value will be used to identify the file if the file name was not found. That can happen if the file was renamed or moved without index update.
  * @return	array		status: array('__status' => TXDAM_file_notfound,'meta' => array(...));
  * @see file_isIndexed()
  */
 function index_check($fileInfo, $hash = '')
 {
     $status = array('__status' => TXDAM_file_unknown, 'meta' => array());
     if (!is_array($fileInfo)) {
         $fileInfo = tx_dam::file_compileInfo($fileInfo, true);
     }
     if (!$hash) {
         $hash = $fileInfo['file_hash'];
     }
     // FIXME $hash is not used - what is the concept?
     if ($fileInfo) {
         $where = array();
         $where['file_name'] = 'file_name=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_name'], 'tx_dam');
         $where['file_path'] = 'file_path=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($fileInfo['file_path'], 'tx_dam');
         if ($rows = tx_dam_db::getDataWhere('', $where, '', '', '1')) {
             reset($rows);
             $row = current($rows);
             $status['meta'] = $row;
             if (!$fileInfo['__exists']) {
                 $status['__status'] = TXDAM_file_missing;
             } elseif ($row['file_mtime'] == $fileInfo['file_mtime']) {
                 $status['__status'] = TXDAM_file_ok;
             } else {
                 $status['__status'] = TXDAM_file_changed;
             }
         }
     }
     return $status;
 }
예제 #5
0
 /**
  * Set all records deleted that matches/begins with the given path.
  *
  * @param	string		$path path
  * @return	void
  */
 function updateFilePathSetDeleted($path)
 {
     $path = tx_dam::path_makeRelative($path);
     // this way db trigger will not work
     // $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'tx_dam.file_path LIKE BINARY '.$GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['TYPO3_DB']->escapeStrForLike($path, 'tx_dam').'%', 'tx_dam'), array('deleted'=>'1'));
     $where = array();
     $where['enableFields'] = '';
     $where['pidList'] = '';
     $likeStr = $GLOBALS['TYPO3_DB']->escapeStrForLike($path, 'tx_dam');
     $where['file_path'] = 'tx_dam.file_path LIKE BINARY ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($likeStr . '%', 'tx_dam');
     $rows = tx_dam_db::getDataWhere('tx_dam.uid', $where);
     foreach ($rows as $row) {
         $row['deleted'] = '1';
         tx_dam_db::insertUpdateData($row);
     }
 }