upskill-event-manager/scripts/README-import.md
bengizmo e608a15c74 fix: Ensure import script sets correct hvac_trainer role for all users
- Add explicit role setting in update_user() method for existing users
- Fix issue where existing users kept their old roles during import
- Update both CLI and web-based import scripts
- Update documentation to reflect role handling improvement

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-18 12:26:06 -03:00

4.1 KiB

HVAC Trainer CSV Import

This script imports trainer data from the Formidable Forms CSV export into the current HVAC Upskill platform user database.

Usage

Download the CSV File First

# Download the CSV file to your local machine
curl -O "https://upskill-staging.measurequick.com/wp-content/uploads/2025/06/250618120131_user-registration_formidable_entries.csv"

Run Import Script

# Dry run (shows what would be imported without making changes)
php scripts/import-trainer-csv.php 250618120131_user-registration_formidable_entries.csv --dry-run

# Actual import
php scripts/import-trainer-csv.php 250618120131_user-registration_formidable_entries.csv

What the Script Does

User Creation

  • Creates new WordPress users with hvac_trainer role
  • Updates existing users and ensures they have hvac_trainer role
  • Maps CSV fields to current database schema
  • Sets users as approved (pre-approved from previous system)
  • Generates secure random passwords
  • Sends welcome emails with password reset links

Field Mappings

CSV Field Database Field Notes
Name first_name Direct mapping
Last Name last_name Direct mapping
Work Email user_email, user_login Primary identifier
Country user_country Direct mapping
State user_state Direct mapping
Personal Accreditations personal_accreditation Direct mapping
Company Name business_name Direct mapping
Company Website business_website Direct mapping
Phone Number business_phone Direct mapping
Trainer Details application_details Background info
Training Target training_audience Converted to array
Organization Type business_type Mapped values
Profile Picture profile_image_id URL mapping only

Image Handling

  • Does NOT download images from staging URLs
  • Maps staging URLs (upskill-staging.measurequick.com) to production URLs
  • Searches for existing attachments by URL
  • Sets profile_image_id if attachment found
  • Logs warnings for missing images

Additional Features

  • Creates Events Calendar organizer profiles
  • Creates venue profiles for businesses
  • Handles duplicate users (updates existing)
  • Comprehensive error handling and logging
  • Import statistics summary

Important Notes

Before Running

  1. Backup your database - This script creates/modifies user data
  2. Run dry-run first - Always test with --dry-run flag
  3. Check production domain - Update the domain mapping in map_profile_image() method if needed

Image URL Mapping

The script expects images to already exist on your current instance but with staging URLs in the CSV. It converts:

upskill-staging.measurequick.com → upskill.measurequick.com

Update line 169 in the script if your production domain is different.

Generated Passwords

  • Users get randomly generated secure passwords
  • Welcome emails include password reset links
  • Users must reset passwords on first login

Organizer/Venue Creation

  • Creates Events Calendar organizer profiles for each trainer
  • Creates venue profiles for trainers with company names
  • Links profiles to user accounts via meta fields

Troubleshooting

Common Issues

  1. Missing images: Check if images exist on current instance
  2. Duplicate usernames: Script auto-handles with numbered suffixes
  3. Email sending: Ensure WordPress mail is configured
  4. WordPress not found: Run from WordPress root directory

Error Messages

  • Could not load WordPress: Run from correct directory
  • CSV file not found: Check file path
  • Could not find attachment: Image doesn't exist on current instance

Output Example

Starting import from: trainers.csv
----------------------------------------
Creating new user: trainer1@example.com
Creating new user: trainer2@example.com
Updating existing user: existing@example.com
Warning: Could not find attachment for URL: https://...

========================================
Import Complete!
========================================
Processed: 25
Created: 23
Updated: 2
Skipped: 0
Errors: 0