Navigation Menu

Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Count file reset #11

Open
ondrejvysek opened this issue Aug 5, 2018 · 17 comments
Open

Count file reset #11

ondrejvysek opened this issue Aug 5, 2018 · 17 comments

Comments

@ondrejvysek
Copy link

after installing a plugin, configured as docummented, file data/count-views.yaml always stores just one rticle with count 1.
The problem is that $data variable at row 89 always return array 0 thus file is recreated.
just addedd $cnt = (array)$datafh->content(); to row 88 and work well (articles are addedd and views are increased)

@Perlkonig
Copy link
Owner

I just now created a brand new install. I installed the plugin, and then visited the two built-in pages. Both appeared in my data file. And my demo site has almost 300 entries. The problem does not appear to be in the plugin itself.

@ondrejvysek
Copy link
Author

I just created fresh install from package grav-skeleton-open-blog-space.zip. The behavior is the same as described in my first post.

@Perlkonig
Copy link
Owner

I'm sorry, but I can't replicate. I just did the same thing, and here's my count-views.yaml data:

/: 2
/standardpage: 1
/modular-page-inject: 1
/readme: 1

@Perlkonig
Copy link
Owner

Closing due to inactivity. Reopen if you have more information.

@Necdilzor
Copy link

having the same problem with a fresh install of grav and plugin, the file just resets itself every time you visit a page or refresh the current one
I'm developing on Windows 10 if that helps

@Perlkonig
Copy link
Owner

I don't know what to say. @ondrejvysek , are you also on Windows?

@ondrejvysek
Copy link
Author

Sorry for late response I was oof - yes my original result was on my dev machine Windows 10 with WAMP, php 7.1

@Perlkonig
Copy link
Owner

Please point me to the dev environment(s) you're using (there are lots of different stacks out there) and I will see if I can replicate.

@Perlkonig Perlkonig reopened this Aug 19, 2018
@Necdilzor
Copy link

Here's what I'm using. I hope it helps!

Windows 10 - 64 bits - version1803
PHP 7.2.7
Apache 2.4.33
(installed by using XAMPP)

@Perlkonig
Copy link
Owner

Well the good news is that I can replicate the issue. But the bad news is that I have no idea why it's happening. Asking around...

@ondrejvysek
Copy link
Author

ondrejvysek commented Aug 19, 2018 via email

@Perlkonig
Copy link
Owner

Please post the code block you're using. Are you replacing the lock line? The problem is that this code works just fine in lines 63-66. The only difference between the two blocks is the file locking. The file locking is important to not lose counts during a flurry of activity. Your suggested code change shouldn't change anything, unless you're removing the lock line, which really shouldn't happen if it can be avoided.

@ondrejvysek
Copy link
Author

ondrejvysek commented Aug 20, 2018

Here is the modded code of the section //Open Data File, originally line 86 to 92.
// Open data file
$datafh = File::instance($path);
$cnt = (array)$datafh->content(); //This line was addedd
$datafh->lock();
$data = Yaml::parse($datafh->content());
if ($data === null) {
$data = array();
}

just added $cnt = (array)$datafh->content(); It doesn't do any modification to the data, just reads array from the file.

@Perlkonig
Copy link
Owner

All you're doing is bypassing the existing code. I assume you've made other adjustments to use $cnt, because that variable doesn't exist in the original code. And this doesn't solve the problem of losing counts during a flurry of activity. (Without file locking, multiple simultaneous updates will just clobber each other.) If you don't care about locking, all you have to do to make the plugin work is delete the $datafh->lock(); line.

I've submitted an issue against the file handling library, and hopefully we'll have a permanent solution soon.

@petira
Copy link

petira commented Nov 11, 2018

Hi, I have the same problem. When I visit a different page, the file is completely deleted, specifically its content is replaced by only the current page but always with the set number of 1.

In other words, when I visit Home, Test, and Home again, it is not finally content

/: 2
/ test: 1

but (step by step)

/: 1

/ test: 1

and finally

/: 1

Tested on the latest version of Grav and Count Views Plugin.

@petira
Copy link

petira commented Mar 28, 2019

The previous issue is really in Win10/XAMPP environment only. In UX environment working this plugin correctly. THX.

@replayshot
Copy link

same issue on Windows WAMP environment after fresh install

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants