-
Notifications
You must be signed in to change notification settings - Fork 6
/
deleteCustomer.php
76 lines (60 loc) · 2.72 KB
/
deleteCustomer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
require dirname(__FILE__) . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory;
use Magento\Customer\Api\CustomerRepositoryInterface;
class Outslide extends \Magento\Framework\App\Http
implements \Magento\Framework\AppInterface {
public function launch()
{
$myClass = $this->_objectManager->create('DeleteCustomer');
$myClass->deleteCustomers();
return $this->_response;
}
}
class DeleteCustomer{
protected $_objectManager;
protected $_registry;
/**
* @var CustomerRepositoryInterface
*/
protected $customerRepository;
public function __construct(
\Magento\Framework\Registry $registry,
CollectionFactory $collectionFactory,
CustomerRepositoryInterface $customerRepository
)
{
$this->_registry = $registry;
$this->customerRepository = $customerRepository;
$this->_objectManager = \Magento\Framework\App\ObjectManager::getInstance();
}
public function deleteCustomers() {
$this->_registry->register("isSecureArea", true);
$limit = 10000;
$collection = $this->_objectManager->create('\Magento\Customer\Model\Customer');
$customers = $collection->getCollection()
->addAttributeToFilter("email", ["like" => "%@qq.com"])
->addAttributeToSort('entity_id', 'DESC')
// ->addAttributeToFilter("email", ["like" => "%@sina.com"])
// ->addAttributeToFilter("email", ["like" => "%@yahoo.com.cn"])
// ->addAttributeToFilter("email", ["like" => "%@163.com"])
// ->addAttributeToFilter("email", ["like" => "%@139.com"])
// ->addAttributeToFilter("email", ["like" => "%@126.com"])
// ->addAttributeToFilter("firstname", ["like" => "%www.%"])
// ->addAttributeToFilter("firstname", ["like" => "%http.%"])
// ->addAttributeToFilter("lastname", ["like" => "%dkhdeiqknp%"])
->setPageSize($limit)->setCurPage(1);
$customersDeleted = 0;
foreach ($customers as $customer) {
$this->customerRepository->deleteById($customer->getId());
$customersDeleted++;
}
if ($customersDeleted) {
echo __('A total of %1 record(s) were deleted.', $customersDeleted);
}
}
}
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Outslide');
$bootstrap->run($app);