Magento Forum

Run DataFlow Profile via shell/PHP [CE 1.7]
 
Xephor
Jr. Member
 
Total Posts:  2
Joined:  2012-09-15
 

Goodafternoon!

In Magento CE 1.7 I’m trying to run a profile trough a PHP-script, to be able to automaticly run DataFlow profiles via cron jobs. I already set a working profile: the import-file is correctly imported by running the profile in the magento backend. The script (see below) I use creates a hopeful output:

2012-09-15T13:04:10+00:00 DEBUG (7): Starting import
2012-09-15T13:04:10+00:00 DEBUG (7): Skip import row, is not valid value \"type\" for field \"type\"
2012-09-15T13:04:11+00:00 DEBUG (7): Starting Mage_Dataflow_Model_Convert_Adapter_Io :: load
2012-09-15T13:04:11+00:00 DEBUG (7): Loaded successfully: \"/home/drogist01/domains/online-drogist.nu/public_html/var/import/droginet_export.csv\".
2012-09-15T13:04:11+00:00 DEBUG (7): Starting Mage_Dataflow_Model_Convert_Parser_Csv :: parse
2012-09-15T13:04:11+00:00 DEBUG (7): Found 2 rows.
2012-09-15T13:04:11+00:00 DEBUG (7): Starting catalog/convert_adapter_product :: parse
2012-09-15T13:04:11+00:00 DEBUG (7): Completed!

Although the product isn\’t imported at all! Could anyone provide me with some help on solving this case smile?

<?
if ($_SERVER[\"SERVER_ADDR\"!= $_SERVER[\"REMOTE_ADDR\"]){
        
exit (\"only run locally\");
}


$profileId 
$argv[1];
if (! isset(
$profileId)){
   
exit (\"\\nPlease specify a profile id. You can find it in the admin panel->Import/Export->Profiles.\\nUsage: \\n\\t\\t  php -f $argv[0] PROFILE_ID\\n\\t example: php -f $argv[0] 7\\n\");
}

$logFileName
\'import.log\';  
$recordCount 0;

require_once 
\'app/Mage.php\';
ob_implicit_flush();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

Mage::log(\"Starting import\",null,$logFileName);  
$profile Mage::getModel(\'dataflow/profile\');
$userModel Mage::getModel(\'admin/user\');
$userModel->setUserId(0);
Mage::getSingleton(\'admin/session\')->setUser($userModel);
#echo \"got singleton\\n\"; 
if ($profileId{
   $profile
->load($profileId);
   if (!
$profile->getId()) {
      Mage
::getSingleton(\'adminhtml/session\')->addError(\'ERROR: Could not load profile\');
   
}
}

Mage
::register(\'current_convert_profile\'$profile);

#echo \"running profile\\n\";
$profile->run();
##echo \"done\\n\";

$batchModel Mage::getSingleton(\'dataflow/batch\');
if (
$batchModel->getId()) {
   
#echo \"getId ok\\n\";
   
if ($batchModel->getAdapter()) {
      
#echo \"getAdapter ok\\n\";
      
$batchId $batchModel->getId(); 
      
$batchImportModel $batchModel->getBatchImportModel();
      
$importIds $batchImportModel->getIdCollection();  
      
$batchModel Mage::getModel(\'dataflow/batch\')->load($batchId);      
      
$adapter Mage::getModel($batchModel->getAdapter());
      foreach (
$importIds as $importId{
         
#echo \"importing $importId\\n\";
         
$recordCount++;
         
try{
            $batchImportModel
->load($importId);
            if (!
$batchImportModel->getId()) {
               $errors[] 
Mage::helper(\'dataflow\')->__(\'WARNING: Skip undefined row\');
               continue;
            
}
            $importData 
$batchImportModel->getBatchData();
            try 
{
               $adapter
->saveRow($importData);
            
catch (Exception $e{
               Mage
::log($e->getMessage(),null,$logFileName);          
               continue;
            
}      
            
if ($recordCount&#x10; == 0) {
               
Mage::log($recordCount \' products imported\',null,$logFileName);
            
}
         } 
catch(Exception $ex{
            Mage
::log(\'File \' $recordCount \', SKU \' $importData[\'sku\']\' - ERROR: \' $ex->getMessage(),null,$logFileName);        
         
}
      }
      
foreach ($profile->getExceptions() as $e{
         Mage
::log($e->getMessage(),null,$logFileName);          
      
}
   }
}
#printf(\"OK\\n\");
Mage::log(\"Completed!\",null,$logFileName);
?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
cthomas88
Jr. Member
 
Total Posts:  15
Joined:  2010-03-31
 

Hi Xephor,

Have you had any luck in finding why the products are not importing? I have the exact same issue but with the stock not updating. Im assuming that whatever is stopping the import it is the same issue for both of us.

Many Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
Xephor
Jr. Member
 
Total Posts:  2
Joined:  2012-09-15
 

Hi cthomas88,

I would strongly recommend using Magmi (Magento Mass Importer): http://sourceforge.net/projects/magmi/

It is much faster compared to the normal profiles and provides a lot more functionallity.

Regards, Xephor

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top