News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Post Limit

Started by Suki, February 11, 2013, 07:30:41 PM

Previous topic - Next topic

Dave J


Suki

I did the change and now the custom message in settings appears on the alert being sent when the user has reached the posting limit set for the account.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Dave J

Thanks Suki I'll check it out later tomorrow and get back to you

Dave J

All working as it should Suki, well done and thank you.

An alert comes as you make the 25% mark and then 75% and then when you have no more it removes the reply button from all areas and an alert tells you you have no more posts left.

Dave J

Tested again today but the cron job couldn't have run as Bill still wasn't allowed to post. I manually ran the task and it did reset. I've changed the message and then posted more posts and the message I've set does post OK, see attached.

I think the 'Hi' in front of the {username} looks more friendly

Dave J

Quote from: harshbhatia01 on March 06, 2025, 06:21:42 AMEnsure the "Subs-PostLimit.php" file is in the Sources folder. If it's not there, I'll download the mod, extract it, and upload the file. Thanks for the reminder!


Just checked and it's not there so that explains why the cron is not changing the limit. I've downloaded the original file and used the "Subs-PostLimit.php" from that

Diego Andrés

Quote from: Dave J on March 06, 2025, 06:28:54 AMJust checked and it's not there so that explains why the cron is not changing the limit. I've downloaded the original file and used the "Subs-PostLimit.php" from that

That was a spambot, you can ignore whatever was posted.

SMF Tricks - Free & Premium Responsive Themes for SMF.

Dave J

Quote from: Diego Andrés on March 06, 2025, 07:25:03 AM
Quote from: Dave J on March 06, 2025, 06:28:54 AMJust checked and it's not there so that explains why the cron is not changing the limit. I've downloaded the original file and used the "Subs-PostLimit.php" from that

That was a spambot, you can ignore whatever was posted.

Well the thing is Diego that file was actually missing from the Sources folder, now whether or not it's meant to be in there I don't know, Suki will tell us, but the file was in the original download so now I've added it to the Sources folder on my test site

Dave J

An update for you Suki,

It seems the custom percent message isn't right. Look at the attached images and compare them with the custom messages I have made. The finished message is fine. Also notice that the default message you created in the 'PostLimit.english.php' is also not being shown. 

That wouldn't have anything to do with the ! in the default message would it? (Hi {username}! you have reached {percentage}% of the total amount you are allowed to post for today.)

Dave J

It would seem the schedules task is not working Suki. See attached for the settings and log

The post limit entries in the log are from manual runs

Suki

For the scheduled task, do you have any error on your error log? something along the lines of "post limit task couldn't be executed" or something similar.

The "Subs-PostLimit.php" file does belong to the original mod, however, the original mod is intended for SMF 2.0.

The new version of the mod, intended for SMF 2.1, doesn't have any Subs-PostLimit.php file and while it is safe to have that file on your server (as it won't actually been used by the new version of the mod) I would delete to avoid confusion.


I will check the alert message not been displayed correctly, most likely another overseeing on my part, its difficult to go back to a codebase and not remember the context.

BTW thanks for all the QA!
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Dave J

Hi Suki

No errors for schedule task, it's just not happening.

I'll remove the 'Subs-postlimit' file, thanks for the info

Suki

Could you find this function on Sources/PostLimit.php file:

public function s(): bool
    {
        global $sourcedir;

        // Need to make sure we loaded these bad boys when running on cron.php
        require_once($sourcedir . '/PostLimit/PostLimitRepository.php');
        require_once($sourcedir . '/PostLimit/PostLimitEntity.php');

        $repository = new PostLimitRepository();
        $repository->resetPostCount();

        // Make sure we are the last hook call, don't ask, just sage nod and move on
        $this->reOrderHookCall($repository);

        //No point in keeping alerts
        $repository->deleteAllAlerts();

        return true;
    }

And replace it with this one:

public function s(): bool
    {
        global $sourcedir;

        // Need to make sure we loaded these bad boys when running on cron.php
        require_once($sourcedir . '/PostLimit/PostLimitRepository.php');
        require_once($sourcedir . '/PostLimit/PostLimitEntity.php');

        log_error('PostLimit scheduled task got called');

        $repository = new PostLimitRepository();
        $repository->resetPostCount();

        // Make sure we are the last hook call, don't ask, just sage nod and move on
        $this->reOrderHookCall($repository);

        //No point in keeping alerts
        $repository->deleteAllAlerts();

        return true;
    }

This will force triggering an entry in the error log, this way we will know if the mod's scheduled task was called or not. Don't trigger the scheduled task manually, let the forum do it like it suppose to do and check your error log after it.

Also, can you make sure you have an entry on your database smf_scheduled_tasks table, it should look like the attached image
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Dave J

OK the code change has been done. See below for the table

Just so you know it's there see attached the scheduled task.

It's due to run again 02.00 GMT, I'll check in the morning and reply with the results

Dave J

Morning Suki,

No sign of the scheduled task being performed. There are no errors in the php log or the site log.

Have you updated the downloadable file (on the SMF downloads page) to incorporate the latest file changes; if not can you attach a version to your next post please?

My thoughts are that I will completely remove all instances of the mod, including database and settings entries and start again, maybe something we've done might be causing the scheduled task not to work. It's odd how manually performing the task lets the limit get reset.

This time I'll test it on my main site as there are always people on there to trigger the cron job running, at present the site I'm testing on rarely gets visitors anymore

Suki

If there are no errors and you are able to manually trigger the scheduled task then its most likely related to low or null forum activity by the time the scheduled task needs to be trigger.

SMF's scheduled tasks depends on forum activity, IE, someone or something visiting your forum around the time a specific scheduled task needs to run. If you are testing this mod in a testing env or a low activity forum, chances are the scheduled task is not being called because there wasn't any activity when it was suppose to trigger.

There are a few solutions for that, the most viable one would be setting up a cron job in your hosting service pointing to yourforum.com/cron.php that way you can guarantee that a scheduled task is going to be called exactly at the time you need to and it eliminates the need for having forum activity.  There are plenty of guides on how to setup cron jobs or you could ask your hosting provider as well.


Another alternative solution for your testing env would be to change the time of the post limit scheduled task to a time where you are certain that your forum has activity.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Dave J

Well that was a great idea. For some reason installing it on my main site results in the members who are post limited cannot access their profiles or their alerts.

So I've uninstalled it.

However I'm going to install it on my test site and set up a cron job to run the scheduled tasks.

Dave J

It's still not refreshing with a cron job and there are no cron errors. 

What is strange is that it obviously wants to run because only today have I noticed that if I'm on the schedule page and I refresh the page the 'Next Due' time changes to the current time on my PC, see attached. It does this every time I refresh the page

Dave J

I couldn't stand it any logger so I did a manual reset as per attached and then posted more until it ran out again. At least we know the process works even if not automatically.

The scheduled server cron job is running every hour so it should have triggered it in the last 12 hours at least once

Suki

I'm lost at this point, without any more details I cannot properly debug why the scheduled task is not running.  One last chance is to take a look at your server error log and see if there is anything on there.

Your screenshots shows that you have the postlimit scheduled at 1am repeating everyday, this means that the postlimit scheduled task is only going to be executed once a day, even if your cronjob executes every hour.

The cronjob executes cron.php which in turn determinate which actions are going to be executed, the cronjob doesn't execute all scheduled task by itself. SMF is the one that handles which action is going to be executed depending on their configuration.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Advertisement: