/**
  * Renaming files or foldes (action=5)
  *
  * @param	array		$cmds['data'] is the new name. $cmds['target'] is the target (file or dir).
  * @param	string		$id: ID of the item
  * @return	string		Returns the new filename upon success
  */
 function func_rename($cmds, $id)
 {
     if (!$this->isInit) {
         return FALSE;
     }
     $theNewName = tx_dam::file_makeCleanName($cmds['data'], true);
     #		$theNewName = $this->cleanFileName($cmds['data']);
     if (empty($theNewName)) {
         return;
     }
     // main log entry
     $this->log['cmd']['rename'][$id] = array('errors' => array(), 'orig_filename' => $cmds['target'], 'target_file' => $theNewName);
     if (!$this->checkFileNameLen($theNewName)) {
         $this->writelog(5, 1, 124, 'New name "%s" was too long (max %s characters)', array($theNewName, $this->maxInputNameLen), 'rename', $id);
         return;
     }
     $theTarget = $cmds['target'];
     $type = filetype($theTarget);
     // $type MUST BE file or dir
     if (!($type == 'file' || $type == 'dir')) {
         $this->writelog(5, 2, 123, 'Target "%s" was neither a directory nor a file!', array($theTarget), 'rename', $id);
         return;
     }
     // Fetches info about path, name, extention of $theTarget
     $fileInfo = t3lib_div::split_fileref($theTarget);
     // The name should be different from the current. And the filetype must be allowed
     if ($fileInfo['file'] == $theNewName) {
         $this->writelog(5, 1, 122, 'Old and new name is the same (%s)', array($theNewName), 'rename', $id);
         return;
     }
     $theRenameName = $fileInfo['path'] . $theNewName;
     // check mountpoints
     if (!$this->checkPathAgainstMounts($fileInfo['path'])) {
         $this->writelog(5, 1, 121, 'Destination path "%s" was not within your mountpoints!', array($fileInfo['path']), 'rename', $id);
         return;
     }
     // check if dest exists
     if (@file_exists($theRenameName)) {
         $this->writelog(5, 1, 120, 'Destination "%s" existed already!', array($theRenameName), 'rename', $id);
         return;
     }
     if ($type == 'file') {
         // user have permissions for action
         if (!$this->actionPerms['renameFile']) {
             $this->writelog(5, 1, 102, 'You are not allowed to rename files!', '', 'rename', $id);
             return;
         }
         $fI = t3lib_div::split_fileref($theRenameName);
         if (!$this->checkIfAllowed($fI['fileext'], $fileInfo['path'], $fI['file'])) {
             $this->writelog(5, 1, 101, 'Fileextension "%s" was not allowed!', array($fI['fileext']), 'rename', $id);
             return;
         }
         if (!@rename($theTarget, $theRenameName)) {
             $this->writelog(5, 1, 100, 'File "%s" was not renamed! Write-permission problem in "%s"?', array($theTarget, $fileInfo['path']), 'rename', $id);
             return;
         }
         $this->writelog(5, 0, 1, 'File renamed from "%s" to "%s"', array($fileInfo['file'], $theNewName), 'rename', $id);
         // update meta data
         if ($this->processMetaUpdate) {
             tx_dam::notify_fileMoved($theTarget, $theRenameName);
         }
     } elseif ($type == 'dir') {
         // user have permissions for action
         if (!$this->actionPerms['renameFolder']) {
             $this->writelog(5, 1, 111, 'You are not allowed to rename directories!', '', 'rename', $id);
             return;
         }
         if (!@rename($theTarget, $theRenameName)) {
             $this->writelog(5, 1, 110, 'Directory "%s" was not renamed! Write-permission problem in "%s"?', array($theTarget, $fileInfo['path']), 'rename', $id);
             return;
         }
         $this->writelog(5, 0, 2, 'Directory renamed from "%s" to "%s"', array($fileInfo['file'], $theNewName), 'rename', $id);
         // update meta data
         if ($this->processMetaUpdate) {
             tx_dam::notify_fileMoved($theTarget, $theRenameName);
         }
     } else {
         return;
     }
     // add file to log entry
     $this->log['cmd']['rename'][$id]['target_' . $type] = $theRenameName;
     return $theRenameName;
 }
示例#2
0
 /**
  * Tries to find a lost index entry for a lost file and reconnect these items
  *
  * @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(...));
  */
 function index_reconnect($fileInfo, $hash = '')
 {
     if (!is_array($fileInfo)) {
         $fileInfo = tx_dam::file_compileInfo($fileInfo, true);
     }
     $status = array('__status' => TXDAM_file_unknown, 'meta' => array());
     $metaArr = tx_dam::meta_findDataForFile($fileInfo, $hash, 'uid,file_name,file_path,deleted');
     foreach ($metaArr as $meta) {
         $srcInfo = tx_dam::file_compileInfo($meta, true);
         if (!$srcInfo['__exists']) {
             if ($meta['deleted']) {
                 // setting the record undeleted right away ...
                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_dam', 'tx_dam.uid=' . $meta['uid'], array('deleted' => 0));
             }
             tx_dam::notify_fileMoved(tx_dam::file_absolutePath($srcInfo), tx_dam::file_absolutePath($fileInfo));
             $meta = tx_dam::meta_getDataByUid($meta['uid']);
             $status['meta'] = $meta;
             $status['__status'] = TXDAM_file_changed;
             break;
         }
     }
     return $status;
 }