删除Magento中的所有客户

时间:2011-03-11 09:50:27

标签: magento

我需要从Magento安装中删除所有客户端,因为它们的日期不好。我在开发的网站上有70,000个客户。我怎么能用SQL做到这一点?

4 个答案:

答案 0 :(得分:34)

首先进行备份并在开发服务器上进行测试! 这将删除所有客户数据,包括日志。

SET FOREIGN_KEY_CHECKS=0;
-- reset customers
TRUNCATE customer_address_entity;
TRUNCATE customer_address_entity_datetime;
TRUNCATE customer_address_entity_decimal;
TRUNCATE customer_address_entity_int;
TRUNCATE customer_address_entity_text;
TRUNCATE customer_address_entity_varchar;
TRUNCATE customer_entity;
TRUNCATE customer_entity_datetime;
TRUNCATE customer_entity_decimal;
TRUNCATE customer_entity_int;
TRUNCATE customer_entity_text;
TRUNCATE customer_entity_varchar;
TRUNCATE log_customer;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;

ALTER TABLE customer_address_entity AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_address_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE customer_entity AUTO_INCREMENT=1;
ALTER TABLE customer_entity_datetime AUTO_INCREMENT=1;
ALTER TABLE customer_entity_decimal AUTO_INCREMENT=1;
ALTER TABLE customer_entity_int AUTO_INCREMENT=1;
ALTER TABLE customer_entity_text AUTO_INCREMENT=1;
ALTER TABLE customer_entity_varchar AUTO_INCREMENT=1;
ALTER TABLE log_customer AUTO_INCREMENT=1;
ALTER TABLE log_visitor AUTO_INCREMENT=1;
ALTER TABLE log_visitor_info AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

答案 1 :(得分:12)

Mage::register('isSecureArea', true);

$customers = Mage::getModel("customer/customer")->getCollection();

foreach ($customers as $customer) {
    $customer->delete();
}

请务必知道您在做什么。如果删除不是您所需要的,您也可以禁用该客户。

答案 2 :(得分:1)

w3schools article on SQL delete可能有所帮助。为什么删除它们? - 你将失去他们所有。为什么不纠正糟糕的日期?

免责声明:请小心,如果您不知道自己在做什么,请不要尝试

答案 3 :(得分:0)

或者你只是构建一个shell脚本并执行类似的操作(不是很快,但它很干净):

 /*
 * Starter
 * */
public function run()
{
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    ini_set('memory_limit', '4096M');
    if (!$this->getArg('iknowwhatido') || $this->getArg('iknowwhatido') != 'yes') {
        $this->usageHelp();
        echo "DEACTIVATED (call it with param '-iknowwhatido yes' to make it work!) \n";
        return -1;
    }
    Mage::register('isSecureArea', true);
    $customers = Mage::getModel("customer/customer")->getCollection()->delete();
}
相关问题