Run a profile from command line?

0

I have created an advanced data profile with the below actions xml. It takes a csv of order ids and my adapter marks the orders as complete. When run through the admin panel, this works fine. However, I am wanting to automate the procedure (as the csv will be updated on a semi-regular basis) so have followed the instructions on Magento Export/Import from the command line (see below for my code).

When I run this code from the command line I am getting the output “Order status update complete. BatchID: nn”, however the orders that I am specifying are not being updated. When I put var_dumps and dies into my adapter nothing happens. When I do var_dumps into the below code I can see that it has loaded the correct profile, and that the actions xml is being read correctly.

How do I get the below code to run my adapter when it is run from the command line?

Actions XML

<action type="dataflow/convert_adapter_io" method="load">
    <var name="type">file</var>
    <var name="path">var/import</var>
    <var name="filename"><![CDATA[filename.csv]]></var>
    <var name="format"><![CDATA[csv]]></var>
</action>
<action type="dataflow/convert_parser_csv" method="parse">
    <var name="delimiter"><![CDATA[,]]></var>
    <var name="enclose"><![CDATA["]]></var>
    <var name="fieldnames">true</var>
    <var name="store"><![CDATA[0]]></var>
    <var name="number_of_records">1</var>
    <var name="decimal_separator"><![CDATA[.]]></var>
    <var name="adapter">mynamespace_mymodule/convert_adapter_store</var>
    <var name="method">saveRow</var>
</action>

Run Profile Code

<?php
//THIS SCRIPT JUST INITIALS THE PROFILE TO BE RUN VIA MAGENTO ADMIN "RUN PROFILE IN POPUP".
//Its the same thing as click just via this file that you can run via cron

// SYSTEM - IMPORT/EXPORT - ADVANCED PROFILES <-- you need to go into your magento admin and grab the exact profile ID
$profileId = 9; 

require_once 'public_html/app/Mage.php';
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::register('current_convert_profile', $profile);
$profile->run();
$batchModel = Mage::getSingleton('dataflow/batch');
echo "ORDER STATUS UPDATE COMPLETE. BATCHID: " . $batchModel->getId();

Link: Run a profile from command line?
Source: Stack Magento

Share.

About Author

Leave A Reply