Appearance
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);
AdvWrapLegacyPasswordHashesone-off job (#966, with the #895auth_hash_migrate_tosetting it needs) added;Adv_sanitize_model::sanitizeAccount()andCustomerErasure::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 unifiedCustomerErasure(#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
AuditTrailStepKey Components
| Component | Path | Role |
|---|---|---|
AdvSanitizeGuestCustomers | ecommercen/job/libraries/AdvSanitizeGuestCustomers.php:20-33 | Job: GDPR guest data sanitization |
AdvAddTagsToCustomers | ecommercen/job/libraries/AdvAddTagsToCustomers.php | Job: daily customer tag generation |
AdvAddCustomersToAudience | ecommercen/job/libraries/AdvAddCustomersToAudience.php | Job: orchestrates audience refresh |
AdvAddCustomersToSpecificAudience | ecommercen/job/libraries/AdvAddCustomersToSpecificAudience.php | Sub-job: evaluates single audience criteria |
AdvWrapLegacyPasswordHashes | ecommercen/job/libraries/AdvWrapLegacyPasswordHashes.php:10-214 | One-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-409 | Second caller: the same selection and sanitizeAll() call as the job, run from the cron controller |
Adv_sanitize_model | ecommercen/eshop/models/Adv_sanitize_model.php:21-32 | Thin legacy entry point: sanitizeAll($userIds) delegates to CustomerErasure::erase() (:29-32), and sanitizeAccount($customerId) (:41-44) to CustomerErasure::eraseAccount() for the storefront self-deletion |
CustomerErasure | src/Domains/Customer/Customer/Erasure/CustomerErasure.php:54 | Runs 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) |
ErasureCoverage | src/Domains/Customer/Customer/Erasure/ErasureCoverage.php:36 | RETAINED list of customer-linked columns deliberately left as they are |
AdvCustomerTagModel | ecommercen/audience/models/AdvCustomerTagModel.php | Model: tag computation and storage |
Adv_customer_model | ecommercen/eshop/models/Adv_customer_model.php | Model: customer queries for sanitization targets |
| Client stubs | application/modules/job/libraries/SanitizeGuestCustomers.php, etc. | Empty extension points |
Code Flow
AdvSanitizeGuestCustomers (GDPR)
Entry: Reads
SANITIZE_INTERVALfrom registry (ESHOPgroup). If zero or negative, exits immediately.Target selection:
customer_model->getCustomersToAutoSanitize($interval)queriesshop_customerfor:is_guest = trueis_sanitized = falsedate_registered < (now - $interval months)(unix timestamp comparison)
Erasure via
sanitize_model->sanitizeAll($userIds)(AdvSanitizeGuestCustomers.php:32), which delegates toCustomerErasure::erase()(ecommercen/eshop/models/Adv_sanitize_model.php:29-32). All selected ids go to ONEerase()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):CustomerRecordStep: clears the personal columns ofshop_customer, replacesmailwith a unique undeliverable placeholder andpasswordwith a random hash, setshas_access = 0andis_sanitized = 1.OrderRecordsStep: keeps orders and gift-card orders, clears their personal fields.MarketplaceOrdersStep: the same forpublic_orders,skroutz_orders,skroutz_invoice_detailsandshopflix_orders.ReviewsStep: deletesshop_product_reviewsbycustomer_id(ReviewsStep.php:45), recomputes each affected product's rating (:47-49), and deletesshop_customer_reviewsrows matching the addresses captured before anonymisation (:51-52).OwnedRecordsStep: deletes wish-list, tags, campaigns, segment memberships, SMS-marketing consents, message log, cart, contact messages and staff notes.AddressKeyedRecordsStep: deletesshop_waiting_listandblog_commentsrows by the captured addresses (AddressKeyedRecordsStep.php:25-28).SessionsStep: deletesrefresh_tokens.NotificationRecordsStep: deletes the customer's push devices, notification consent, order messages and deliveries, and clearscustomer_idon a campaign aimed at them alone.AuditTrailStep: clears identity and payload of the customer'sREST_CUSTOMERrows inuser_audit_logs.
The full DELETED / KEPT description, the per-step columns and the failure behaviour are in CF-11 Customer Account.
Failure: if the transaction fails,
CustomerErasurethrowsErasureFailedand 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
- Entry: Computes
fromDateas yesterday's date (-1 days). - Delegation: Calls
customer_tag_model->saveCustomersTags($fromDate). - Tag generation (8 types, each gated by
CUSTOMER_TAGS_GROUPSconstant):
| Tag Type | Group ID | SQL Strategy | Source Data |
|---|---|---|---|
| Category | 2 | INSERT IGNORE | Order baskets -> product categories |
| Vendor | 1 | INSERT IGNORE | Order baskets -> product vendors |
| Registered | 3 | INSERT IGNORE | Customer is_guest=0 status |
| Last Referral | 4 | DELETE + insert_batch | Latest order's skroutz_referer |
| Country | 7 | REPLACE INTO | Order billing country (alpha_2) |
| County | 8 | REPLACE INTO | Order billing county |
| Turnover | 5 | REPLACE INTO | SUM of total_vat across fulfilled orders |
| Avg Cart | 6 | REPLACE INTO | AVG of total_vat across fulfilled orders |
- Filtering: All queries exclude guest customers (
is_guest=0) and sanitized customers (is_sanitized=0). - Date filtering: When
fromDateis provided, only processes orders/registrations from that date forward (except Turnover and Avg Cart which always recalculate globally). - Idempotency:
INSERT IGNOREprevents duplicate tags for Category/Vendor/Registered.REPLACE INTOoverwrites for Country/County/Turnover/Avg Cart. Last Referral explicitly deletes old records before inserting.
AdvAddCustomersToAudience
- Entry: Fetches all audience records via
audience_model->getRecords(). - Job creation: For each audience, creates an
AddCustomersToSpecificAudiencejob 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>}
- Queue:
- Sub-job execution:
AdvAddCustomersToSpecificAudiencevalidates the audience ID and callsaudience_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).
- Options (
:36-45):scope(customers|guests|users, defaultcustomers;:17-21,:58),dryRun,batchSize(default 500;:12,:75),fromIdandtoId. - Refuses to run unless
auth_hash_migrate_toyields a usable target (:66-72). A live run first reminds the operator to back up thepasswordcolumn: a wrapped hash cannot be turned back into the legacy hash and the job keeps no copy (:93-99). - Selection: rows whose
passwordmatches^([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). - 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 aschanged(:141-145).
Data Model
Tables
| Table | Role |
|---|---|
shop_customer | Customer records; is_guest, is_sanitized, date_registered fields control sanitization; the row is kept with personal fields cleared |
shop_order | Order records; kept, personal fields NULLed or blanked (not replaced with UUIDs) |
wishlist | Deleted for erased customers |
shop_customer_tag | Customer-tag associations (customer_id, tag_id, group_id, custom_value); deleted for erased customers |
shop_customer_campaign | Campaign tracking (prevents duplicate birthday/points emails); deleted for erased customers |
shop_customer_reviews | Review-prompt dedup log; rows matching the customer's pre-anonymisation address are deleted (ReviewsStep.php:51-52) |
shop_product_reviews | Product reviews; deleted by customer_id (ReviewsStep.php:45) |
shop_waiting_list | Waiting list entries; DELETED by the captured address (no longer email-replaced) |
| Other erasure targets | Also 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 |
audience | Audience definitions |
audience_criteria | Criteria rules for audience membership |
shop_customer_audience | Customer-audience membership |
shop_order_basket | Order line items; joined for tag computation |
product_codes | Product codes; joined for tag computation |
shop_product_category_lp | Product-category links; joined for category tags |
country | Country reference table; validates country codes |
county | County reference table; validates county codes |
Tag Group IDs (CUSTOMER_TAGS_GROUPS constant)
| Group | ID | tag_id Meaning | custom_value Meaning |
|---|---|---|---|
| VENDOR | 1 | vendor_id | null |
| CATEGORY | 2 | category_id | null |
| REGISTERED | 3 | 1 (registered) / 0 (guest) | null |
| LAST.REFERRAL | 4 | Referrer channel ID (0 = none) | null |
| TURNOVER | 5 | 0 | Total order value (decimal) |
| AVG.CART | 6 | 0 | Average cart value (decimal) |
| COUNTRY | 7 | 0 | Country alpha_2 code |
| COUNTY | 8 | 0 | County alpha code |
Configuration
Registry Settings
| Group | Key | Description |
|---|---|---|
ESHOP | SANITIZE_INTERVAL | Months after which guest accounts are sanitized (0 = disabled) |
Config File
| Key | Path | Description |
|---|---|---|
auth_hash_migrate_to | application/config/auth.php:22 | Default null. AdvWrapLegacyPasswordHashes refuses to run unless it is set to a usable scheme (password-hash-mcrypt or password-hash-argon2i, #895) |
Application Constants
| Constant | Path | Description |
|---|---|---|
CUSTOMER_TAGS_GROUPS | application/config/constants.php | Maps tag type names to group IDs |
CUSTOMER_CAMPAIGN_TYPE | application/config/constants.php | Maps campaign types: POINTS_REMAINING=1, BIRTHDAY=2 |
Job Options
| Job | Option | Type | Required | Description |
|---|---|---|---|---|
AdvSanitizeGuestCustomers | (none) | -- | -- | Interval from registry |
AdvAddTagsToCustomers | (none) | -- | -- | Uses yesterday as fromDate |
AdvAddCustomersToAudience | (none) | -- | -- | Processes all audiences |
AdvAddCustomersToSpecificAudience | audience | int | Yes | Audience ID to evaluate |
AdvWrapLegacyPasswordHashes | scope, dryRun, batchSize, fromId, toId | string, bool, int, int, int | No | See its Code Flow section |
Client Extension Points
- Job override: Create
SanitizeGuestCustomers,AddTagsToCustomers, orAddCustomersToAudienceinapplication/modules/job/libraries/extending theAdv*base class. - Sanitize model / erasure: The client stub is
application/modules/eshop/models/Sanitize_model.php.Adv_sanitize_modelno longer has protected helpers, so overriding them has no effect. A client-only table or column holding customer data must become anErasureStep(rebindCustomerErasure's$stepsin the client container) or be justified inErasureCoverage::RETAINED(src/Domains/Customer/Customer/Erasure/ErasureCoverage.php:36). See CF-11 Customer Account. - Tag model override: Override
AdvCustomerTagModelinapplication/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 intoCustomerRecordStepatsrc/Domains/Customer/container.php:28-29. - Tag groups: The
CUSTOMER_TAGS_GROUPSconstant can be extended with additional tag types if the tag model is overridden.
Business Rules
Sanitization (GDPR)
- Guest-only (for the job): The job and the cron target only guest accounts (
is_guest=true,is_sanitized=false,date_registeredolder 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). - Interval-based: The
SANITIZE_INTERVALregistry value controls the grace period in months. Setting it to 0 disables sanitization. - Cleared, not UUID-replaced: Personal columns are set to NULL; NOT NULL columns get
''or a placeholder;mailandpasswordget random values. Rows are kept to preserve referential integrity (orders are tax records). - Unconditional: The clearing does not depend on the original value being non-empty.
- Step order, one transaction: The 9 steps run in the order
CustomerRecordStep,OrderRecordsStep,MarketplaceOrdersStep,ReviewsStep,OwnedRecordsStep,AddressKeyedRecordsStep,SessionsStep,NotificationRecordsStep,AuditTrailStepinside a single transaction (src/Domains/Customer/Customer/Erasure/CustomerErasure.php:99-105, order registered atsrc/Domains/Customer/container.php:38-49). The customers' addresses are captured before the first step so the later address-keyed steps still match them. - Irreversible: Once
is_sanitized=1is set, the customer is permanently excluded from future tag generation and email campaigns.- Fail loud, no partial deletion: A failed transaction throws
ErasureFailedand nothing is deleted (CustomerErasure.php:107-109); a row not flaggedis_sanitizedafter 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, andtests/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.
- Fail loud, no partial deletion: A failed transaction throws
Tag Generation
- Daily execution: Tags are typically regenerated daily, processing only the previous day's data for incremental tags.
- Non-guest, non-sanitized only: All tag queries filter out guests and sanitized customers.
- Fulfilled orders: Turnover and Avg Cart tags only consider orders with status
SENT,PAID_SENT, orINVOICED. - Gift exclusion: Category and Vendor tags exclude gift items (
gift_id IS NULL) from order baskets. - 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
- Staggered execution: Sub-jobs are spaced 5 minutes apart to avoid overwhelming the database with concurrent criteria evaluations.
- Queue isolation: Audience jobs use the
personalizationqueue, separate from other job queues. - Single retry: Each audience sub-job allows one retry on failure.
Known Issues & Security Gaps
- The job and the cron do not handle
ErasureFailed.AdvSanitizeGuestCustomers::executeCommand()(ecommercen/job/libraries/AdvSanitizeGuestCustomers.php:32) andCronjob::sanitizeGuestCustomers()(application/controllers/Cronjob.php:406) callsanitizeAll()without a try/catch, so the exception propagates out of the cron run. - 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.
Related Flows
- CF-11 Customer Account -- Canonical description of what erasure deletes and keeps
- SY-01 Cron Framework -- Job registration and scheduling infrastructure
- SY-35 Push Notifications -- the notification tables erased by
NotificationRecordsStep - AD-04 Customer Management -- Admin customer management
- AD-22 Audience & Campaigns -- Audience definition and campaign management
- AD-46 Audience REST -- Modern REST API for audience management
- SY-12 Birthday & Points Emails -- Uses
shop_customer_campaignfor tracking - CF-32 Loyalty Points -- Points system that interacts with tag generation