ryancramerdesign / ProcessWireUpgrade

Upgrade ProcessWire core to latest master or dev version automatically in the admin.
16 stars 6 forks source link

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

Open adrianbj opened 8 years ago

adrianbj commented 8 years ago

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 commented 8 years ago

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

matjazpotocnik commented 3 years ago

@ryancramerdesign this is still an issue...

matjazpotocnik commented 3 years ago

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.