# ๐Ÿ”„ DokuWiki โ†’ Outlook Sync Setup Guide ## ๐Ÿ“‹ Prerequisites - PHP 7.4+ with cURL extension - Office 365 / Outlook.com account - Azure account (free tier works fine) --- ## ๐Ÿ”‘ Step 1: Azure App Registration ### 1. Go to Azure Portal https://portal.azure.com โ†’ **Azure Active Directory** โ†’ **App registrations** ### 2. Create New Registration - Click **"New registration"** - Name: `DokuWiki Calendar Sync` - Supported account types: **"Accounts in this organizational directory only"** - Redirect URI: Leave blank - Click **Register** ### 3. Note Your IDs **Copy these values** (you'll need them): - **Application (client) ID** - e.g., `abc123-...` - **Directory (tenant) ID** - e.g., `xyz789-...` ### 4. Create Client Secret - Go to **Certificates & secrets** tab - Click **"New client secret"** - Description: `DokuWiki Sync` - Expires: **24 months** (recommended) - Click **Add** - **โš ๏ธ COPY THE SECRET VALUE NOW** - You can't see it again! ### 5. Grant API Permissions - Go to **API permissions** tab - Click **"Add a permission"** - Choose **Microsoft Graph** - Choose **Application permissions** - Search and add: - `Calendars.ReadWrite` โœ… - `User.Read.All` โœ… - Click **"Grant admin consent"** (requires admin) - If you're not admin, request consent from IT --- ## โš™๏ธ Step 2: Configure Sync Script ### 1. Edit Configuration File ```bash cd /var/www/html/dokuwiki/lib/plugins/calendar nano sync_config.php ``` ### 2. Fill In Credentials ```php 'tenant_id' => 'YOUR_TENANT_ID_HERE', // From Azure Portal 'client_id' => 'YOUR_CLIENT_ID_HERE', // Application ID 'client_secret' => 'YOUR_CLIENT_SECRET_HERE', // Secret value 'user_email' => 'your@email.com', // Your Office 365 email ``` ### 3. Configure Category Mapping (Optional) Map DokuWiki namespaces to Outlook categories: ```php 'category_mapping' => [ 'work' => 'Blue category', 'personal' => 'Green category', 'projects' => 'Yellow category', ], ``` **Available Outlook Categories:** - Blue category - Green category - Orange category - Red category - Yellow category - Purple category ### 4. Save Configuration ```bash # Make sure permissions are secure chmod 600 sync_config.php ``` --- ## ๐Ÿงช Step 3: Test the Sync ### 1. Dry Run (No Changes) ```bash php sync_outlook.php --dry-run ``` **Expected output:** ``` [2026-01-25 23:45:30] [INFO] === DokuWiki โ†’ Outlook Sync Started === [2026-01-25 23:45:30] [INFO] DRY RUN MODE - No changes will be made [2026-01-25 23:45:31] [INFO] Authenticating with Microsoft Graph API... [2026-01-25 23:45:32] [INFO] Authentication successful [2026-01-25 23:45:32] [INFO] Loading DokuWiki calendar events... [2026-01-25 23:45:32] [INFO] Found 25 events in DokuWiki [2026-01-25 23:45:32] [INFO] Created: Meeting [work] [2026-01-25 23:45:32] [INFO] Created: Dentist [personal] ... [2026-01-25 23:45:35] [INFO] === Sync Complete === [2026-01-25 23:45:35] [INFO] Scanned: 25 events [2026-01-25 23:45:35] [INFO] Created: 25 [2026-01-25 23:45:35] [INFO] Updated: 0 [2026-01-25 23:45:35] [INFO] Deleted: 0 ``` ### 2. Real Sync If dry run looks good: ```bash php sync_outlook.php ``` ### 3. Check Outlook Open Outlook and verify: - Events appear in your calendar - Categories are color-coded - Reminders are set (15 minutes before) --- ## ๐Ÿ”„ Step 4: Automate with Cron ### 1. Add Cron Job ```bash crontab -e ``` ### 2. Add This Line ```bash # Sync DokuWiki calendar to Outlook every 30 minutes */30 * * * * cd /var/www/html/dokuwiki/lib/plugins/calendar && php sync_outlook.php >> sync.log 2>&1 ``` ### 3. Alternative: Hourly Sync ```bash # Every hour at :15 (e.g., 1:15, 2:15, 3:15) 15 * * * * cd /var/www/html/dokuwiki/lib/plugins/calendar && php sync_outlook.php >> sync.log 2>&1 ``` --- ## ๐ŸŽฏ Usage Examples ### Sync Everything ```bash php sync_outlook.php ``` ### Sync Specific Namespace ```bash php sync_outlook.php --namespace=work ``` ### Dry Run (Preview Changes) ```bash php sync_outlook.php --dry-run ``` ### Force Re-sync All ```bash php sync_outlook.php --force ``` ### Verbose Output ```bash php sync_outlook.php --verbose ``` --- ## ๐Ÿ“ Files Created - **sync_config.php** - Your credentials (gitignore this!) - **sync_state.json** - Mapping of DokuWiki IDs to Outlook IDs - **sync.log** - Sync history and errors --- ## ๐Ÿ” Troubleshooting ### "Failed to get access token" - Check your tenant_id, client_id, and client_secret - Verify API permissions are granted in Azure - Check if client secret has expired ### "Calendars.ReadWrite permission not granted" - Go to Azure Portal โ†’ App registrations โ†’ Your app โ†’ API permissions - Click "Grant admin consent" - May need IT admin to approve ### Events not syncing ```bash # Check the log tail -f sync.log # Test authentication php sync_outlook.php --dry-run --verbose ``` ### Wrong timezone ```bash # Edit sync_config.php 'timezone' => 'America/Los_Angeles' # Pacific Time 'timezone' => 'America/New_York' # Eastern Time 'timezone' => 'Europe/London' # GMT ``` ### Categories not showing - Categories must exist in Outlook first - Use one of the 6 preset colors - Or create custom categories in Outlook settings --- ## ๐ŸŽจ Category Setup in Outlook ### Option 1: Use Presets (Easiest) Just use the built-in colors: - Blue category - Green category - Yellow category - Orange category - Red category - Purple category ### Option 2: Rename Categories 1. Open Outlook 2. Go to **Calendar** view 3. Right-click any category 4. Choose **"All Categories"** 5. Rename categories to match your namespaces: - Blue category โ†’ Work - Green category โ†’ Personal - Yellow category โ†’ Projects Then update sync_config.php: ```php 'category_mapping' => [ 'work' => 'Work', 'personal' => 'Personal', 'projects' => 'Projects', ], ``` --- ## ๐Ÿ”’ Security Notes - **Never commit sync_config.php** to git - Add to .gitignore: ``` sync_config.php sync_state.json sync.log ``` - File permissions: `chmod 600 sync_config.php` - Store credentials securely --- ## ๐Ÿ“Š What Gets Synced โœ… Event title โœ… Date and time โœ… Multi-day events โœ… All-day events โœ… Description โœ… Category (based on namespace) โœ… Reminders (15 min before) โŒ Recurring events (expanded as individual occurrences) โŒ Event colors (uses categories instead) โŒ Task checkboxes (syncs as events) --- ## ๐Ÿš€ Advanced Features ### Skip Completed Tasks ```php 'sync_completed_tasks' => false, ``` ### Disable Deletions ```php 'delete_outlook_events' => false, ``` ### Custom Reminder Time ```php 'reminder_minutes' => 30, // 30 minutes before ``` ### Filter Namespaces ```bash # Only sync work events php sync_outlook.php --namespace=work ``` --- ## ๐Ÿ’ก Pro Tips 1. **Run dry-run first** - Always test with `--dry-run` before real sync 2. **Check logs** - Monitor `sync.log` for errors 3. **Backup Outlook** - Export calendar before first sync 4. **Test with one namespace** - Start small with `--namespace=test` 5. **Schedule during off-hours** - Run cron at night to avoid conflicts --- ## ๐Ÿ†˜ Support **Common Issues:** - Check sync.log for detailed errors - Verify Azure permissions are granted - Test API credentials with --dry-run - Ensure PHP has cURL extension **Reset Sync State:** ```bash # Start fresh (will re-sync everything) rm sync_state.json php sync_outlook.php --dry-run ``` --- **Version:** 1.0 **Compatibility:** DokuWiki Calendar Plugin v3.3+ **Tested:** Office 365, Outlook.com ๐ŸŽ‰ **Happy Syncing!** ๐ŸŽ‰