Skip to content

Instantly share code, notes, and snippets.

@blessani
Last active April 16, 2019 15:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save blessani/e700e35d9ecbade2021c8e0f6d95a8c0 to your computer and use it in GitHub Desktop.
Save blessani/e700e35d9ecbade2021c8e0f6d95a8c0 to your computer and use it in GitHub Desktop.
Magento 1 Customer Delete Shell Class
<?php
require_once 'abstract.php';
class Mage_Shell_Customer extends Mage_Shell_Abstract
{
/**
* Run script
*
*/
public function run()
{
$collection = Mage::getModel('customer/customer')->getCollection()
->addAttributeToSelect('firstname')
->addAttributeToSelect('lastname')
->addAttributeToSelect('email');
if (!$this->getArg('delete') && !$this->getArg('print')) {
printf("ERROR: Either --delete or --print must be specified\n");
exit(1);
}
if ($name = $this->getArg('firstname'))
$collection->addAttributeToFilter('firstname', array('like' => $name));
if ($name = $this->getArg('lastname'))
$collection->addAttributeToFilter('lastname', array('like' => $name));
if ($email = $this->getArg('email'))
$collection->addAttributeToFilter('email', array('like' => $email));
foreach ($collection as $item) {
if ($this->getArg('delete')) {
printf("Deleting ID:%s\n", $item->getId());
$item->delete();
} else {
printf("%s\t%s\n",
str_pad($item->getFirstname() . $item->getLastname(), 50),
$item->getEmail()
);
}
}
}
/**
* Retrieve Usage Help Message
*
*/
public function usageHelp()
{
return <<<USAGE
Usage: php -f customer.php -- [options]
--firstname Filter by first name
--lastname Filter by last name
--email Filter by email
--delete Delete matching users
--print Display matching users
USAGE;
}
}
$customer = new Mage_Shell_Customer();
$customer->run();
@mehdichaouch
Copy link

mehdichaouch commented Sep 26, 2018

Cleaning up created users

Once you've got your mechanisms in place to help prevent further SPAM registrations, its time to clean up the records created. Use this quick shell script for Magento that you can download.

  1. Download the gist to the Magento shell directory
    wget --no-check-certificate https://gist.githubusercontent.com/blessani/e700e35d9ecbade2021c8e0f6d95a8c0/raw/28c530b727999a2f7f66e0372eae45bc3ab7c551/customer.php -qO shell/customer.php

  2. Execute the script in dry run (print only) using matching data you observed in the Magento admin "Manage customers" pane,
    php shell/customer.php --lastname "%drive.google.com%" --print

  3. After reviewing the results, re-run the command with the delete option
    php shell/customer.php --lastname "%drive.google.com%" --delete

src: https://www.sonassi.fr/blog/combating-spam-user-registration-magento#cleaning-up-created-users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment