Comment to 'UNA 14 Timeline Cleanup Script – Expert Review Requested'
  • Below is an exact “safest” WHERE clause tailored to your schema and your distribution results. It is conservative: it deletes only real user timeline posts, skips system-generated events, skips pinned/sticked/promoted, and only targets active/visible items.

    What we will delete (whitelist)

    From your distribution table, the only thing that represents the “native Timeline post” objects is:

    • type = 'timeline_common_post' (action is blank / NULL in your data)

    We will not touch:

    • comment (65639) — these are comment events
    • timeline_common_repost (3130) — reposts
    • module-generated “added” events: bx_posts, bx_photos, bx_videos, bx_ads, bx_groups, bx_polls
    • profile changes: bx_persons actions

    Safest WHERE clause

    Use this in your cleanup query:

    WHERE `type` = 'timeline_common_post'
      AND (`action` IS NULL OR `action` = '')
      AND `date` < ?
      AND `system` = 0
      AND `status` = 'active'
      AND `status_admin` = 'active'
      AND `active` = 1
      AND `pinned` = 0
      AND `sticked` = 0
      AND `promoted` = 0
      AND `owner_id` > 0
      AND `object_id` > 0
    

    Full query drop-in (recommended)

    Replace your current selection block with:

    $eventIds = $db->getColumn("
        SELECT `id`
        FROM `bx_timeline_events`
        WHERE `type` = 'timeline_common_post'
          AND (`action` IS NULL OR `action` = '')
          AND `date` < ?
          AND `system` = 0
          AND `status` = 'active'
          AND `status_admin` = 'active'
          AND `active` = 1
          AND `pinned` = 0
          AND `sticked` = 0
          AND `promoted` = 0
          AND `owner_id` > 0
          AND `object_id` > 0
        ORDER BY `date` ASC
        LIMIT ?
    ", [$cutoff, $batch]);
    

    Why this is the safest

    • Type/action whitelist ensures you only delete the Timeline’s own “common post” items, not module activity events or comments/reposts.
    • system = 0 prevents removal of “system” entries.
    • status/status_admin/active ensure you only remove content that is currently treated as active/visible by UNA.
    • pinned/sticked/promoted = 0 avoids deleting highlighted content.
    • owner_id/object_id > 0 avoids orphan/system rows.

    One optional safety improvement (recommended)

    Run a preview query in phpMyAdmin before going live:

    SELECT `id`, `owner_id`, `date`, `type`, `action`, `system`, `status`, `status_admin`,
           `active`, `pinned`, `sticked`, `promoted`
    FROM `bx_timeline_events`
    WHERE `type` = 'timeline_common_post'
      AND (`action` IS NULL OR `action` = '')
      AND `date` < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 60 DAY))
      AND `system` = 0
      AND `status` = 'active'
      AND `status_admin` = 'active'
      AND `active` = 1
      AND `pinned` = 0
      AND `sticked` = 0
      AND `promoted` = 0
    ORDER BY `date` ASC
    LIMIT 50;
    

    If those 50 rows look exactly like “old timeline posts you truly want gone,” you are good to proceed.

    If you want to also delete reposts safely later, we can add a second pass with type='timeline_common_repost' but I would keep that separate from the first run.

    You're very kind.