Cron task

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Cron task

Post by Hervé »

Hi,
In phpBB there is a Cron directory, I suppose it allows some tasks to be started automatically.
How can I add a php script to be executed in certain circumstances ?
Thanks in advance for your help
Last edited by Mick on Thu Jul 18, 2024 10:06 am, edited 2 times in total.
Reason: Solved.
User avatar
Mike-on-Tour
Registered User
Posts: 530
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Cron task

Post by Mike-on-Tour »

In order to start your own cron jobs through phpBB you need to write an extension which holds the skript with the cron task.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

Certainly : how to ?
User avatar
Mike-on-Tour
Registered User
Posts: 530
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Cron task

Post by Mike-on-Tour »

You can find at least everything you need to know to start writing an extension here if that was your question.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

I don't really want to write a complete extension, just run a vrey short php script from time to time.
The ideal would be each time a member modifies a specific profile field, at least each time a member logs in or even once a day.
User avatar
Mike-on-Tour
Registered User
Posts: 530
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Cron task

Post by Mike-on-Tour »

Since a cron job that is running every time a member is modifying a profile field (which isn't strictly a cron job) is not part of phpBB's core code there is no alternative but write an extension. And if you want to modify a phpBB database table I would not recommend to do this outside of phpBB at all which is a second argument for writing an extension.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6314
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: Cron task

Post by thecoalman »

Hervé wrote: Sun Jul 14, 2024 8:07 am The ideal would be each time a member modifies a specific profile field, at least each time a member logs in
That's not something you would do with cron task, that's something you would do in the script when those conditions are met.

or even once a day.
This is something you would do with cron task. Note that the cron task within phpBB is what is considered a "poor mans cron" as it typically relies on a user loading a page to trigger it. You don't need phpBB to do this.If you look in your hosting control panel there is probably section for contrab where you can set it to execute a script based on whatever time measurement you want.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

My host doesn't provide cron task function.
The goal is to update a custom profile field that a member cannot edit by himself each time he modifies another profile field,
at least each time he logs in,
or each time anybody logs in
or even once a day hence the idea of ​​cron.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6314
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: Cron task

Post by thecoalman »

On line 406 of /includes/ucp/ucp_profile.php you would need to add conditional to alter the array $cp_data

Code: Select all

						// Update Custom Fields
						$cp->update_profile_field_data($user->data['user_id'], $cp_data);
That may not work when you are in the ACP so you may want to consider altering the function update_profile_field_data
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

Hi,
I don't understand what you mean by "conditional to alter the array $cp_data".
The custom profile field that a member cannot edit by himself should be updated unconditionally with the result of a calculation based on another field which is mandatory.
In other words, each time FieldA is modified then FieldB = f(FieldA).
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

/includes/ucp/ucp_profile.php calls the function update_profile_field_data :

Code: Select all

	public function update_profile_field_data($user_id, $cp_data)
	{
		$sql = 'UPDATE ' . $this->fields_data_table . '
			SET ' . $this->db->sql_build_array('UPDATE', $cp_data) . '
			WHERE user_id = ' . (int) $user_id;
		$this->db->sql_query($sql);
	}
Can I simply do

Code: Select all

$sql = "UPDATE phpbb_profile_fields_data SET `pf_autovol`='".$Vol."' WHERE user_id=".data['user_id'];
$this->db->sql_query($sql);
User avatar
Mike-on-Tour
Registered User
Posts: 530
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Cron task

Post by Mike-on-Tour »

Short answer: NO

Reason: Just replacing the original UPDATE with yours will break everything phpBB is doing there.

Read this and you will see your error and find a solution.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

OK, thanks.
I think I should rather put my value in the $cp_data array before the DB update takes place.

How can I alter the array $cp_data so that $cp_data[x] = F($cp_data[y]) ?
In other words how can I find the x and y values related to the columns pf_autovol and pf_tankdim of the phpbb_profile_fields_data table ?
Hervé
Registered User
Posts: 562
Joined: Tue Jun 04, 2019 7:51 am
Location: Belgium
Name: Rudy

Re: Cron task

Post by Hervé »

sorry if I write nonsense : like this ?

Code: Select all

$user->get_profile_fields( $user->data['user_id'] );
$TankDim = $user->profile_fields['pf_tankdim'];
// compute $Vol = F($TankDim)
$user->profile_fields['pf_autovol'] = $Vol;
User avatar
Mike-on-Tour
Registered User
Posts: 530
Joined: Wed Jan 15, 2020 3:51 pm
Location: Germany
Name: Michael

Re: Cron task

Post by Mike-on-Tour »

I wouldn't know since I do not know what you are trying to accomplish. But be aware that everything you are going to change or to add has to be done after every phpBB update. That is the reason why there are extensions.

And no, I definitely have neither the time nor the desire to dig into the code in order to come up with a solution.
Watz fo lunch?
If you like my extensions or my support please consider a donation: Image

Return to “phpBB Custom Coding”