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 77 78 79 
<?php
/* --------------------------------------------------------------
   CustomerDeleter.inc.php 2017-12-18
   Gambio GmbH
   http://www.gambio.de
   Copyright (c) 2017 Gambio GmbH
   Released under the GNU General Public License (Version 2)
   [http://www.gnu.org/licenses/gpl-2.0.html]
   --------------------------------------------------------------
*/

MainFactory::load_class('CustomerDeleterInterface');

/**
 * Class CustomerDeleter
 *
 * This class is used for deleting customer data.
 *
 * @category   System
 * @package    Customer
 * @implements CustomerDeleterInterface
 */
class CustomerDeleter implements CustomerDeleterInterface
{
    /**
     * Query builder.
     * @var CI_DB_query_builder
     */
    protected $db;
    

    /**
     * Constructor of the class CustomerDeleter
     *
     * @param CI_DB_query_builder $dbQueryBuilder Query builder.
     */
    public function __construct(CI_DB_query_builder $dbQueryBuilder)
    {
        $this->db = $dbQueryBuilder;
    }


    /**
     * Deletes all data of a specific customer.
     *
     * @param CustomerInterface $customer Customer.
     *
     * @return CustomerDeleter Same instance for method chaining.
     */
    public function delete(CustomerInterface $customer)
    {
        $customerId = (int)(string)$customer->getId();
        $this->db->delete('admin_access', array('customers_id' => $customerId));
        $this->db->delete('admin_access_users', array('customer_id' => $customerId));
        $this->db->delete('customers', array('customers_id' => $customerId));
        $this->db->delete('customers_basket', array('customers_id' => $customerId));
        $this->db->delete('customers_basket_attributes', array('customers_id' => $customerId));
        $this->db->delete('customers_info', array('customers_info_id' => $customerId));
        $this->db->delete('customers_ip', array('customers_id' => $customerId));
        $this->db->delete('customers_status_history', array('customers_id' => $customerId));
        $this->db->delete('customers_wishlist', array('customers_id' => $customerId));
        $this->db->delete('customers_wishlist_attributes', array('customers_id' => $customerId));
        $this->db->delete('coupon_gv_customer', array('customer_id' => $customerId));
        $this->db->delete('coupon_gv_queue', array('customer_id' => $customerId));
        $this->db->delete('coupon_redeem_track', array('customer_id' => $customerId));
        $this->db->delete('gm_gprint_cart_elements', array('customers_id' => $customerId));
        $this->db->delete('gm_gprint_wishlist_elements', array('customers_id' => $customerId));
        $this->db->delete('products_notifications', array('customers_id' => $customerId));
        $this->db->delete('whos_online', array('customer_id' => $customerId));

        $this->db->update('coupon_redeem_track', array('customer_id' => 0), array('customer_id' => $customerId));
        $this->db->update('gm_gprint_uploads', array('customers_id' => 0), array('customers_id' => $customerId));
        $this->db->update('newsletter_recipients', array('customers_id' => 0), array('customers_id' => $customerId));
        $this->db->update('orders', array('customers_id' => 0), array('customers_id' => $customerId));
        $this->db->update('withdrawals', array('customer_id' => 0), array('customer_id' => $customerId));

        return $this;
    }
}