# Deployment Guide

This guide covers deploying the HVAC Trainer Network Events plugin to development and production environments.

## Quick Start

```bash
# Deploy to development
./Users/ben/dev/upskill-event-manager/wordpress-dev/deploy.sh --config deploy-config.sh

# Deploy and run tests
./Users/ben/dev/upskill-event-manager/wordpress-dev/deploy.sh --config deploy-config.sh --run-tests

# Deploy to production
./Users/ben/dev/upskill-event-manager/wordpress-dev/deploy.sh --config deploy-config-production.sh
```

## Plugin Dependencies

The HVAC Trainer Network Events plugin requires the following plugins:

1. The Events Calendar (6.10.2 or higher)
2. The Events Calendar Pro (7.4.2 or higher)
3. Event Tickets (5.19.3 or higher)
4. Event Tickets Plus (6.2.0 or higher)
5. The Events Calendar: Community Events (latest version)
6. Spectra Pro (2.0.0 or higher)
7. Premium Starter Templates (4.4.14 or higher)
8. Essential Blocks (5.3.2 or higher)

**Important Notes:**
- Plugin versions are managed separately from deployment
- Do not update plugins as part of deployment or testing
- Plugin updates should be tested separately in a staging environment
- Use the plugin management system of your hosting environment for updates

## Configuration Files

### Development Configuration
File: `deploy-config.sh`
```bash
REMOTE_HOST="upskill_wordpress"
REMOTE_USER="root"
WP_PATH="/var/www/html/"
PLUGIN_SLUG="network-events"
WP_CLI_PATH="wp"
PURGE_BREEZE_CACHE=false
USE_ROOT=true
```

### Production Configuration
File: `deploy-config-production.sh`
- Contains production-specific settings
- Includes additional security measures
- Requires SSH key configuration

## Deployment Process

1. **Pre-deployment Checks**
   - Verify dependencies
   - Run tests
   - Check file permissions

2. **Deployment Steps**
   - Package plugin files
   - Transfer to target environment
   - Update WordPress configuration
   - Clear caches

3. **Post-deployment Verification**
   - Check plugin activation
   - Verify functionality
   - Monitor error logs

## Development Environment

### Setup
```bash
# Start development environment
cd /Users/ben/dev/upskill-event-manager/wordpress-dev
./Users/ben/dev/upskill-event-manager/wordpress-dev/manage-env.sh start

# Stop development environment
./Users/ben/dev/upskill-event-manager/wordpress-dev/manage-env.sh stop

# Reset development environment
./Users/ben/dev/upskill-event-manager/wordpress-dev/manage-env.sh reset
```


## Production Environment

### Requirements
- SSH access to production server
- WordPress admin credentials
- Appropriate file permissions

### Deployment Steps
1. Configure SSH access
2. Update production configuration
3. Run deployment script
4. Verify deployment
## Staging Environment

The staging environment on Cloudways serves as a pre-production testing platform. It includes dedicated configuration, deployment, and testing procedures.

### Environment Setup

1. **Configure Environment Variables**
```bash
# Required in .env file
UPSKILL_STAGING_URL=https://wordpress-974670-5399585.cloudwaysapps.com/
UPSKILL_STAGING_IP=146.190.76.204
UPSKILL_STAGING_SSH_USER=roodev
UPSKILL_STAGING_PASS=<password>
UPSKILL_STAGING_PATH=/home/974670.cloudwaysapps.com/uberrxmprk/public_html
UPSKILL_STAGING_DB_NAME=uberrxmprk
UPSKILL_STAGING_DB_USER=uberrxmprk
UPSKILL_STAGING_DB_PASSWORD=<password>
```

2. **Deploy Configuration**
```bash
# Deploy configuration files
./bin/deploy-config-staging.sh

# Verify deployment
./bin/verify-staging.sh
```

3. **Configure Test Environment**
```bash
# Set up test configuration
./bin/configure-staging-tests.sh

# Run initial tests
./bin/run-staging-unit-tests.sh
```

### Deployment Process

1. **Pre-deployment**
```bash
# Verify staging environment
./bin/verify-staging.sh

# Configure test environment
./bin/configure-staging-tests.sh

# Run tests before deployment
./bin/run-staging-tests.sh
```

2. **Deploy Plugin**
```bash
# Deploy plugin files
./bin/deploy-plugin.sh --config wordpress-dev/deploy-config-staging.sh

# Verify deployment
./bin/verify-staging.sh --deployment
```

3. **Post-deployment**
```bash
# Run tests after deployment
./bin/run-staging-tests.sh

# Check logs
./bin/verify-staging.sh --logs
```

### Configuration Files

1. **deploy-config-staging.sh**
```bash
REMOTE_HOST="${UPSKILL_STAGING_IP}"
REMOTE_USER="${UPSKILL_STAGING_SSH_USER}"
REMOTE_PATH_BASE="/home/974670.cloudwaysapps.com/uberrxmprk/public_html"
PLUGIN_SLUG="hvac-community-events"
REMOTE_PLUGIN_PATH="${REMOTE_PATH_BASE}/wp-content/plugins/${PLUGIN_SLUG}/"
LOCAL_PLUGIN_PATH="../wp-content/plugins/${PLUGIN_SLUG}/"
```

2. **wp-tests-config-staging.php**
```php
define('DB_NAME', 'uberrxmprk');
define('DB_USER', 'uberrxmprk');
define('DB_PASSWORD', 'vRVr7GJCAZ');
define('DB_HOST', 'localhost');
define('ABSPATH', '/home/974670.cloudwaysapps.com/uberrxmprk/public_html/');
```

### Staging-Specific Tools

1. **Configuration**
- `deploy-config-staging.sh`: Deployment configuration
- `configure-staging-tests.sh`: Test environment setup
- `wp-tests-config-staging.php`: WordPress test configuration

2. **Deployment**
- `deploy-plugin.sh`: Deploy plugin files
- `deploy-config-staging.sh`: Deploy configuration files

3. **Testing**
- `run-staging-unit-tests.sh`: Run unit tests
- `run-staging-tests.sh`: Run all test suites

4. **Verification**
- `verify-staging.sh`: Environment verification
- `sync-staging.sh`: Data synchronization

### Staging Environment Maintenance

1. **Regular Tasks**
- Run tests weekly
- Monitor error logs
- Update test data
- Verify plugin functionality

2. **Data Management**
```bash
# Sync data from staging
./bin/sync-staging.sh

# Deploy fresh test data
./bin/deploy-config-staging.sh --test-data
```

3. **Monitoring**
```bash
# Check logs
./bin/verify-staging.sh --logs

# Monitor performance
./bin/verify-staging.sh --performance
```

## Troubleshooting

### Development Environment Issues

1. **Permission Errors**
   ```bash
   # Fix permissions
   ./Users/ben/dev/upskill-event-manager/manage-env.sh fix-permissions
   ```

2. **Cache Issues**
   ```bash
   # Clear WordPress cache
   wp cache flush
   ```

3. **Plugin Activation Issues**
   ```bash
   # Check plugin status
   wp plugin list
   ```

### Staging Environment Issues

1. **SSH Connection Issues**
   ```bash
   # Test SSH connection
   sshpass -p "$UPSKILL_STAGING_PASS" ssh "$UPSKILL_STAGING_SSH_USER@$UPSKILL_STAGING_IP" "echo 'Connection test'"

   # Check SSH configuration
   ./bin/verify-staging.sh --ssh

   # Verify credentials
   env | grep UPSKILL_STAGING
   ```

2. **Test Environment Issues**
   ```bash
   # Reconfigure test environment
   ./bin/configure-staging-tests.sh

   # Check test configuration
   ./bin/verify-staging.sh --test-env

   # View test logs
   ./bin/verify-staging.sh --logs
   ```

3. **Database Connection Issues**
   ```bash
   # Test database connection
   mysql -h "$UPSKILL_STAGING_IP" -u "$UPSKILL_STAGING_DB_USER" -p"$UPSKILL_STAGING_DB_PASSWORD" "$UPSKILL_STAGING_DB_NAME" -e "SELECT 1"

   # Verify database configuration
   ./bin/verify-staging.sh --database

   # Check database permissions
   ./bin/verify-staging.sh --permissions
   ```

4. **Deployment Issues**
   ```bash
   # Check deployment status
   ./bin/verify-staging.sh --deployment

   # Verify file permissions
   ./bin/verify-staging.sh --permissions

   # Check plugin status
   ./bin/verify-staging.sh --plugin
   ```

5. **Test Failures**
   ```bash
   # Run specific test
   ./bin/run-staging-unit-tests.sh --filter=test_name

   # Debug test environment
   ./bin/verify-staging.sh --test-env

   # View detailed test output
   ./bin/run-staging-unit-tests.sh --debug
   ```

6. **Performance Issues**
   ```bash
   # Check server resources
   ./bin/verify-staging.sh --performance

   # Monitor PHP processes
   ./bin/verify-staging.sh --processes

   # View error logs
   ./bin/verify-staging.sh --logs
   ```

## Rollback Procedure

If deployment fails:
1. Restore from backup
2. Revert plugin files
3. Clear caches
4. Verify functionality

## Maintenance

### Regular Tasks
1. Update dependencies
2. Run tests
3. Monitor error logs
4. Backup data

### Backup Management
```bash
# Create backup
./Users/ben/dev/upskill-event-manager/wordpress-dev/manage-env.sh backup

# Restore from backup
./Users/ben/dev/upskill-event-manager/wordpress-dev/manage-env.sh restore
```

## Security Considerations

1. **Configuration Security**
   - Use environment variables
   - Secure sensitive data
   - Restrict file permissions

2. **Access Control**
   - Limit SSH access
   - Use strong passwords
   - Enable two-factor authentication

3. **Monitoring**
   - Check error logs
   - Monitor file changes
   - Track plugin activity 