# Developer Workflow

How to make code changes on the dev server and publish them to clients.

---

## Overview

```
Dev server (this machine)
    ↓  bash scripts/pbx-publish.sh
Bitbucket (git@bitbucket.org:openvdev/vconnectpbx.git)
    ↓  sudo bash scripts/pbx-update.sh
Client machines
```

---

## Making and publishing changes

### 1. Make your changes

Edit files normally (Kiro, VS Code, direct SSH, etc.)

### 2. Publish to Bitbucket

```bash
bash /var/www/html/scripts/pbx-publish.sh "describe what changed"
```

This stages all changes, commits with your message, and pushes to Bitbucket.

**Examples:**
```bash
bash /var/www/html/scripts/pbx-publish.sh "fix queue ringinuse bug"
bash /var/www/html/scripts/pbx-publish.sh "add caller ID prepend to inbound routes"
bash /var/www/html/scripts/pbx-publish.sh "update health check warnings for fresh installs"
```

### 3. Update client machines

On each client machine that should receive the update:

```bash
sudo bash /var/www/html/scripts/pbx-update.sh
```

---

## Checking what's changed

```bash
# What's changed since last commit
git -C /var/www/html diff

# What's staged
git -C /var/www/html diff --cached

# Recent commit history
git -C /var/www/html log --oneline -10

# What's different between local and Bitbucket
git -C /var/www/html fetch origin
git -C /var/www/html diff HEAD origin/main --stat
```

---

## What's in git (and what isn't)

### In git ✓
- All PHP code (`app/`, `routes/`, `config/`, `database/`)
- Blade views (`resources/views/`)
- Artisan commands
- Deployment scripts (`scripts/`)
- Documentation (`docs/`)
- `composer.json`, `composer.lock`

### NOT in git ✗
- `.env` — each machine has its own (DB credentials, APP_KEY, domain)
- `vendor/` — installed by `composer install` on each machine
- `public/build/` — compiled assets
- `storage/` — logs, cache, sessions
- `/etc/asterisk/*` — system configs managed by `pbx:deploy`

---

## Scripts reference

| Script | Run on | Purpose |
|---|---|---|
| `scripts/pbx-publish.sh` | Dev server | Commit + push to Bitbucket |
| `scripts/pbx-update.sh` | Client machine | Pull latest from Bitbucket |
| `scripts/pbx-setup-client.sh` | Client machine | One-time new client setup |
| `scripts/php/factory-reset.php` | Client machine | Wipe all tenant data |

---

## Artisan commands reference

```bash
# Deploy / repair system
sudo php artisan pbx:deploy

# Sync individual components
php artisan pbx:sync-blf-hints
php artisan pbx:sync-did-normalizer
php artisan pbx:reconcile-astdb
php artisan pbx:audit-recording --fix

# Factory reset (wipe all tenant data)
sudo php scripts/php/factory-reset.php --dry-run     # preview
sudo php scripts/php/factory-reset.php --yes-i-am-sure  # apply

# Health check
php artisan pbx:readiness-check
```

---

## Bitbucket repository

- URL: https://bitbucket.org/openvdev/vconnectpbx
- Branch: `main`
- Access: https://bitbucket.org/openvdev/vconnectpbx/admin/access-keys/
