travispessetto / script-updater-for-php

A MIT Licensed script updater for projects
MIT License
31 stars 7 forks source link

The undo scripts are not running. #7

Open Poltavtcev opened 9 months ago

Poltavtcev commented 9 months ago

Failed to get the undo scripts working. Also, I don't see a function that would execute scripts from the restore.yml file.

Poltavtcev commented 9 months ago

In the function RestoreBackup, I added the following code before the point where the new version is saved to the version.txt file to execute the undo scripts:

if (file_exists($yamlFile)) {
              $spyc = Spyc::YAMLLoad($yamlFile);
              if (array_key_exists("scripts", $spyc) && is_array($spyc['scripts'])) {
                  foreach ($spyc["scripts"] as $script) {
                      $scriptPath = $restoreTo . '/' . $script['script'];
                      if (file_exists($scriptPath)) {
                          include($scriptPath);
                          if ($script['delete']) {
                              unlink($scriptPath);
                          }
                      }
                  }
              }
          }