Jump to content

  • twitter
  • youtube
  • googleplus
  • facebook
  • rss
  • newsletter


Tutorial info Visit support topic

  • Added on: Jan 21 2009 04:47 AM
  • Views: 2864
 


[IPB 2.3.x] Adding your own task

Posted by Michael on Jan 21 2009 04:47 AM
There is many reasons while you might need a task in your modification, from clearing out your mods logs to performing resource intensives tasks in the background, like updating categories views.

IP.Board allows you to add a task without editing any files. To start off we need to add a file to the sources/tasks/ folder. You can name this file what ever you want, in this example we are going to call it news.php.

<?php

if ( ! defined( 'IN_IPB' ) )
{
	print "<h1>Incorrect access</h1>You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files.";
	exit();
}

class task_item
{
	var $class	 = "";
	var $root_path = "";
	var $task	  = "";
	
	function run_task()
	{
		// Run what ever we need in a task here, this is just like any other file and should be able to
		// run what ever you had in components_public and want to run as a task.
		
		// Add to task log?		
		$this->class->append_task_log( $this->task, 'Task news.php has run.' );
		
		// Unlock Task 
		// leave this one alone, you need to unlock a task.
		$this->class->unlock_task( $this->task );
	}
	
	function register_class(&$class)
	{
		$this->class	 = &$class;
		$this->ipsclass  =& $class->ipsclass;
		$this->root_path = $this->class->root_path;
	}
	
	function pass_task( $this_task )
	{
		$this->task = $this_task;
	}	
}
?>

It's best to leave all the functions alone and just add your task code above $this->class->append_task_log( $this->task, 'Task news.php has run.' );

Next you will need to setup the task details in the admin cp. Go to Admin CP > Tools & Settings Tab > Task Manager > Add New Task button. I've added a screenshot of the example details we need to fill out. Remember to name the Task PHP File To Run field the same name as your sources/tasks/ file with .php added to the end of it.

task_manager.png

Powered by Tutorials 1.4.1 © 2012, by Michael McCune