david1
December 6, 2022, 1:59pm
1
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:
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
@david1 , I see you’ve also logged an issue at the repo of the plugin: mkdir() not allowed for plugin://login/pages/.revs · Issue #28 · david-szabo97/grav-plugin-admin-addon-revisions · GitHub
Unfortunately, the owner is not quite responsive the last few years.
david1
December 6, 2022, 3:15pm
3
Yes i did. That’s why i offer for someone to clone this script and provide patch. Perhaps fork then?
david1
December 10, 2022, 9:38am
4
Ok i have fixed mkdir issue. I will fork and provide patch too but now is other issue:
Maybe grav 1.7 compatible issue?
scandir(plugin://login/pages/.revs): Failed to open directory: "RocketTheme\Toolbox\StreamWrapper\ReadOnlyStream::dir_opendir" call failed"
code itself:
<?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;
}
}
david1
December 11, 2022, 8:37am
5
I can pay for this plugin code fix.
@david1 , Have you tried emailing your offer to the author directly? david.szabo97@gmail.com
david1
December 11, 2022, 10:47am
7
will contact plugin author
david1
December 11, 2022, 12:52pm
8
Im searching help for grav mkdir function. I thinked it is php native mkdir but not. Following code will result to
$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
#[\ReturnTypeWillChange]
public function mkdir($uri, $mode, $options)
{
throw new BadMethodCallException(sprintf('mkdir() not allowed for %s', $uri));
}
Well… ReadOnlyStream.php
name says it cleaarly - it’s a class for read-only access. What’s the question?
david1
December 11, 2022, 1:32pm
10
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
david1
December 11, 2022, 2:06pm
12
\ did not work. still same error message. i am trying slightly modified my version. Like this one:
if (is_dir($this->path)) {
return false;
}
else {
\mkdir($this->path, 0775, true);
}