I want to remove all customers that have the following string in their first name: 'http://' (spam customers that have links in their first names)
.
Is there a good way to remove these programmatically using a setup script in Magento 2?
There must be a better way than to get the filtered customer collection and delete them one by one right?
--------- UPDATE -----------
I am currently using the following method. It works, but it takes quite some time:
/**
* Remove Customers with links (http:// or https://) in their names
*/
private function removeFakeCustomers()
{
$this->registry->register('isSecureArea', true);
$customers = $this->customerFactory->create();
$customers->addFieldToFilter(
'firstname',
[
['like' => '%http://%'],
['like' => 'http://%'],
['like' => '%https://%'],
['like' => 'https://%']
]
);
if (!$customers) {
return;
}
echo 'Start removing fake customers...';
foreach ($customers as $customer) {
$customer->delete();
}
echo 'Fake Customers removed...';
}
customer_entity
WHEREfirstname
like '%http://%'; You can try this. This is just an example. It will not take much time. If still it takes time then you can try DELETE FROMcustomer_entity
WHEREfirstname
like '%http://%' limit 5000; – Sukumar Gorai Sep 13 '18 at 12:34