/** * Deleting files and folders (action=4) * * @param array $cmds['data'] is the the file/folder to delete * @return boolean Returns true upon success */ function func_delete($cmds, $id) { if (!$this->isInit) { return FALSE; } // Checking path: $theFile = $cmds['data']; // main log entry $this->log['cmd']['delete'][$id] = array('errors' => array(), 'orig_filename' => $theFile, 'target_file' => '', 'target_path' => ''); # $theFile = preg_replace('#/$#', '', $theFile); if (!$this->isPathValid($theFile)) { $this->writelog(4, 2, 101, 'Target "%s" had invalid path (".." and "//" is not allowed in path).', array($theFile), 'delete', $id); return FALSE; } // Recycler moving or not? if ($this->useRecycler && ($recyclerPath = $this->findRecycler($theFile))) { // If a recycler is found, the deleted items is moved to the recycler and not just deleted. $newCmds = array(); $newCmds['data'] = $theFile; $newCmds['target'] = $recyclerPath; $newCmds['altName'] = 1; $theDestFile = $this->func_move($newCmds); $this->writelog(4, 0, 4, 'Item "%s" moved to recycler at "%s"', array($theFile, $recyclerPath), 'delete', $id); // add file to log entry $this->log['cmd']['delete'][$id]['target_file'] = $theDestFile; $this->log['cmd']['delete'][$id]['target_path'] = $recyclerPath; // update meta data if ($this->processMetaUpdate) { tx_dam::notify_fileDeleted($theFile, $recyclerPath . '/' . tx_dam::file_basename($theFile)); } return TRUE; } elseif ($this->useRecycler != 2) { // if $this->useRecycler==2 then we cannot delete for real!! if (@is_file($theFile)) { // If we are deleting a file... if ($this->actionPerms['deleteFile']) { if ($this->checkPathAgainstMounts($theFile)) { if (@unlink($theFile)) { $this->writelog(4, 0, 1, 'File "%s" deleted', array($theFile), 'delete', $id); // update meta data if ($this->processMetaUpdate) { tx_dam::notify_fileDeleted($theFile); } return TRUE; } else { $this->writelog(4, 1, 110, 'Could not delete file "%s". Write-permission problem?', array($theFile), 'delete', $id); } } else { $this->writelog(4, 1, 111, 'Target was not within your mountpoints! T="%s"', array($theFile), 'delete', $id); } } else { $this->writelog(4, 1, 112, 'You are not allowed to delete files', '', 'delete', $id); } // FINISHED deleting file } elseif (@is_dir($theFile)) { // if we're deleting a folder if ($this->actionPerms['deleteFolder']) { $theFile = $this->is_directory($theFile); if ($theFile) { if ($this->checkPathAgainstMounts($theFile)) { // I choose not to append '/' to $theFile here as this will prevent us from deleting mounts!! (which makes sense to me...) if ($this->actionPerms['deleteFolderRecursively'] && !$this->dont_use_exec_commands) { // No way to do this under windows $cmd = 'rm -Rf ' . escapeshellarg($theFile); exec($cmd); // This is a quite critical command... clearstatcache(); if (!@file_exists($theFile)) { $this->writelog(4, 0, 2, 'Directory "%s" deleted recursively!', array($theFile), 'delete', $id); // update meta data if ($this->processMetaUpdate) { tx_dam::notify_fileDeleted($theFile); } return TRUE; } else { $this->writelog(4, 2, 119, 'Directory "%s" WAS NOT deleted recursively! Write-permission problem?', array($theFile), 'delete', $id); } } else { if (@rmdir($theFile)) { $this->writelog(4, 0, 3, 'Directory "%s" deleted', array($theFile), 'delete', $id); // update meta data if ($this->processMetaUpdate) { tx_dam::notify_fileDeleted($theFile); } return TRUE; } else { $this->writelog(4, 1, 120, 'Could not delete directory! Write-permission problem? Is directory "%s" empty? (You are not allowed to delete directories recursively).', array($theFile), 'delete', $id); } } } else { $this->writelog(4, 1, 121, 'Target was not within your mountpoints! T="%s"', array($theFile), 'delete', $id); } } else { $this->writelog(4, 2, 122, 'Target seemed not to be a directory! (Shouldn\'t happen here!)', '', 'delete', $id); } } else { $this->writelog(4, 1, 123, 'You are not allowed to delete directories', '', 'delete', $id); } // FINISHED copying directory } else { $this->writelog(4, 2, 130, 'The item was not a file or directory! "%s"', array($theFile), 'delete', $id); } } else { $this->writelog(4, 1, 131, 'No recycler found!', '', 'delete', $id); } }
/** * Delete a file and process DB update * * @param string $filename File path * @param boolean $getFullErrorLogEntry If set the full error log entry will be returned as array * @return mixed error message or error array * @see tx_dam_tce_file::getLastError() */ function process_deleteFile($filename, $getFullErrorLogEntry = FALSE) { global $TYPO3_CONF_VARS; $error = false; if ($filename = tx_dam::file_absolutePath($filename)) { if (!@file_exists($filename)) { tx_dam::notify_fileDeleted($filename); } else { // Init TCE-file-functions object: require_once PATH_txdam . 'lib/class.tx_dam_tce_file.php'; $TCEfile = t3lib_div::makeInstance('tx_dam_tce_file'); $TCEfile->init(); // Processing rename folder $cmd = array(); $cmd['delete']['NONE']['data'] = $filename; $TCEfile->setCmdmap($cmd); $TCEfile->process(); if ($TCEfile->errors()) { $error = $TCEfile->getLastError($getFullErrorLogEntry); } } if (!$error) { $info = array('target_file' => $filename); tx_dam::_callProcessPostTrigger('deleteFile', $info); } } return $error; }