Jump to content
DevFuse Forums

Task locks itself after run


ShaneV

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.

Link to comment
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 );

}

}

Link to comment
Share on other sites

  • Management

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 );        
       }

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...