# easy-invoice/2.1.2/includes/Migration/Src/DataCleanupMigration.php

Easy Invoice – Invoice Generator, PDF Quotes &amp; Payments, version 2.1.2. 86 lines.

- Page: https://pluginprobe.com/plugins/easy-invoice/2.1.2/code/includes/Migration/Src/DataCleanupMigration.php
- Raw: https://pluginprobe.com/plugins/easy-invoice/2.1.2/raw/includes/Migration/Src/DataCleanupMigration.php
- Modified: 2025-08-19T15:19:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/easy-invoice/2.1.2/code/includes/Migration/Src/DataCleanupMigration.php#L10-L20`.

```php
<?php
/**
 * Data Cleanup Migration for Easy Invoice
 *
 * @package     EasyInvoice
 * @subpackage  Migration
 * @since       2.0.0
 */

namespace EasyInvoice\Migration\Src;

/**
 * Data Cleanup Migration Class
 *
 * Handles post-migration data management.
 *
 * @since 2.0.0
 */
class DataCleanupMigration extends AbstractMigration {

    /**
     * Migration description.
     *
     * @since 2.0.0
     * @var string
     */
    protected $description = 'Finalize migration (preserves old data)';

    /**
     * Check if cleanup is needed.
     *
     * @since 2.0.0
     * @return bool
     */
    public function is_needed(): bool {
        // Always return true as we need to finalize the migration
        return true;
    }

    /**
     * Run the cleanup.
     *
     * @since 2.0.0
     * @param array $options Cleanup options
     * @return array
     */
    public function migrate(array $options = []): array {
        $this->log('Finalizing migration (old data preserved)');

        try {
            // Mark migration as completed
            update_option('easy_invoice_migration_completed', true);
            update_option('easy_invoice_migration_completed_time', current_time('mysql'));

            // Ensure version is bumped to target version when migration finalizes
            if (defined('EASY_INVOICE_VERSION')) {
                update_option('easy_invoice_version', EASY_INVOICE_VERSION);
            }

            // Store migration summary
            $summary = [
                'completed_at' => current_time('mysql'),
                'old_data_preserved' => true,
                'version_migrated_from' => get_option('easy_invoice_version', '1.0.0'),
                'version_migrated_to' => defined('EASY_INVOICE_VERSION') ? EASY_INVOICE_VERSION : '2.0.0'
            ];
            update_option('easy_invoice_migration_summary', $summary);

            $this->log('Migration finalized successfully. Old data has been preserved.');

            return [
                'success' => true,
                'message' => 'Migration finalized successfully. Old data has been preserved.',
                'summary' => $summary
            ];

        } catch (\Exception $e) {
            $this->log('Failed to finalize migration: ' . $e->getMessage());
            return [
                'success' => false,
                'message' => 'Failed to finalize migration: ' . $e->getMessage()
            ];
        }
    }
}

```
