Skip to content

Customer Data Jobs (GDPR / Sanitize / Tags / Audience) ​

Flow ID: SY-09 | Module(s): job, eshop, audience | Complexity: High Last Updated: 2026-11-04 — 4.129.0 resync: citations re-anchored (erasure, sanitising selection); AdvWrapLegacyPasswordHashes one-off job (#966, with the #895 auth_hash_migrate_to setting it needs) added; Adv_sanitize_model::sanitizeAccount() and CustomerErasure::eraseAccount() noted; previous: 2026-10-13 — 4.127.0 resync: diagram and component table now list all 9 erasure steps (NotificationRecordsStep, #559); previous, 2026-10-02 — 4.125.0 resync: guest sanitising now runs the unified CustomerErasure (#855) — diagram, components, tables, client extension points and business rules re-written, Known Issues & Security Gaps section added

Business Overview ​

Three automated jobs manage customer data lifecycle and segmentation:

  • AdvSanitizeGuestCustomers (GDPR compliance): Erases the personal data of inactive guest accounts after a configurable interval by running the shared customer erasure (CustomerErasure), ensuring compliance with data protection regulations. What erasure deletes and keeps is described in CF-11 Customer Account.
  • AdvAddTagsToCustomers: Generates behavioral and demographic tags from order history, enabling customer segmentation for marketing and audience targeting.
  • AdvAddCustomersToAudience: Orchestrates audience membership refresh by spawning staggered sub-jobs that evaluate each audience's criteria against customer tags.

Together, these jobs form the data pipeline for customer personalization: sanitization removes stale data, tagging classifies active customers, and audience assignment groups them for campaigns.

A fourth, one-off job, AdvWrapLegacyPasswordHashes (#966), is not part of that pipeline: it replaces stored legacy password hashes with Advauth's wrapped form (see its Code Flow section below).

Architecture ​

AdvSanitizeGuestCustomers         AdvAddTagsToCustomers         AdvAddCustomersToAudience
         |                                |                              |
         v                                v                              v
  customer_model                 customer_tag_model              audience_model
  getCustomersToAutoSanitize()   saveCustomersTags()             getRecords()
         |                                |                              |
         v                                v                              v
  sanitize_model                 8 tag generation methods         For each audience:
  sanitizeAll()                  (INSERT IGNORE / REPLACE)        create AddCustomersTo
         |                                                        SpecificAudience job
         v                                                        (5-min stagger)
  CustomerErasure::erase()
  9 ordered steps, ONE transaction:
  CustomerRecordStep
  OrderRecordsStep
  MarketplaceOrdersStep
  ReviewsStep
  OwnedRecordsStep
  AddressKeyedRecordsStep
  SessionsStep
  NotificationRecordsStep
  AuditTrailStep

Key Components ​

ComponentPathRole
AdvSanitizeGuestCustomersecommercen/job/libraries/AdvSanitizeGuestCustomers.php:20-33Job: GDPR guest data sanitization
AdvAddTagsToCustomersecommercen/job/libraries/AdvAddTagsToCustomers.phpJob: daily customer tag generation
AdvAddCustomersToAudienceecommercen/job/libraries/AdvAddCustomersToAudience.phpJob: orchestrates audience refresh
AdvAddCustomersToSpecificAudienceecommercen/job/libraries/AdvAddCustomersToSpecificAudience.phpSub-job: evaluates single audience criteria
AdvWrapLegacyPasswordHashesecommercen/job/libraries/AdvWrapLegacyPasswordHashes.php:10-214One-off job that replaces stored legacy password hashes with Advauth's wrapped form. CLI php cli.php "job/WrapLegacyPasswordHashes/scope=customers&dryRun=1" (:8)
Cronjob::sanitizeGuestCustomers()application/controllers/Cronjob.php:398-409Second caller: the same selection and sanitizeAll() call as the job, run from the cron controller
Adv_sanitize_modelecommercen/eshop/models/Adv_sanitize_model.php:21-32Thin legacy entry point: sanitizeAll($userIds) delegates to CustomerErasure::erase() (:29-32), and sanitizeAccount($customerId) (:41-44) to CustomerErasure::eraseAccount() for the storefront self-deletion
CustomerErasuresrc/Domains/Customer/Customer/Erasure/CustomerErasure.php:54Runs the erasure steps in order inside one transaction: erase() (:70) and eraseAccount() (:82, which also erases the account's other registered rows with the same email) share one transaction body, eraseWithin() (:93-121)
Erasure/Step/*src/Domains/Customer/Customer/Erasure/Step/The 9 ordered steps (registered in src/Domains/Customer/container.php:28-49)
ErasureCoveragesrc/Domains/Customer/Customer/Erasure/ErasureCoverage.php:36RETAINED list of customer-linked columns deliberately left as they are
AdvCustomerTagModelecommercen/audience/models/AdvCustomerTagModel.phpModel: tag computation and storage
Adv_customer_modelecommercen/eshop/models/Adv_customer_model.phpModel: customer queries for sanitization targets
Client stubsapplication/modules/job/libraries/SanitizeGuestCustomers.php, etc.Empty extension points

Code Flow ​

AdvSanitizeGuestCustomers (GDPR) ​

  1. Entry: Reads SANITIZE_INTERVAL from registry (ESHOP group). If zero or negative, exits immediately.

  2. Target selection: customer_model->getCustomersToAutoSanitize($interval) queries shop_customer for:

    • is_guest = true
    • is_sanitized = false
    • date_registered < (now - $interval months) (unix timestamp comparison)
  3. Erasure via sanitize_model->sanitizeAll($userIds) (AdvSanitizeGuestCustomers.php:32), which delegates to CustomerErasure::erase() (ecommercen/eshop/models/Adv_sanitize_model.php:29-32). All selected ids go to ONE erase() call, which captures the customers' current addresses first and then runs the 9 steps in order inside one transaction (src/Domains/Customer/Customer/Erasure/CustomerErasure.php:101-104):

    1. CustomerRecordStep: clears the personal columns of shop_customer, replaces mail with a unique undeliverable placeholder and password with a random hash, sets has_access = 0 and is_sanitized = 1.
    2. OrderRecordsStep: keeps orders and gift-card orders, clears their personal fields.
    3. MarketplaceOrdersStep: the same for public_orders, skroutz_orders, skroutz_invoice_details and shopflix_orders.
    4. ReviewsStep: deletes shop_product_reviews by customer_id (ReviewsStep.php:45), recomputes each affected product's rating (:47-49), and deletes shop_customer_reviews rows matching the addresses captured before anonymisation (:51-52).
    5. OwnedRecordsStep: deletes wish-list, tags, campaigns, segment memberships, SMS-marketing consents, message log, cart, contact messages and staff notes.
    6. AddressKeyedRecordsStep: deletes shop_waiting_list and blog_comments rows by the captured addresses (AddressKeyedRecordsStep.php:25-28).
    7. SessionsStep: deletes refresh_tokens.
    8. NotificationRecordsStep: deletes the customer's push devices, notification consent, order messages and deliveries, and clears customer_id on a campaign aimed at them alone.
    9. AuditTrailStep: clears identity and payload of the customer's REST_CUSTOMER rows in user_audit_logs.

    The full DELETED / KEPT description, the per-step columns and the failure behaviour are in CF-11 Customer Account.

  4. Failure: if the transaction fails, CustomerErasure throws ErasureFailed and nothing is deleted (CustomerErasure.php:107-109). Neither the job (AdvSanitizeGuestCustomers.php:32) nor the cron (Cronjob.php:406) catches it; see Known Issues & Security Gaps.

AdvAddTagsToCustomers ​

  1. Entry: Computes fromDate as yesterday's date (-1 days).
  2. Delegation: Calls customer_tag_model->saveCustomersTags($fromDate).
  3. Tag generation (8 types, each gated by CUSTOMER_TAGS_GROUPS constant):
Tag TypeGroup IDSQL StrategySource Data
Category2INSERT IGNOREOrder baskets -> product categories
Vendor1INSERT IGNOREOrder baskets -> product vendors
Registered3INSERT IGNORECustomer is_guest=0 status
Last Referral4DELETE + insert_batchLatest order's skroutz_referer
Country7REPLACE INTOOrder billing country (alpha_2)
County8REPLACE INTOOrder billing county
Turnover5REPLACE INTOSUM of total_vat across fulfilled orders
Avg Cart6REPLACE INTOAVG of total_vat across fulfilled orders
  1. Filtering: All queries exclude guest customers (is_guest=0) and sanitized customers (is_sanitized=0).
  2. Date filtering: When fromDate is provided, only processes orders/registrations from that date forward (except Turnover and Avg Cart which always recalculate globally).
  3. Idempotency: INSERT IGNORE prevents duplicate tags for Category/Vendor/Registered. REPLACE INTO overwrites for Country/County/Turnover/Avg Cart. Last Referral explicitly deletes old records before inserting.

AdvAddCustomersToAudience ​

  1. Entry: Fetches all audience records via audience_model->getRecords().
  2. Job creation: For each audience, creates an AddCustomersToSpecificAudience job with:
    • Queue: personalization
    • Status: JOB_NOT_STARTED
    • Run time: staggered at 5-minute intervals from current time
    • Grace time: 60 seconds
    • Retries: 1
    • Arguments: {"audience": <audience_id>}
  3. Sub-job execution: AdvAddCustomersToSpecificAudience validates the audience ID and calls audience_model->saveCustomersToAudience($audienceId).

AdvWrapLegacyPasswordHashes (#966) ​

One-off job: replaces every legacy password hash in a scope with Advauth's wrapped form of it, so the stored value is a password_hash() hash while sign-in keeps working; a later sign-in replaces the wrapped hash with a plain one (ecommercen/job/libraries/AdvWrapLegacyPasswordHashes.php:3-9). Wrapping and verifying are in Advauth (see AD-01 Admin Auth and CF-10 Customer Auth).

  1. Options (:36-45): scope (customers | guests | users, default customers; :17-21, :58), dryRun, batchSize (default 500; :12, :75), fromId and toId.
  2. Refuses to run unless auth_hash_migrate_to yields a usable target (:66-72). A live run first reminds the operator to back up the password column: a wrapped hash cannot be turned back into the legacy hash and the job keeps no copy (:93-99).
  3. Selection: rows whose password matches ^([0-9a-f]{32}|[0-9a-f]{40})$ (:160-178). A row that matches zero or more than one accepted legacy scheme is skipped (:126-133).
  4. Write: the row is replaced through replacePasswordHash(id, expectedHash, newHash) only while it still holds the expected hash (:180-185; ecommercen/eshop/models/Adv_customer_model.php:496-509). A row that changed meanwhile counts as changed (:141-145).

Data Model ​

Tables ​

TableRole
shop_customerCustomer records; is_guest, is_sanitized, date_registered fields control sanitization; the row is kept with personal fields cleared
shop_orderOrder records; kept, personal fields NULLed or blanked (not replaced with UUIDs)
wishlistDeleted for erased customers
shop_customer_tagCustomer-tag associations (customer_id, tag_id, group_id, custom_value); deleted for erased customers
shop_customer_campaignCampaign tracking (prevents duplicate birthday/points emails); deleted for erased customers
shop_customer_reviewsReview-prompt dedup log; rows matching the customer's pre-anonymisation address are deleted (ReviewsStep.php:51-52)
shop_product_reviewsProduct reviews; deleted by customer_id (ReviewsStep.php:45)
shop_waiting_listWaiting list entries; DELETED by the captured address (no longer email-replaced)
Other erasure targetsAlso deleted: blog_comments, shop_customer_audience, shop_customer_sms_marketing, shop_customer_message_history, shop_cart, contact_emails, shop_notes, refresh_tokens, and the push-notification tables notification_device, notification_customer_consent, notification_message, notification_delivery (a single-customer notification_campaign is kept with customer_id cleared; see SY-35 Push Notifications). Kept with personal fields cleared: gift_card_orders, public_orders, skroutz_orders, skroutz_invoice_details, shopflix_orders. Identity and payload cleared on REST_CUSTOMER rows of user_audit_logs. See CF-11 Customer Account
audienceAudience definitions
audience_criteriaCriteria rules for audience membership
shop_customer_audienceCustomer-audience membership
shop_order_basketOrder line items; joined for tag computation
product_codesProduct codes; joined for tag computation
shop_product_category_lpProduct-category links; joined for category tags
countryCountry reference table; validates country codes
countyCounty reference table; validates county codes

Tag Group IDs (CUSTOMER_TAGS_GROUPS constant) ​

GroupIDtag_id Meaningcustom_value Meaning
VENDOR1vendor_idnull
CATEGORY2category_idnull
REGISTERED31 (registered) / 0 (guest)null
LAST.REFERRAL4Referrer channel ID (0 = none)null
TURNOVER50Total order value (decimal)
AVG.CART60Average cart value (decimal)
COUNTRY70Country alpha_2 code
COUNTY80County alpha code

Configuration ​

Registry Settings ​

GroupKeyDescription
ESHOPSANITIZE_INTERVALMonths after which guest accounts are sanitized (0 = disabled)

Config File ​

KeyPathDescription
auth_hash_migrate_toapplication/config/auth.php:22Default null. AdvWrapLegacyPasswordHashes refuses to run unless it is set to a usable scheme (password-hash-mcrypt or password-hash-argon2i, #895)

Application Constants ​

ConstantPathDescription
CUSTOMER_TAGS_GROUPSapplication/config/constants.phpMaps tag type names to group IDs
CUSTOMER_CAMPAIGN_TYPEapplication/config/constants.phpMaps campaign types: POINTS_REMAINING=1, BIRTHDAY=2

Job Options ​

JobOptionTypeRequiredDescription
AdvSanitizeGuestCustomers(none)----Interval from registry
AdvAddTagsToCustomers(none)----Uses yesterday as fromDate
AdvAddCustomersToAudience(none)----Processes all audiences
AdvAddCustomersToSpecificAudienceaudienceintYesAudience ID to evaluate
AdvWrapLegacyPasswordHashesscope, dryRun, batchSize, fromId, toIdstring, bool, int, int, intNoSee its Code Flow section

Client Extension Points ​

  • Job override: Create SanitizeGuestCustomers, AddTagsToCustomers, or AddCustomersToAudience in application/modules/job/libraries/ extending the Adv* base class.
  • Sanitize model / erasure: The client stub is application/modules/eshop/models/Sanitize_model.php. Adv_sanitize_model no longer has protected helpers, so overriding them has no effect. A client-only table or column holding customer data must become an ErasureStep (rebind CustomerErasure's $steps in the client container) or be justified in ErasureCoverage::RETAINED (src/Domains/Customer/Customer/Erasure/ErasureCoverage.php:36). See CF-11 Customer Account.
  • Tag model override: Override AdvCustomerTagModel in application/modules/audience/models/ to add custom tag types or modify tag computation logic.
  • Invalid email domain: The sanitized email pattern uses config_item('order.invalid.email') which can be configured per client; it is injected into CustomerRecordStep at src/Domains/Customer/container.php:28-29.
  • Tag groups: The CUSTOMER_TAGS_GROUPS constant can be extended with additional tag types if the tag model is overridden.

Business Rules ​

Sanitization (GDPR) ​

  1. Guest-only (for the job): The job and the cron target only guest accounts (is_guest=true, is_sanitized=false, date_registered older than the interval; ecommercen/eshop/models/Adv_customer_model.php:973-1001). Registered customers are never auto-sanitized. The erasure itself is not guest-only: the storefront, admin and REST paths run the same operation on registered customers (see CF-11 Customer Account).
  2. Interval-based: The SANITIZE_INTERVAL registry value controls the grace period in months. Setting it to 0 disables sanitization.
  3. Cleared, not UUID-replaced: Personal columns are set to NULL; NOT NULL columns get '' or a placeholder; mail and password get random values. Rows are kept to preserve referential integrity (orders are tax records).
  4. Unconditional: The clearing does not depend on the original value being non-empty.
  5. Step order, one transaction: The 9 steps run in the order CustomerRecordStep, OrderRecordsStep, MarketplaceOrdersStep, ReviewsStep, OwnedRecordsStep, AddressKeyedRecordsStep, SessionsStep, NotificationRecordsStep, AuditTrailStep inside a single transaction (src/Domains/Customer/Customer/Erasure/CustomerErasure.php:99-105, order registered at src/Domains/Customer/container.php:38-49). The customers' addresses are captured before the first step so the later address-keyed steps still match them.
  6. Irreversible: Once is_sanitized=1 is set, the customer is permanently excluded from future tag generation and email campaigns.
    • Fail loud, no partial deletion: A failed transaction throws ErasureFailed and nothing is deleted (CustomerErasure.php:107-109); a row not flagged is_sanitized after commit also throws (:111-120). The job and the cron do not catch it (see Known Issues & Security Gaps).
    • Completeness is enforced: ErasureCoverage (ErasureCoverage.php:36-52) lists the customer-linked personal columns deliberately left as they are, and tests/Integration/Domains/Customer/Customer/Erasure/CustomerErasureCoverageTest.php (Database suite) fails when a customer-linked personal column is neither claimed by a step nor justified there.

Tag Generation ​

  1. Daily execution: Tags are typically regenerated daily, processing only the previous day's data for incremental tags.
  2. Non-guest, non-sanitized only: All tag queries filter out guests and sanitized customers.
  3. Fulfilled orders: Turnover and Avg Cart tags only consider orders with status SENT, PAID_SENT, or INVOICED.
  4. Gift exclusion: Category and Vendor tags exclude gift items (gift_id IS NULL) from order baskets.
  5. Last Referral replace: Unlike other incremental tags, Last Referral deletes existing records before inserting (in 1000-record chunks to avoid large DELETE queries).

Audience Orchestration ​

  1. Staggered execution: Sub-jobs are spaced 5 minutes apart to avoid overwhelming the database with concurrent criteria evaluations.
  2. Queue isolation: Audience jobs use the personalization queue, separate from other job queues.
  3. Single retry: Each audience sub-job allows one retry on failure.

Known Issues & Security Gaps ​

  1. The job and the cron do not handle ErasureFailed. AdvSanitizeGuestCustomers::executeCommand() (ecommercen/job/libraries/AdvSanitizeGuestCustomers.php:32) and Cronjob::sanitizeGuestCustomers() (application/controllers/Cronjob.php:406) call sanitizeAll() without a try/catch, so the exception propagates out of the cron run.
  2. One failure rolls back the whole batch. Both callers hand every selected id to ONE erase() call (AdvSanitizeGuestCustomers.php:27-32, Cronjob.php:403-406), which runs one transaction for all of them (src/Domains/Customer/Customer/Erasure/CustomerErasure.php:99-105). A failure for any single customer therefore leaves every guest in that run unsanitized until the next run, and a persistently failing record blocks the rest.