Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Last active May 16, 2017 22:11
Show Gist options
  • Save tegansnyder/1595961ee572739de079 to your computer and use it in GitHub Desktop.
Save tegansnyder/1595961ee572739de079 to your computer and use it in GitHub Desktop.
Programmatically running a Magento Dataflow Profile export and appending timestamp to filename
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
ini_set('memory_limit', '2048M');
$profile_id = 44;
$profile = Mage::getModel("dataflow/profile")->load($profile_id);
$admin_user = Mage::getModel('admin/user')->setUserId(0);
Mage::getSingleton('admin/session')->setUser($admin_user);
$profile->load($profile_id);
if (!$profile->getId()) {
echo 'Error';
exit();
}
$filename = 'es-catalog_backup-' . time() . '.csv';
$gui_data = $profile->getGuiData();
$gui_data['file']['filename'] = $filename;
$profile->setGuiData($gui_data);
$profile->save();
$profile = Mage::getModel("dataflow/profile")->load($profile_id);
Mage::register('current_convert_profile', $profile);
$profile->run();
@ihsanberahim
Copy link

how to select certain fields only?

For now i follow this

@maurisource
Copy link

Thanks for this. Very useful. FYI don't forget to mention your dataflow profile id you wish to export on this line
$profile_id = 44;

@praful-rajput
Copy link

I am facing following issue.

PHP Fatal error: Call to a member function setDataflowProfile() on a non-object in /chroot/home/helllooo/heloooo.com/html/app/code/core/Mage/Dataflow/Model/Profile.php on line 204

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment