david-szabo97 / grav-plugin-admin-addon-revisions

An extension for Grav Admin plugin which adds revisions for pages.
MIT License
11 stars 8 forks source link

Revisions directories are not created #31

Open Xoriander opened 7 months ago

Xoriander commented 7 months ago

The plugin was installed on a fresh installation of Grav v1.7.44 - Admin v1.10.44 running on PHP 8.2.16. If a page was changed no revision was found. Debugger shows --- Admin Addon Revision - Analyzing 'PageName' --- and -- Not writable, skipping for all pages.

On line 207 of admin-addon-revisions.php is a writable check of the revisions directory, it is before a directory existing check. So on first install there is a writable check on a non existing directory that result is always false.

https://github.com/david-szabo97/grav-plugin-admin-addon-revisions/blob/7c7946ef05c0a6b8fe5382a9b7cb38c8c34c1a27/admin-addon-revisions.php#L206-L216

I've changed it to:

    $revisions = new Revisions($page);

    // Make sure we have a revisions directory
    if (!$revisions->exists()) {
      if (is_writable($page->path())) {
        $this->debugMessage('-- Creating revision directory...');
        $revisions->create();
      } else {
        $this->debugMessage('-- Page directory not writable, skipping');
        return;  
      }
    }

    if (!$revisions->writable()) {
      $this->debugMessage('-- Revisions directory not writable, skipping');
      return;
    }

Now it is working for me. Thank you for the Plugin.