Open adrianbj opened 8 years ago
I think I just accidentally did the same thing again - it's going to really take some users by surprise!
@ryancramerdesign this is still an issue...
My attempt to fix this: in __destruct() method, I added 3 lines, so now it looks like this:
public function __destruct() {
if(!count($this->renames)) return;
//$rootPath = dirname(rtrim($this->wirePath, '/')) . '/';
foreach($this->renames as $oldPath => $newPath) {
if(file_exists($newPath)) {
$n = 0;
do {
$newPath2 = $newPath . "-" . (++$n);
} while(file_exists($newPath2));
if(rename($newPath, $newPath2)) {
$this->message("Renamed $newPath => $newPath2");
}
}
$old = basename(rtrim($oldPath, '/'));
$new = basename(rtrim($newPath, '/'));
if(rename($oldPath, $newPath)) {
$this->message("Renamed $old => $new");
} else {
rename($newPrev, $oldPrev); //added this line
$this->error("Unable to rename $old => $new");
}
$newPrev = $newPath; //added this line
$oldPrev = $oldPath; //added this line
}
$this->renames = array();
}
It reverts the last rename operation in the previous step. Perhaps not perfect, but at least the site works.
This might be an unusual situation, but on one of my sandbox installs, I reloaded: /processwire/setup/upgrades/install/#
and it ended up breaking the site because it renamed the current versions of wire/htaccess/index.php to the version number of the new version that was just installed. This left the site with no current / active versions of these files. It was easy to fix by renaming these manually, but I think the module should prevent this from being possible.