php - Magento:可以从 shell ssh 运行导出配置文件

标签 php magento export

我正尝试从 Magento 导出 18,0000 种产品,但它卡在了

 Warning: Please do not close the window during importing/exporting data

阶段。

我发现使用 php indexer.php --reindex <code> 可以快速重新索引这么多产品

是否可以使用类似的方法来强制导出所有产品,或通过其 ID 运行数据流配置文件?

最佳答案

这将按 ID 运行导出配置文件,然后清理 dataflow_batch_?之后表。请注意,它作为命令行用户运行,并且可以作为该用户创建缓存文件,这在某些 Web 服务器配置下可能不方便。运行后清除缓存不会有什么坏处。

有一段时间,在 1.4.1.1 上,这是导出大量产品的唯一方法,直到我们发现内存泄漏并修复它。

<?php

/***********************
 * Import/Export Script to run Import/Export profile 
 * from command line or cron. Cleans entries from dataflow_batch_(import|export) table
 ***********************/

$mageconf = './app/etc/local.xml';  // Mage local.xml config
$mageapp  = './app/Mage.php';       // Mage app location
$logfile  = 'export_data.log';      // Import/Export log file

/* uncomment following block when moved to server - to ensure this page is 
 * not accessed from anywhere else 
 */

//if ($_SERVER['REMOTE_ADDR'] !== '<your server ip address>') {
//   die("You are not a cron job!");
//}


/* System -> Import/Export -> Profiles get profile ID from 
 * Magento Import/Export Profiles
 */

$profileId = 9;

/* Post run housekeeping table bloat removal
 * imports use "dataflow_batch_import" table
 * exports use "dataflow_batch_export" table
 */

$table = 'dataflow_batch_export';

/* Scan Magento local.xml file for connection information */

if (file_exists($mageconf)) {

$xml = simplexml_load_file($mageconf, NULL, LIBXML_NOCDATA);

$db['host'] = $xml->global->resources->default_setup->connection->host;
$db['name'] = $xml->global->resources->default_setup->connection->dbname;
$db['user'] = $xml->global->resources->default_setup->connection->username;
$db['pass'] = $xml->global->resources->default_setup->connection->password;
$db['pref'] = $xml->global->resources->db->table_prefix;

} 

else {
    Mage::log('Export script failed to open Mage local.xml', null, $logfile);
    exit('Failed to open Mage local.xml');
}


/* Initialize profile to be run as Magento Admin and log start of export */

require_once $mageapp;
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::log('Export ' . $profileId . ' Started.', null, $logfile);

Mage::register('current_convert_profile', $profile);
$profile->run();
$recordCount = 0;
$batchModel = Mage::getSingleton('dataflow/batch');

Mage::log('Export '.$profileId.' Complete. BatchID: '.$batchModel->getId(), null, $logfile);

echo "Export Complete. BatchID: " . $batchModel->getId() . "\n";

/* Connect to Magento database */

sleep(30);

mysql_connect($db['host'], $db['user'], $db['pass']) or die(mysql_error());
mysql_select_db($db['name']) or die(mysql_error());

/* Truncate dataflow_batch_(import|export) table for housecleaning */

$querystring = "TRUNCATE ".$db['pref'].$table;

mysql_query($querystring) or die(mysql_error());

?> 

关于php - Magento:可以从 shell ssh 运行导出配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11856841/

相关文章:

php - 将某一列的数据替换为另一列的数据 相同表名、相同列名不同数据库名

orm - 在 Magento ORM 中使用 boolean 字段

java.security.KeyStore 仅显示 p12 文件中两个证书之一

asp.net-mvc-3 - MEFContrib.MVC3:导出具有基类的 Controller

mysql - 如何导出 Mysql 表的数据,包括另一个表的引用 ID 的值

php - 如何将数组作为 get str 处理为 url?

javascript - 访问 WooCommerce 产品页面中的产品属性选定值

php - 显示和随机化 php 数组

Magento 1.6.0.0 : prevent PayPal Exporess altering my customers' shipping address

Magento 允许的货币列表