Michał Wejwoda Michał Wejwoda - 1 year ago 70
PHP Question

Automatic activation dataflow profile by cron

I want to run my dataflow import profile by cron without manipulation in Cron.php or crontab files. My profile is working, when I start it manually.
This adapter imports data about product from csv file.
I'm trying to run this profile by :


But I have no effect after cron action. Run method isn't work correctly.
File is in the correct location. Id of profile is correct, profile was loaded.


I found answer. If you want to run import profile, you should use this code after $profile->run(); :

        $batchModel = Mage::getSingleton('dataflow/batch');
        $batchImportModel = $batchModel->getBatchImportModel();
        $adapter = $batchModel->getAdapter();
        $importIds = $batchImportModel->getIdCollection();

        foreach ($importIds as $importId) {
            try {
                $importData = $batchImportModel->getBatchData();
            } catch (Exception $e) {
                Mage::log("Exception : " . $e);

        if (method_exists($adapter, 'getEventPrefix')) {

            // Event to process rules relationships after import
            Mage::dispatchEvent($adapter->getEventPrefix() . '_finish_before', array(
                'adapter' => $adapter

            // Clear affected ids for possible reuse