magento: is there a way to “run profile” with cron?

后端 未结 3 1312
陌清茗
陌清茗 2021-01-25 11:27

I have an export profile on magento 1.6 and I can run it manually (\"Run profile in popup\"), but I need it to run automatically every day. Is there a way to set up a cron job t

相关标签:
3条回答
  • 2021-01-25 12:08

    I used the following taken from (note: broken link, code is copied below):

    http://www.premasolutions.com/content/magento-dataflow-exportimport-form-command-line

    <?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
    $profileId = 8; // SYSTEM - IMPORT/EXPORT - ADVANCED PROFILES <-- you need to go into your magento admin and grab the exact profile ID
       
    require_once '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();
    $recordCount = 0;
    $batchModel = Mage::getSingleton('dataflow/batch');
    echo "EXPORT COMPLETE. BATCHID: " . $batchModel->getId();
    

    It worked properly on 1.5.x (not tested yet on 1.6.x, sorry).

    If it works, it's only matter of scheduling a cron job to call the script automatically.

    Regards, Alessandro

    0 讨论(0)
  • 2021-01-25 12:27

    There are other things to consider, but in short, all you need is

    Mage::getModel("dataflow/profile")
        ->load(5) // id of the desired profile
        ->run();
    
    0 讨论(0)
  • 2021-01-25 12:34

    Here's a cron script from 1.4.x.x that will run a profile. Export Profile Script

    In 1.4.x.x and later, given proper resources, the final part where it opens the dataflow_batch_export table and truncates it may be commented out if your system is properly cleaning out the contents on completion of the export. There for a while, we were having problems with dataflow_batch_import and dataflow_batch_export table growth due to failure to clean up after either operation because a memory leak interrupted their proper operations.

    0 讨论(0)
提交回复
热议问题