Jump to content
DevFuse Forums
Sign in to follow this  
ShaneV

Task locks itself after run

Recommended Posts

Hi,

 

I have this simple task and it replace all underscores but for some reason the task locks itself and wont run again.

 

	public function runTask()
{

	//-----------------------------------------
	// ATTEMPT TO CONNECT TO DB
	//-----------------------------------------

	$con = mysql_connect($this->settings['sql_host'], $this->settings['sql_user'], $this->settings['sql_pass']) or die('Could not connect: ' . mysql_error());
	mysql_select_db($this->settings['sql_database'], $con);


	//-----------------------------------------
	// REPLACE '_' WITH ' ' IN ALL TITLES
	//-----------------------------------------

	mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "topics SET title=REPLACE(title, '_', ' ')");
	mysql_close($con);


	//--------------------------------------------------
	// UNLOCK TASK, CLOSE DB CONNECTION AND CLEAR MEMORY
	//--------------------------------------------------

	mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "task_manager SET task_locked=0 WHERE task_id=24");
	mysql_close($con);

	unset($con,$this->settings,$this->registry,$this->task);

}

 

If i check table task_manager i see the task has a date stamp in the cell task_locked.

All i want is that the task will not locks itself, i want it to runs every 24 hours (but now i have to unlock it every time)

 

Sorry for the bad English, hope someone can help.

Share this post


Link to post
Share on other sites

You'll need to add this under your unset line. It's designed so if anything goes wrong it locks the task, if all goes ok, the task is unlocked for the next run.

 

$this->class->unlockTask( $this->task );

Share this post


Link to post
Share on other sites

Hi, i added $this->class->unlockTask( $this->task ); but it stil locks after it runs.

 

Full page:

 

<?php

/**
* Underscore title replacer for IPB3.x
**/

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
{
/**
* Parent task manager class
*
* @access	protected
* @var		object
*/
protected $class;

/**
* This task data
*
* @access	protected
* @var		array
*/
protected $task			= array();

/**
* Registry Object Shortcuts
*/
protected $registry;
protected $settings;

/**
* Constructor
*
* @access	public
* @param 	object		ipsRegistry reference
* @param 	object		Parent task class
* @param	array 		This task data
* @return	void
*/
public function __construct( ipsRegistry $registry, $class, $task )
{
	/* Make registry objects */
	$this->registry	= $registry;
	$this->settings =& $this->registry->fetchSettings();		
	$this->class	= $class;
	$this->task		= $task;
}

/**
* Run this task
*
* @access	public
* @return	void
*/
public function runTask()
{

	//-----------------------------------------
	// ATTEMPT TO CONNECT TO DB
	//-----------------------------------------

	$con = mysql_connect($this->settings['sql_host'], $this->settings['sql_user'], $this->settings['sql_pass']) or die('Could not connect: ' . mysql_error());
	mysql_select_db($this->settings['sql_database'], $con);


	//-----------------------------------------
	// REPLACE '_' WITH ' ' IN ALL TITLES
	//-----------------------------------------

	mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "topics SET title=REPLACE(title, '_', ' ')");
	mysql_close($con);


	//--------------------------------------------------
	// UNLOCK TASK, CLOSE DB CONNECTION AND CLEAR MEMORY
	//--------------------------------------------------

	mysql_query("UPDATE " . $this->settings['sql_tbl_prefix'] . "task_manager SET task_locked=0 WHERE task_id=24");
	mysql_close($con);

	unset($con,$this->settings,$this->registry,$this->task);
	$this->class->unlockTask( $this->task );

}

}

Share this post


Link to post
Share on other sites

Might be easier just to use IPB3 db class.

 

<?php

/**
* Underscore title replacer for IPB3.x
**/

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
{
       /**
       * Parent task manager class
       *
       * @access       protected
       * @var          object
       */
       protected $class;

       /**
       * This task data
       *
       * @access       protected
       * @var          array
       */
       protected $task                 = array();

       /**
       * Registry Object Shortcuts
       */
       protected $registry;
       protected $settings;

       /**
       * Constructor
       *
       * @access       public
       * @param        object          ipsRegistry reference
       * @param        object          Parent task class
       * @param        array           This task data
       * @return       void
       */
       public function __construct( ipsRegistry $registry, $class, $task )
       {
               /* Make registry objects */
               $this->registry = $registry;
               $this->DB		= $this->registry->DB();
               $this->settings =& $this->registry->fetchSettings();            
               $this->class    = $class;
               $this->task             = $task;
       }

       /**
       * Run this task
       *
       * @access       public
       * @return       void
       */
       public function runTask()
       {         
           $this->DB->query( "UPDATE {$this->settings['sql_tbl_prefix']}topics SET title=REPLACE(title, '_', ' ')" );

           $this->class->unlockTask( $this->task );        
       }

}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×