ShaneV Posted February 4, 2010 Report Share Posted February 4, 2010 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. Quote Link to comment Share on other sites More sharing options...
Management Michael Posted February 4, 2010 Management Report Share Posted February 4, 2010 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 ); Quote Link to comment Share on other sites More sharing options...
ShaneV Posted February 6, 2010 Author Report Share Posted February 6, 2010 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 ); } } Quote Link to comment Share on other sites More sharing options...
Management Michael Posted February 7, 2010 Management Report Share Posted February 7, 2010 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 ); } } Quote Link to comment Share on other sites More sharing options...
ShaneV Posted February 8, 2010 Author Report Share Posted February 8, 2010 Yeah maybe thats better :) working fine now ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.