• Welcome to Simple Machines Community Forum. Please login or sign up.
November 30, 2021, 02:33:47 AM

News:

Check out the SMF Function DB!


Post History

Started by niko, May 23, 2009, 01:02:36 AM

Previous topic - Next topic

aegersz

If you use linux then add something like this into your crontab for weekly execution:

0 0 * * 0 UUUU Prune_Post_History

where UUUU is the designated user's name who runs the task

I run mine every 6 months now
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

SMiFFER

Quote from: Kolya on February 04, 2018, 09:55:54 AM
Please post in the thread and I will explain there as good as I can.

Okay! I do!
But I did not want to disrupt this thread with my newbie-questions.

Unfortunately you have deleted/not quoted what I had asked you.
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

SMiFFER

OK, I'll try to recall.

I wrote:
QuoteI am using this mod and I like it very much.
One question though: The messages-history file in my database gets a bit big now
Is there any option to "purge" outdated changes?

In the offered solution (AVAILABLE HERE)
you list a source code of a php file.

My questions would have been how to make use of that code
Save as what file? And where?
What adjustments are necessary to make it run on my side of the table?
And how to run it?


This might sound too newbie, I really have never looked much into php, which is why I preffered to email you.

My apologies if that maybe sounds too stupid for you.

At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Kolya

You save that code as a PHP file. Name it anything you want (eg post_history_removal.php), just make sure it has the .php extension.
Enter your database details in the code, below "//Connection details".
Then upload the file to your webspace where you keep your forum. The folder is not important, you just need to remember it for when you call this file.
Now call the file with your browser. Say if you uploaded it to the root directory of http://www.my-awesome-smf.com then you need to enter in your browser: http://www.my-awesome-smf.com/post_history_removal.php
This will delete all post history entries that are older than a year.
There will be no feedback in the browser, it will just show a white page.

For advanced usage you can let your server regularly (eg once a month) call this file automatically, by using a cron job. This is exactly what cron jobs do: It's like a scheduled task in Windows. It will regularly call a specific file.
How you set up a cron job will be specific to your hosting service. But generally (provided you have managed hosting and didn't set up the server yourself) you will have some kind of server backend, like cPanel where you can find cronjobs.
You just create a new job there, enter the URL from above (http://www.my-awesome-smf.com/post_history_removal.php) and choose how often you want to let it run.

Kolya

I should add that there are better ways of getting into the database (through SMF functions) instead of writing down the connection details into a PHP file.
I didn't know this yet when I wrote the code you linked above. Maybe I'll update it sometime or maybe someone else will.
Of course the best solution would be if someone integrated it into the mod and let the removal code run as a scheduled task in SMF.

Kindred

February 16, 2018, 11:57:28 AM #165 Last Edit: February 16, 2018, 02:32:59 PM by Kindred
do the following



Code (in ScheduledTasks.php, at end of file - add the following) Select

function scheduled_purge_post_history()
{
global $modSettings, $sourcedir, $mbname, $txt, $smcFunc, $scripturl;

if (((int) $modSettings['posthistory_timelimit']) > 0) {
$datestamp = date('Y-m-d H:i:s', strtotime('-'.((int) $modSettings['posthistory_timelimit']).' day'));

$result = $smcFunc['db_query']('', '
DELETE FROM {db_prefix}smf_messages_history
WHERE date < {string:datestamp}',
array(
'datestamp' => $datestamp,
)
);
}

return true;
}



Code (in ManageSettings.php, find) Select

// Mod authors, add any settings UNDER this line. Include a comma at the end of the line and don't remove this statement!!


Code (Just after that code comment line, add the following) Select

'',
$txt['posthistory_timelimit'],
array('int', 'posthistory_timelimit', 'subtext' => $txt['posthistory_timelimit_desc']),
'',

      
Code (in Modifications.english.php, add the following to the section already added for Post History MOD) Select

$txt['posthistory_timelimit'] = 'Maximum Age of Data (days)';
$txt['posthistory_timelimit_desc'] = 'Set the maximum time to save post history records';


Code (in Help.english.php, add the following) Select

$helptxt['posthistory_timelimit'] = 'This setting will run as a scheduled task and automatically purge all post history records older than the setting, in days. Set this value to 0 to retain all data, always.';


Code (in the smf_scheduled_tasks table of the database, add a row) Select

INSERT INTO `smf_scheduled_tasks` (`id_task`, `next_time`, `time_offset`, `time_regularity`, `time_unit`, `disabled`, `task`) VALUES (NULL, '0', '0', '1', 'd', '1', 'posthistory');




this will add a setting in admin > configuration > modification settings
this will add a scheduled task (disabled by default) that can be set to run automatically or run manually - which will delete all history older than the setting above.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.<br /><br />"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Kolya

That's pretty sweet. Thank you Kindred!

SMiFFER

Many thanks for your help and efforts!
I will take a look, try it and report back in.
Again: VERY MUCH APPRECIATED!!
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

aegersz

hey, that is cool.

it's good to see such a great feature get additional support and seamless integration.
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

SMiFFER

ok, trying this out.

a question for the part with adding a task

where do I enter this:

INSERT INTO `smf_scheduled_tasks` (`id_task`, `next_time`, `time_offset`, `time_regularity`, `time_unit`, `disabled`, `task`) VALUES (NULL, '0', '0', '1', 'd', '1', 'posthistory');


everything else is done.

At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Kindred

In the database...   probably using phpmyadmin, if that's what your host uses.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.<br /><br />"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Kolya

Have you thought about creating a pull request for your changes, Kindred?
https://github.com/nikop/PostHistory

SMiFFER

Quote from: Kindred on February 25, 2018, 06:10:16 PM
In the database...   probably using phpmyadmin, if that's what your host uses.

Ah, so the following is not a command line then and I can just enter the values into the respective fields manually?


INSERT INTO `smf_scheduled_tasks` (`id_task`, `next_time`, `time_offset`, `time_regularity`, `time_unit`, `disabled`, `task`) VALUES (NULL, '0', '0', '1', 'd', '1', 'posthistory');


Then that is really much easier that I thought :)
I had thought that is a command line and looked where to enter that - DOH!
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

SMiFFER

OUCH!

Since I did that - and I was not aware till I took at the logs just now... somehow all scheduled tasks are NOT running.

It looks as though I did something wrong here, all these tasks have not been run since two months:



What can I do to fix this?
A backup of the old file is of course there.

Any idea where to begin?
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

tranhiep_116

Thanks for your give to me

Arnox

May 11, 2018, 08:09:45 PM #175 Last Edit: May 12, 2018, 04:55:59 PM by Kindred
Fix for 2.0.14 and up so it won't spam the error log with "expected to be a reference, value given" errors anymore.

SMiFFER

Quote from: Arnox on May 11, 2018, 08:09:45 PM
Fix for 2.0.14 and up so it won't spam the error log with "expected to be a reference, value given" errors anymore.

AAAAAH! There it is!!!! Thanks a lot, my error log got cluttered with that error already..

What line is the fix?
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

SMiFFER

I have the log full with

2: mysql_num_rows() expects parameter 1 to be resource, object given
Apply Filter: Only show the errors from this file
File: ../forum/Sources/Subs-Post.php
Line: 1601

Is that the same?
At least these 16 (getting more???)steps must be completed for SMF2.1 Final.
Last Full Version: 2.0 Final released more than 10 years ago on 20110604

QUOTE OF Aleksi "Lex" Kilpinen: "That version is old enough to go to school itself."
Quote of the day: A troll is an obstinate bloke who only hungers for your attention. If you feed him, he will puke all over you!

Arnox

Quote from: SMiFFER on May 12, 2018, 03:53:40 AM
I have the log full with

2: mysql_num_rows() expects parameter 1 to be resource, object given
Apply Filter: Only show the errors from this file
File: ../forum/Sources/Subs-Post.php
Line: 1601

Is that the same?

That is from something different.

Arnox

May 12, 2018, 06:13:09 AM #179 Last Edit: May 12, 2018, 06:45:23 AM by Arnox
EVERYONE DO NOT DOWNLOAD THE OLD 1.0.4 ZIP I UPLOADED EARLIER. IT STILL HAS THE OLD CODE BECAUSE I'M STUPID, AND I CAN'T MODIFY THE POST NOW. PLEASE USE THE ONE BELOW INSTEAD.

Quote from: SMiFFER on May 12, 2018, 03:47:32 AM
Quote from: Arnox on May 11, 2018, 08:09:45 PM
Fix for 2.0.14 and up so it won't spam the error log with "expected to be a reference, value given" errors anymore.

AAAAAH! There it is!!!! Thanks a lot, my error log got cluttered with that error already..

What line is the fix?

PH_actions. actionArray specifically. It should just be "$actionArray". No leading '&'.

BTW, please redownload. For some reason, I put in the old unedited PostHistory.php file into the zip. Sorry. DX

Advertisement: