ProcessWireUpgrade icon indicating copy to clipboard operation
ProcessWireUpgrade copied to clipboard

Possibility to break site on upgrade if you reload the install page

Open adrianbj opened this issue 8 years ago • 3 comments

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.

adrianbj avatar Apr 29 '16 21:04 adrianbj

I think I just accidentally did the same thing again - it's going to really take some users by surprise!

adrianbj avatar Aug 30 '16 16:08 adrianbj

@ryancramerdesign this is still an issue...

matjazpotocnik avatar May 03 '21 19:05 matjazpotocnik

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.

matjazpotocnik avatar May 03 '21 19:05 matjazpotocnik