News:

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

Main Menu

add a new function to scheduled tasks

Started by busterone, December 17, 2011, 06:34:07 PM

Previous topic - Next topic

busterone

I needed to post back to clarify a couple of issues in the event any code newbies like me reads this topic in the future.  :)

After I said that it was working last night, I went on to bed. Upon awakening, the scheduled event was not working, only if I manually ran the task did it work. I changed the time interval, left it and went on to work. Upon returning, it still wasn't working except on manual.  Being new to this, I thought I had overlooked some code, but after studying Arantor's topic more closely, I realized that the function was in the wrong file.  :)

It was posted earlier in this topixc to place the function in /Sources/ManageScheduledTasks.php,  however, in Arantor's topic, it is  /Sources/ScheduledTasks.php.
I simply moved the code to the proper file and everything is working as expected.  :)
If placed in the former file, it will only work manually.

Thanks again to everyone that answered for the help.  :)

Kays

My bad. Maybe I should of read that also instead of just skimming over it.  :-[

Glad you got it sorted out. :)

If at first you don't succeed, use a bigger hammer. If that fails, read the manual.
My Mods

busterone

I had already read it several times myself and was overlooking it too.  Thanks. All is well.   :)

busterone

I am resurrecting this one.  The scheduled task has worked well, but the bots have increased their posts dramatically, so I want to take it in a different direction. I am getting an average of 1000+ bot posts per day, and I manually delete them at least once every other day. It is time consuming even with quick mod enabled and page view set to 100 topics per page.  I want to automate the topics deletions through the scheduled tasks.

I am re-posting the previous code to save time of looking back in the topic to see what it is. I would like to change this function from simply replacing all posts with a character to actually deleting them all at my set interval.
function scheduled_my_update()
{
  global $smcFunc;

  $smcFunc['db_query']('', '
UPDATE {db_prefix}messages
SET body = {string:body_str}',
array(
'body_str' => 'x'
)
  );
log_error('My update was successfully run');
}


I am not overly concerned with updating the member's post counts and forum stats etc, because I also delete all the members about once a week as well.  I am just a bit unsure how to write the db query without breaking the honeypot forum.   :)

busterone


IchBin™

If you don't need any posts, then just truncate the table instead of update it.

TRUNCATE TABLE tablename;
IchBin™        TinyPortal

busterone

#26
I would need to empty both smf_messages and smf_topic tables, so I am not sure how to write it correctly.
something like this? -   

function scheduled_my_update()
{
  global $smcFunc;

  $smcFunc['db_query']('', '
TRUNCATE TABLE{db_prefix}messages;
        TRUNCATE TABLE{db_prefix}topics;
    );
log_error('My update was successfully run');
}


Not quite right- I get the following error when I try to manually run the task
Parse error: syntax error, unexpected T_STRING in /xx/xx/xx/htdocs/daily/Sources/ScheduledTasks.php on line 1568

line 1568 is log_error('My update was successfully run'); so it is something previous to that line in the code, but I don't see it myself.

IchBin™

You need two separate queries for each of those statements. Just add one query below the other.
IchBin™        TinyPortal

busterone

Ok, I somewhat get what you are saying, but not completely. Remember, I am not a coder, I stumble through this stuff most of the time. Something more like this, even though I know that isn't right either.

function scheduled_my_update()
{
  global $smcFunc;

  $smcFunc['db_query']('', '
TRUNCATE TABLE{db_prefix}topics;
    );
  $smcFunc['db_query']('', '
        TRUNCATE TABLE{db_prefix}messages;
    );
log_error('My update was successfully run');
}

IchBin™

#29
Syntax is a little off, but that is the gist of it.

function scheduled_my_update()
{
global $smcFunc;

$smcFunc['db_query']('', '
TRUNCATE TABLE {db_prefix}topics'
);
$smcFunc['db_query']('', '
TRUNCATE TABLE {db_prefix}messages'
);
log_error('My update was successfully run');
}
IchBin™        TinyPortal

Arantor

There should be spaces between TABLE and {db_prefix}

IchBin™

IchBin™        TinyPortal

busterone

O yeah, works a charm.  I see where my syntax was off now, so close but not quite.
Thanks much.  :)
Remarking this one as solved. 

Advertisement: