【问题标题】:Remove all Customers in Magento删除 Magento 中的所有客户
【发布时间】:2011-07-13 09:13:00
【问题描述】:

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

【问题讨论】:

    标签: sql magento


    【解决方案1】:

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

    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;
    

    【讨论】:

    • Magento 的表结构可能会发生变化,并且可能会受到扩展的影响。在新版本的 magento 上执行此操作时,我建议谨慎。
    • 我在 MySQL 运行上述查询时遇到错误:Invalid default value for 'created_at'。在开头添加这一行可以解决:/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;(更多:stackoverflow.com/a/23147829/3763649
    • 注意:如果使用 phpmyadmin 4.6+,您可以删除“set foreign_key_checks=”语句并简单地取消选中 SQL 部分中的“启用外键复选框”。
    【解决方案2】:
    Mage::register('isSecureArea', true);
    
    $customers = Mage::getModel("customer/customer")->getCollection();
    
    foreach ($customers as $customer) {
        $customer->delete();
    }
    

    一定要知道你在做什么。如果删除不是你需要的,你也可以禁用客户。

    【讨论】:

      【解决方案3】:

      或者您只是构建一个 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();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-13
        相关资源
        最近更新 更多