#!/bin/bash

# Script to update adm_ table prefixes to career_ prefixes in PHP files

# Directory containing PHP files
SOURCE_DIR="/var/www/html/linways/career-api/src"

# Array of common adm_ tables to be replaced
declare -a tables=(
    "adm_weightage_quotas"
    "adm_domicile_nationality_relation"
    "adm_stages"
    "adm_form_course_stages"
    "adm_stage_actions"
    "adm_student_branch_preference"
    "adm_student_details"
    "adm_applicant"
    "adm_form_phase"
    "adm_settings"
    "adm_permission_table"
    "adm_bulk_update_data"
    "adm_form"
    "adm_admission_student_details"
    "adm_user_account_privileges"
    "adm_rule_evaluation_status_table"
    "adm_tie_rule_mark_processing_table"
    "adm_form_course_group"
    "adm_stage_rule_groups"
    "adm_batch_timings"
    "adm_batch_timing_course_mapping"
    "adm_boardstram_type"
    "adm_streams"
    "adm_stream_subjects"
    "adm_subjects"
    "adm_admit_certificates"
    "adm_admit_certificate_courses"
    "adm_admit_certificate_student_uploads"
    "adm_gd_topics"
    "adm_actions"
)

# Iterate through each PHP file in the source directory recursively
find "$SOURCE_DIR" -name "*.php" -print0 | while IFS= read -r -d '' file; do
    echo "Processing file: $file"
    
    # Replace each table name
    for table in "${tables[@]}"; do
        career_table="${table/adm_/career_}"
        # Use sed to replace table names - careful with the syntax, this is for GNU sed
        sed -i "s/$table/$career_table/g" "$file"
    done
done

echo "Table name replacement completed!"