Skip to content
Grav 2.0 is officially stable. Read the announcement →
Support

Mkdir() not allowed for plugin://login/pages/.revs

Started by david 4 years ago · 11 replies · 317 views
4 years ago

Hi

I am seeking if someone can help me with grav-plugin-admin-addon-revisions plugin

It has bug:

When first script run it creates directories .revs. I can see that directories for first time are actually created but with website refresh, whole site not working with error message: mkdir() not allowed for plugin://login/pages/.revs

I think it still tries to create directories but they are there. Plugin has if exists function too but for some reason this does not seem to work

Conf:

YAML
enabled: true
debug: false
directory: .revs
limit:
  maximum: 50
  older: 1 year

Plugin is latest stable what grav cli download

Grav v1.7.37.1
Admin Addon Revisions [v1.4.0]

Web files belong to www user/group

Can someone with php/grav knowledge clone this script and provide patch?
I can sponsor

I think it's great feature (grav revision) what is missing from core

last edited 12/06/22 by david
4 years ago

Yes i did. That's why i offer for someone to clone this script and provide patch. Perhaps fork then?

4 years ago

Ok i have fixed mkdir issue. I will fork and provide patch too but now is other issue:
Maybe grav 1.7 compatible issue?

TXT
scandir(plugin://login/pages/.revs): Failed to open directory: "RocketTheme\Toolbox\StreamWrapper\ReadOnlyStream::dir_opendir" call failed"

code itself:

PHP
<?php
namespace AdminAddonRevisions\Util;

use Grav\Common\Grav;
use Grav\Plugin\AdminAddonRevisionsPlugin;
use AdminAddonRevisions\Util\Diff;

class Util {

  public static function filePathToUrl($filePath) {
    return Grav::instance()['base_url'] . preg_replace('|^' . preg_quote(GRAV_ROOT) . '|', '', $filePath);
  }

  public static function scandir($directory, $fileOnly = true) {
    $files = array_diff(scandir($directory), ['.', '..', AdminAddonRevisionsPlugin::instance()->directoryName()]);

    $files = array_filter($files, function($file) use($directory, $fileOnly) {
      $fileOnlyCondition = is_dir($directory . DS . $file) === !$fileOnly;
      $ignoredCondition = AdminAddonRevisionsPlugin::instance()->isIgnoredFile($directory . DS . $file);

      return $fileOnlyCondition && !$ignoredCondition;
    });

    return $files;
  }

  public static function scandirForFiles($directory) {
    return self::scandir($directory, true);
  }

  public static function scandirForDirectories($directory) {
    return self::scandir($directory, false);
  }

  public static function fileChanged($path1, $path2) {
    return filesize($path1) !== filesize($path2)
            || md5_file($path1) !== md5_file($path2);
  }

  public static function diffToHTML($diff) {
    $html = '';

    foreach ($diff as $c) {
      switch ($c[1]) {
        case Diff::UNMODIFIED:
          $html .= '' . $c[0];
          break;
        case Diff::INSERTED:
          $html .= '<span class="inserted">' . $c[0]. '</span>';
          break;
        case Diff::DELETED:
          $html .= '<span class="deleted">' . $c[0]. '</span>';
          break;
      }
    }

    return $html;
  }

}
4 years ago

I can pay for this plugin code fix.

4 years ago

@david1, Have you tried emailing your offer to the author directly? [email protected]

last edited 12/11/22 by pamtbaau
4 years ago

Well... ReadOnlyStream.php name says it cleaarly - it's a class for read-only access. What's the question?

4 years ago

Im searching help for grav mkdir function. I thinked it is php native mkdir but not. Following code will result to

PHP
 $path = $this->path();
if (is_dir($this->path)) {
    return false;
}
else {
mkdir($path, 0775, true);
}

"mkdir() not allowed for plugin://login/pages/.revs"

here is grav mkdir function

vendor/rockettheme/toolbox/StreamWrapper/src/ReadOnlyStream.php

TXT
#[\ReturnTypeWillChange]
    public function mkdir($uri, $mode, $options)
    {
        throw new BadMethodCallException(sprintf('mkdir() not allowed for %s', $uri));
    }
4 years ago

Try in the plugin adding \ before mkdir() in both places - like \mkdir(). It should force to use native php function instead of StreamWrapper. Just not sure how it will handle
plugin stream.

But browsing the code, it looks like it should use Grav\Common\Filesystem\Folder::mkdir(). Not sure why it doesn't. Would need to debug to figure out

4 years ago

\ did not work. still same error message. i am trying slightly modified my version. Like this one:

PHP
if (is_dir($this->path)) {

return false;

}

else {

\mkdir($this->path, 0775, true);

}

Suggested topics

Topic Participants Replies Views Activity
Support · by Duc , 2 hours ago
1 17 1 hour ago
Support · by Thomas, 1 week ago
3 101 10 hours ago
Support · by Anna, 3 days ago
2 99 1 day ago
Support · by Justin Young, 1 day ago
1 66 1 day ago
Support · by Duc , 1 week ago
2 101 6 days ago