/** * Same as above but returns error if file already exists at destination. * * @param string $oldfile The path to the file to be moved. * @param string $newfile The path where $oldfile should be moved to. * @return boolean TRUE if file successfully moved */ function moveFileIfNotExists($oldfile, $newfile) { if (!file_exists($newfile)) { return PhotoQHelper::moveFile($oldfile, $newfile); } else { return FALSE; } }
function _rebuildFileSystem($updateOriginalFolder, $changedSizes) { $oldNewFolderName = array('', ''); if ($updateOriginalFolder) { $oldNewFolderName = $this->updateOriginalFolderName(); PhotoQHelper::moveFile($oldNewFolderName[0], $oldNewFolderName[1]); } //remove the image dirs foreach ($changedSizes as $changedSize) { PhotoQHelper::recursiveRemoveDir($this->_oc->getImgDir() . $changedSize . '/'); } PhotoQHelper::debug('oldNewFolderName: ' . print_r($oldNewFolderName, true)); return $oldNewFolderName; }
function cleanUpAfterError() { //move back original if it has been moved already $oldPath = $this->_oc->getQDir() . $this->imgname; if (!file_exists($oldPath) && file_exists($this->_sizes[$this->_oc->ORIGINAL_IDENTIFIER]->getPath())) { PhotoQHelper::moveFile($this->_sizes[$this->_oc->ORIGINAL_IDENTIFIER]->getPath(), $oldPath); } //remove any resized images that have been created unless a corresponding original image exists if (!file_exists($this->_sizes[$this->_oc->ORIGINAL_IDENTIFIER]->getPath())) { foreach ($this->_sizes as $size) { $size->deleteResizedPhoto(); } } }
/** * Overwrites default behavior. No call to phpThumb needed for original photo. * Just move it to the imgdir. * * @param unknown_type $oldOriginalPath * @return unknown */ function createPhoto($oldOriginalPath, $moveOriginal = true) { //create directory if (!PhotoQHelper::createDir($this->_yearMonthDirPath)) { return new PhotoQErrorMessage(sprintf(_c('Error when creating directory: %s| dirname', 'PhotoQ'), $this->_yearMonthDirPath)); } //move the image file if (!file_exists($this->_path)) { if ($moveOriginal) { if (!PhotoQHelper::moveFile($oldOriginalPath, $this->_path)) { return new PhotoQErrorMessage(sprintf(_c('Unable to move %s, posting aborted.| imgname', 'PhotoQ'), $this->_imgName)); } } else { //we don't move we only copy if (!copy($oldOriginalPath, $this->_path)) { return new PhotoQErrorMessage(sprintf(_c('Unable to copy %s, posting aborted.| imgname', 'PhotoQ'), $this->_imgName)); } } } else { return new PhotoQErrorMessage(sprintf(_c('Image %s already exists, posting aborted.| imgname', 'PhotoQ'), $this->_imgName)); } return new PhotoQStatusMessage(__('Original photo moved successfully')); }
function _rebuildFileSystem($updateOriginalFolder, $changedSizes, $imgDirChanged, $oldImgDir) { //check whether imgdir changed. if so we have to move all the existing stuff and rebuild the content if ($imgDirChanged) { $this->_moveImgDir($oldImgDir, false); } $oldNewFolderName = array('', ''); if ($updateOriginalFolder) { $oldNewFolderName = $this->_updateOriginalFolderName($oldImgDir); PhotoQHelper::moveFile($oldNewFolderName[0], $oldNewFolderName[1]); } //remove the image dirs foreach ($changedSizes as $changedSize) { PhotoQHelper::recursiveRemoveDir($this->_oc->getImgDir() . $changedSize . '/'); } PhotoQHelper::debug('oldNewFolderName: ' . print_r($oldNewFolderName, true)); return $oldNewFolderName; }
function mergeDirs($oldfile, $newfile) { if (!file_exists($newfile)) { return PhotoQHelper::moveFile($oldfile, $newfile); } else { if (is_dir($oldfile) && is_dir($newfile)) { $oldfile = rtrim($oldfile, '/') . '/'; $newfile = rtrim($newfile, '/') . '/'; //get all visible files from old img dir $match = '#^[^\\.]#'; //exclude hidden files starting with . $visibleFiles = PhotoQHelper::getMatchingDirContent($oldfile, $match); foreach ($visibleFiles as $file2merge) { PhotoQHelper::mergeDirs($file2merge, str_replace($oldfile, $newfile, $file2merge)); /*if(!$res){ return false; }*/ } } else { return false; } } }