Farcell
Member
Hi there, I am trying to run a Cron script in batches, so that I don't get a headache later, so I decided to load the data in batches of 1000 at a time. I've written this PHP script in a file to be triggered, which will hopefully update my my cargo table:
The problem is it gives me an error which is an 'Undeclared variable' in the limit i set when I execute it manually in schedule. I created a separate table to load and updated the row count from the previous cron execution which I get the row count from the previous execution.
Can you tell me how I can get around this problem?
Code:
<?php
defined('_JEXEC') or die('Restricted index access');
$myDb = FabrikWorker::getDbo();
$myDb->setQuery("SELECT * FROM `row` WHERE `country` = 'uk'");
$rows = $myDb->loadObjectList();
foreach($rows as $row) {
$count = $row->cargo;
}
// Update row count for Next Batch of Cron Execution
// Get cargo row count
$counter = $myDb->setQuery("SELECT COUNT(*) AS id FROM `cargo` WHERE `cargo_archive` = '0'");
$num = mysql_fetch_array($counter);
$counted = $num["id"];
//Return row count to 0
if ($counted <= $count){
// Return row ro 0
$myDb->setQuery("UPDATE `row` SET `cargo` = '0' WHERE `country` = 'uk'");
$myDb->execute();
}else{
//Increase row count by 1000 for next batch
$myDb->setQuery("UPDATE `row` SET `cargo` = `cargo`+'1000' WHERE `country` = 'uk'");
$myDb->execute();
}
//Update next batch of 1000 rows
$myDb->setQuery("UPDATE `cargo` SET `cargo_archive` = '1' WHERE `cargo_archive` = (SELECT * FROM `cargo` WHERE `cargo_archive` = '0' LIMIT `$count`,`1000`) AND DATE(cargo.arrival_date) = CURDATE()");
$myDb->execute();
?>
The problem is it gives me an error which is an 'Undeclared variable' in the limit i set when I execute it manually in schedule. I created a separate table to load and updated the row count from the previous cron execution which I get the row count from the previous execution.
Can you tell me how I can get around this problem?