Archive2 Documentation

Archive2 Controller Documentation

File: /controllers/archive2Controller.php

Purpose: Advanced database archiving and backup operations with selective table migration

Last Updated: December 20, 2024

Total Functions: 12+

Lines of Code: ~584

---

๐Ÿ“‹ Overview

The Archive2 Controller is an enhanced version of the archiving system that provides sophisticated database backup and restoration capabilities. It handles:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Core Management Tables

Table NamePurposeKey Columns
**newdbname**Database registrynewdbnameId, dbname
**usergroup**User group managementusergroupid, startpage
**accountstree**Chart of accountsid, parent, customName
### Data Tables (Selective Migration)

Table NamePurposeKey Columns
**product**Product masterproductId, productCatId
**productcat**Product categoriesproductCatId, productCatParent
**client**Customer dataclientid, clientarea
**supplier**Supplier datasupplierid
**employee**Employee recordsemployeeid
**bank**Banking informationbankid
**assets**Asset managementassetid, assetscatid
### Transaction Tables (Date Filtered)

Table NamePurposeKey Columns
**savedaily**Daily cash transactionssavedailydate
**clientdebtchange**Customer debt historyclientdebtchangedate
**supplierdebtchange**Supplier debt historysupplierdebtchangedate
**salaryreport**Salary paymentssalaryreportdate
**employeepersonnel**Employee recordsemployeepersonneldate
### System Tables (Always Migrated)

Table NamePurposeKey Columns
**billproperty**Bill propertiesbillpropertyid
**programsettings**System settingsprogramsettingsid
**user**System usersuserid
**usergroup**User groupsusergroupid
**store**Store/warehouse datastoreid
**save**Cash registerssaveid
---

๐Ÿ”‘ Key Functions

1. emptying() - Advanced Table Clearing

Location: Line 123

Purpose: Intelligently empty database tables with preservation options

Function Signature:

function emptying()

Process Flow:

1. Determine empty type from POST data

2. Build table exclusion list for settings preservation

3. Execute TRUNCATE commands via RedBean

4. Preserve critical system configuration

Empty Types:

Preserved Tables:

$settingsTables = array("programsettings", "billproperty", "billname", 
                       "billsettings", "properties", "relusergroupproperties", 
                       "user", "usergroup", "menuurl");

---

2. createNewDB() - Advanced Database Creation

Location: Line 147

Purpose: Create new database with intelligent data migration

Function Signature:

function createNewDB()

Process Flow:

1. Parse selected migration options

2. Build stable tables array based on selections

3. Create new database with timestamped name

4. Copy structure and migrate selected data

5. Clean up account tree references

6. Apply date filters and special options

7. Register new database in system

Migration Options:

Key Features:

// Timestamped database names
$newName = $newName . '_' . date("dmY") . '_' . date("his");

// Intelligent table grouping
$stableTablesSorted = array(
    'products' => array("product", "productcat", "productunit", ...),
    'client' => array("client", "clientarea", "typeclient", ...),
    'supplier' => array("supplier", "typesupplier", ...)
);

---

3. copyNewDBStructureFromOldOneAndFillReqTables() - Database Replication

Location: Line 436

Purpose: Advanced database structure copying with selective data migration

Function Signature:

function copyNewDBStructureFromOldOneAndFillReqTables($hostname, $username, $password, 
                                                     $sourceDatabase, $destinationDatabase, 
                                                     $stableTables)

Process Flow:

1. Establish source and destination connections

2. Create destination database if needed

3. Iterate through all source tables

4. Copy table structure using LIKE syntax

5. Migrate data for selected tables only

6. Clean account tree for non-migrated entities

7. Apply special business rules and filters

Account Tree Cleanup:

// Remove tree references for non-migrated tables
if (!in_array($tableName, $stableTables)) {
    $destinationConnection->query("DELETE FROM accountstree 
                                  WHERE id IN (SELECT $colName FROM $sourceDatabase.$tableName)");
}

---

4. Special Data Processing Functions

Cash Register Reset

if ($archiveOptionForCheck == 1) {
    $destinationConnection->query("update save set savecurrentvalue = 0");
}

Completed Checks Cleanup

if ($archiveOptionForCheck == 1) {
    $destinationConnection->query("DELETE FROM datedchecked WHERE done = 1");
}

Date-Based Filtering

$destinationConnection->query("DELETE FROM savedaily 
                              WHERE date(savedailydate) < '" . $from . "'");
$destinationConnection->query("DELETE FROM clientdebtchange 
                              WHERE date(clientdebtchangedate) < '" . $from . "'");

Category-Based Product Filtering

if ($catOptionForCheck == 1) {
    // Clean category IDs and remove unwanted products
    $destinationConnection->query("DELETE FROM productcat 
                                  WHERE productCatId NOT IN ($caiIdsToBeTransfered)");
    $destinationConnection->query("DELETE FROM product 
                                  WHERE productCatId NOT IN (SELECT productCatId FROM productcat)");
}

---

5. loadDatabases() - Database Registry

Location: Line 355

Purpose: Load available archived databases for selection

Function Signature:

function loadDatabases()

Returns: Array of database objects for dropdown population

---

6. restoreDB() - Database Switching

Location: Line 363

Purpose: Switch active database session to selected archive

Function Signature:

function restoreDB()

Process Flow:

1. Validate selected database ID

2. Load database record from registry

3. Update session variable

4. Redirect to user's start page

---

7. alterDB() - Engine Conversion

Location: Line 385

Purpose: Convert database tables between MyISAM and InnoDB engines

Function Signature:

function alterDB()

Supported Tables:

$tablesArray = array("buyandruternbill", "buybill", "sellbill", 
                    "product", "storedetail", "storemovement", 
                    "supplierdebtchange", "movementmanage");

Engine Types:

---

๐Ÿ”„ Workflows

Workflow 1: Advanced Database Creation

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Select Migration Options
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Parse Migration Selections
- Product categories and related tables
- Client/supplier data with history
- Employee records and attendance
- Banking and financial accounts
- Assets and maintenance data
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Stable Tables Array
- Start with core system tables
- Add selected module tables
- Remove duplicates and validate
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Create Destination Database
- Generate timestamped name
- Create database structure
- Establish connections
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Copy Structure and Data
FOR EACH source table:
โ”‚
โ†’ Copy table structure (CREATE TABLE LIKE)
โ”‚
โ”œโ”€โ†’ IF table in stable list:
โ”‚ โ”‚ โ””โ”€โ†’ Copy all data (INSERT INTO SELECT) โ”‚
โ”‚
โ”‚ โ””โ”€โ†’ ELSE: Create empty table โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
5Clean Account Tree References
- Find tables with tree columns
- Remove account tree entries for non-migrated data
- Maintain accounting integrity
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
6Apply Business Rules
- Reset cash register values if requested
- Remove completed checks if requested
- Apply date filters to transaction tables
- Filter products by categories if requested
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
7Register and Activate
- Register new database in system
- Update file registry
- Destroy session to force re-login
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

Workflow 2: Intelligent Table Emptying

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Select Empty Options
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Determine Empty Type
- emptyType = 0: Empty all tables
- emptyType = 1: Preserve settings tables
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Build Table List
IF preserving settings:
โ†’ Get all tables
โ”‚ โ””โ”€โ†’ Exclude settings tables โ”‚
ELSE:
โ”‚ โ””โ”€โ†’ Get all tables โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Execute TRUNCATE Operations
FOR EACH table in list:
โ”‚ โ””โ”€โ†’ Execute: TRUNCATE TABLE tablename โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)Default viewShow archive options form
`do=emptydata`Show formDisplay table emptying interface
`do=emptying``emptying()`Execute table emptying operation
`do=archive`Show formDisplay advanced archive creation form
`do=newDB``createNewDB()`Create new archived database
`do=changDB` or `do=show``loadDatabases()`Show database selection interface
`do=restoreDB``restoreDB()`Switch to selected database
`do=dbType`Show formDisplay engine conversion options
`do=alterdb``alterDB()`Convert database engine type
### Required Parameters by Action

Database Creation (do=newDB):

Table Emptying (do=emptying):

Database Restore (do=restoreDB):

Engine Conversion (do=alterdb):

---

๐Ÿงฎ Advanced Features

Category-Based Product Migration

// Parse and validate category IDs
$caiIdsToBeTransfered = $_POST['caiIdsToBeTransfered'];
$caiIdsToBeTransfered = preg_replace('/[^0-9,]/', '', $caiIdsToBeTransfered);
$caiIdsToBeTransfered = array_filter(explode(',', $caiIdsToBeTransfered));
$caiIdsToBeTransfered = implode(',', $caiIdsToBeTransfered);

// Remove unwanted categories and related data
$destinationConnection->query("DELETE FROM productcat 
                              WHERE productCatId NOT IN ($caiIdsToBeTransfered) 
                              AND productCatParent NOT IN ($caiIdsToBeTransfered)");

Account Tree Integrity Maintenance

// Find all tables with tree references
$tablesInTreeSql = "SELECT c.table_name, c.column_name
                   FROM information_schema.columns c
                   WHERE c.column_name LIKE 'tree%' 
                   AND c.column_name != 'treeType'";

// Clean up tree references for non-migrated data
foreach ($tablesInTree as $value) {
    if (!in_array($tableName, $stableTables)) {
        $destinationConnection->query("DELETE FROM accountstree 
                                      WHERE id IN (SELECT $colName FROM $sourceDatabase.$tableName)");
    }
}

Transaction-Safe Operations

mysql_query("START TRANSACTION");
mysql_query("BEGIN");
try {
    // Perform operations
    mysql_query("COMMIT");
} catch (Exception $exc) {
    mysql_query("ROLLBACK");
    echo $exc->getTraceAsString();
}

---

๐Ÿ”’ Security & Validation

Input Sanitization

// Category ID validation
$caiIdsToBeTransfered = preg_replace('/[^0-9,]/', '', $caiIdsToBeTransfered);
$caiIdsToBeTransfered = array_filter(explode(',', $caiIdsToBeTransfered));

Database Connection Security

Permission Checks

---

๐Ÿ“Š Performance Considerations

Optimization Strategies

1. Batch Operations: Copy data in bulk using INSERT INTO SELECT

2. Index Preservation: Table structure copying maintains indexes

3. Connection Management: Separate connections prevent blocking

4. Memory Efficiency: Process tables individually to avoid memory issues

Known Limitations

---

๐Ÿ› Common Issues & Troubleshooting

1. Database Creation Failures

Issue: New database creation fails

Cause: Insufficient privileges or name conflicts

Debug:

-- Check database privileges
SHOW GRANTS FOR CURRENT_USER;

-- Check existing databases
SHOW DATABASES LIKE 'pattern%';

2. Account Tree Inconsistencies

Issue: Broken account references after migration

Cause: Missing tree cleanup for non-migrated entities

Fix: Run account tree validation queries and manual cleanup

3. Category Filter Issues

Issue: Products disappear unexpectedly

Cause: Parent category relationships not preserved

Solution: Include all parent categories in migration list

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur