This will start the export profile by id and then clear dataflow_batch_? thereafter. Keep in mind that he works as a command line user and can create cache files as this user, which can be inconvenient with certain web server settings. This does not hurt to clear the cache after startup.
1.4.1.1 , .
<?php
$mageconf = './app/etc/local.xml';
$mageapp = './app/Mage.php';
$logfile = 'export_data.log';
$profileId = 9;
$table = 'dataflow_batch_export';
if (file_exists($mageconf)) {
$xml = simplexml_load_file($mageconf, NULL, LIBXML_NOCDATA);
$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;
}
else {
Mage::log('Export script failed to open Mage local.xml', null, $logfile);
exit('Failed to open Mage local.xml');
}
require_once $mageapp;
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$profile = Mage::getModel('dataflow/profile');
$userModel = Mage::getModel('admin/user');
$userModel->setUserId(0);
Mage::getSingleton('admin/session')->setUser($userModel);
$profile->load($profileId);
if (!$profile->getId()) {
Mage::getSingleton('adminhtml/session')->addError('ERROR: Incorrect profile id');
}
Mage::log('Export ' . $profileId . ' Started.', null, $logfile);
Mage::register('current_convert_profile', $profile);
$profile->run();
$recordCount = 0;
$batchModel = Mage::getSingleton('dataflow/batch');
Mage::log('Export '.$profileId.' Complete. BatchID: '.$batchModel->getId(), null, $logfile);
echo "Export Complete. BatchID: " . $batchModel->getId() . "\n";
sleep(30);
mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());
$querystring = "TRUNCATE ".$db['pref'].$table;
mysql_query($querystring) or die(mysql_error());
?>