| Server IP : 35.154.56.2 / Your IP : 216.73.217.116 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-0-189 6.8.0-1029-aws #31-Ubuntu SMP Wed Apr 23 18:20:04 UTC 2025 aarch64 User : ubuntu ( 1000) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /srv/shop.prima-automation.com/html/ |
Upload File : |
<?php
use Magento\Framework\App\Bootstrap;
$rootDirectory = dirname(__FILE__);
require $rootDirectory . '/app/bootstrap.php';
// Instantiate Magento so we can use it outside the framework.
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('adminhtml');
// We need to set the area to secure so that we can delete customers.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$objectManager->get('Magento\Framework\Registry')->register('isSecureArea', true);
for($i=1; $i<=44; $i++) {
echo 'Batch ' . $i . "\n";
$customerCollection = $objectManager->create('Magento\Customer\Model\ResourceModel\Customer\Collection')
->addAttributeToSelect('*')
->addAttributeToFilter([
['attribute' => 'email', 'like' => '%@qq.com'],
]);
$customerCollection->getSelect()->limit(1000);
foreach($customerCollection as $customer )
{
// Let's check if the customer has an address.
// If they do have an address, the liklihood of it being spam is low so we'll skip and not delete.
$addresses = $customer->getAddresses();
if ($addresses)
continue;
// Check if customer has an order.
// If they do have an order, the liklihood of it being spam is low so we'll skip and not delete.
$_orders = $objectManager->create('Magento\Sales\Model\ResourceModel\Order\Collection')
->AddAttributeToSelect('*')
->addAttributeToFilter(
'customer_id', $customer->getId()
)
->load();
if ($_orders->count())
continue;
// Delete customer
try {
// TODO: Create a log if you'll like to a record of deleted customers.
$customer->delete();
// break; // Uncomment this to delete one at a time for testing.
} catch (\Exception $e) {
// TODO: Handle exception. Just printing for now.
print($e->getMessage());
}
}
}