Skip to content

Commit d253bd4

Browse files
Prophet731claude
andcommitted
feat: auto-create custom fields, add try/catch coverage, PHPDoc, and Pint formatting
- Auto-create 'Initial Operating System' and 'Initial SSH Key' custom fields via Database::ensureCustomFields() on module load, eliminating the manual modify.sql step - Delete modify.sql (no longer needed) - Add try/catch blocks around every DB operation and API call across all PHP files per CLAUDE.md error handling rules - Add comprehensive PHPDoc to all classes, methods, and properties - Set up Laravel Pint (laravel/pint) with Laravel-style preset for consistent code formatting across the codebase - Add git pre-commit hook (hooks/pre-commit) that runs Pint on staged PHP files, auto-installed via Composer post-install/post-update scripts - Simplify README installation to a single copy-paste command Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1ab2ef4 commit d253bd4

22 files changed

+2215
-1305
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/.idea/
2-
/.superpowers/
2+
/.superpowers/
3+
/vendor/

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ The `publish-release.yml` workflow creates a GitHub/Gitea release with auto-gene
9191
6. Updates WHMCS hosting record (IP, username, password, domain)
9292
7. Calls `ConfigureService::initServerBuild()` with selected OS + SSH key
9393

94+
Custom fields (`Initial Operating System`, `Initial SSH Key`) are auto-created by `Database::ensureCustomFields()` on module load for all products using this module. No manual SQL setup required.
95+
9496
### Configurable Option Mapping
9597

9698
Custom option names can be mapped in `config/ConfigOptionMapping.php` (copy from `-example.php`). Default mapping keys: `packageId`, `hypervisorId`, `ipv4`, `storage`, `memory`, `traffic`, `cpuCores`, `networkSpeedInbound`, `networkSpeedOutbound`, `networkProfile`, `storageProfile`.

README.md

Lines changed: 11 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -108,95 +108,28 @@ You also need a VirtFusion API token with the following permissions:
108108

109109
## Installation
110110

111-
### Step 1: Download & Install
112-
113-
Download the latest release from the [releases](https://github.com/EZSCALE/virtfusion-whmcs-module/releases) page, or install directly via the command line:
114-
115111
```bash
116-
cd /tmp
117-
git clone https://github.com/EZSCALE/virtfusion-whmcs-module.git
118-
rsync -ahP --delete /tmp/virtfusion-whmcs-module/modules/servers/VirtFusionDirect/ /path/to/whmcs/modules/servers/VirtFusionDirect/
119-
rm -rf /tmp/virtfusion-whmcs-module
120-
```
121-
122-
Replace `/path/to/whmcs` with your actual WHMCS installation root.
123-
124-
The resulting file structure should be:
125-
126-
```
127-
modules/servers/VirtFusionDirect/
128-
VirtFusionDirect.php # Main module file
129-
client.php # Client AJAX API
130-
admin.php # Admin AJAX API
131-
hooks.php # WHMCS hooks
132-
modify.sql # Custom field setup SQL
133-
lib/
134-
Module.php # Core module class
135-
ModuleFunctions.php # Provisioning functions
136-
ConfigureService.php # OS/SSH config service
137-
Database.php # Database operations
138-
Curl.php # HTTP client
139-
ServerResource.php # Data transformer
140-
AdminHTML.php # Admin interface HTML
141-
Log.php # Logging
142-
templates/
143-
overview.tpl # Client area template
144-
error.tpl # Error template
145-
css/module.css # Styles
146-
js/module.js # Client JavaScript
147-
js/keygen.js # SSH Ed25519 key generator
148-
config/
149-
ConfigOptionMapping-example.php # Config mapping example
112+
git clone https://github.com/EZSCALE/virtfusion-whmcs-module.git /tmp/vf && rsync -ahP --delete /tmp/vf/modules/servers/VirtFusionDirect/ /path/to/whmcs/modules/servers/VirtFusionDirect/ && rm -rf /tmp/vf
150113
```
151114

152-
### Step 2: Set Up Server in WHMCS
115+
Replace `/path/to/whmcs` with your actual WHMCS installation root. The database table, schema migrations, and custom fields are all created automatically on first load.
153116

154-
1. Go to **Configuration > System Settings > Servers**
155-
2. Click **Add New Server**
156-
3. Fill in:
157-
- **Name**: Anything descriptive (e.g., "VirtFusion Production")
158-
- **Hostname**: Your VirtFusion panel hostname (e.g., `cp.example.com`)
159-
- **Type**: VirtFusion Direct Provisioning
160-
- **Password/Access Hash**: Your VirtFusion API token
161-
4. Click **Test Connection** to verify
162-
5. Click **Save Changes**
117+
Then configure in WHMCS Admin:
163118

164-
### Step 3: Create Product
119+
1. **Add Server** — Configuration > System Settings > Servers > Add New Server. Set hostname to your VirtFusion panel (e.g. `cp.example.com`), type to "VirtFusion Direct Provisioning", and paste your API token in the Password field. Click **Test Connection** to verify.
120+
2. **Create Product** — Configuration > System Settings > Products/Services. On the Module Settings tab, select "VirtFusion Direct Provisioning", choose your server, and set the Hypervisor Group ID, Package ID, and Default IPv4 count.
165121

166-
1. Go to **Configuration > System Settings > Products/Services**
167-
2. Create a new product or edit an existing one
168-
3. On the **Module Settings** tab:
169-
- Set **Module Name** to "VirtFusion Direct Provisioning"
170-
- Select your VirtFusion server
171-
- Set **Hypervisor Group ID**, **Package ID**, and **Default IPv4** count
172-
4. Save the product
173-
174-
### Step 4: Set Up Custom Fields
175-
176-
See [Custom Fields](#custom-fields) section below.
177-
178-
### Step 5: Activate Hooks
179-
180-
The hooks file (`hooks.php`) is automatically detected by WHMCS when the module is active. If you add the module files to an existing installation, you may need to re-save the product settings or clear the WHMCS template cache for hooks to take effect.
122+
That's it. Hooks activate automatically and custom fields are created on module load.
181123

182124
## Upgrading
183125

184-
1. Back up your existing `modules/servers/VirtFusionDirect/` directory
185-
2. Back up `config/ConfigOptionMapping.php` if you have a custom mapping
186-
3. Download and deploy the new version:
187-
188126
```bash
189-
cd /tmp
190-
git clone https://github.com/EZSCALE/virtfusion-whmcs-module.git
191-
rsync -ahP --delete /tmp/virtfusion-whmcs-module/modules/servers/VirtFusionDirect/ /path/to/whmcs/modules/servers/VirtFusionDirect/
192-
rm -rf /tmp/virtfusion-whmcs-module
127+
git clone https://github.com/EZSCALE/virtfusion-whmcs-module.git /tmp/vf && rsync -ahP --delete /tmp/vf/modules/servers/VirtFusionDirect/ /path/to/whmcs/modules/servers/VirtFusionDirect/ && rm -rf /tmp/vf
193128
```
194129

195-
4. Restore your custom `config/ConfigOptionMapping.php` if applicable
196-
5. If you have theme-overridden templates, review them for any new template variables
197-
6. Clear the WHMCS template cache: **Configuration > System Settings > General Settings > clear template cache**
130+
> **Note:** If you have a custom `config/ConfigOptionMapping.php`, back it up first — `--delete` will remove it. Restore it after upgrading.
198131
199-
The module database table (`mod_virtfusion_direct`) is automatically migrated on first load.
132+
If you use theme-overridden templates, review them for any new template variables. Clear the WHMCS template cache after upgrading: **Configuration > System Settings > General Settings > clear template cache**.
200133

201134
## Configuration
202135

@@ -222,20 +155,9 @@ Each WHMCS product using this module needs:
222155

223156
### Custom Fields
224157

225-
You **must** create two custom fields on each product that uses this module:
158+
The module requires two custom fields per product: **Initial Operating System** and **Initial SSH Key**. These are **automatically created** when the module loads — no manual setup required.
226159

227-
| Field Name | Field Type | Show on Order Form | Admin Only | Required |
228-
|---|---|---|---|---|
229-
| Initial Operating System | Text Box | Yes | No | No |
230-
| Initial SSH Key | Text Box | Yes | No | No |
231-
232-
These fields are hidden text boxes that are dynamically replaced by dropdown selects via JavaScript hooks on the order form.
233-
234-
**Automated setup**: Run the SQL from [modify.sql](modify.sql) to auto-create these fields for all VirtFusion products:
235-
236-
```bash
237-
mysql -u whmcs_user -p whmcs_database < modules/servers/VirtFusionDirect/modify.sql
238-
```
160+
The fields are hidden text boxes that are dynamically replaced by dropdown selects via JavaScript hooks on the order form. They are created for every product with the module type set to "VirtFusion Direct Provisioning".
239161

240162
### Module Configuration Options
241163

@@ -559,7 +481,6 @@ modules/servers/VirtFusionDirect/
559481
client.php # Client-facing AJAX API (authenticated, ownership-validated)
560482
admin.php # Admin-facing AJAX API (admin authentication required)
561483
hooks.php # WHMCS hooks (order form OS/SSH dropdowns, checkout validation)
562-
modify.sql # SQL for creating custom fields
563484
lib/
564485
Module.php # Base class: API communication, power, network, VNC, rebuild
565486
ModuleFunctions.php # Provisioning: create, suspend, unsuspend, terminate, change package

composer.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "ezscale/virtfusion-whmcs-module",
3+
"description": "VirtFusion Direct Provisioning Module for WHMCS",
4+
"type": "whmcs-module",
5+
"license": "GPL-3.0-or-later",
6+
"require-dev": {
7+
"laravel/pint": "^1.0"
8+
},
9+
"scripts": {
10+
"post-install-cmd": [
11+
"cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit"
12+
],
13+
"post-update-cmd": [
14+
"cp hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit"
15+
],
16+
"lint": "pint",
17+
"lint-test": "pint --test"
18+
}
19+
}

composer.lock

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hooks/pre-commit

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Run Pint on staged PHP files before committing.
4+
# Fixes formatting in-place and re-stages the corrected files.
5+
6+
STAGED_PHP=$(git diff --cached --name-only --diff-filter=ACM | grep '\.php$')
7+
8+
if [ -z "$STAGED_PHP" ]; then
9+
exit 0
10+
fi
11+
12+
# Check that Pint is installed
13+
if [ ! -x "./vendor/bin/pint" ]; then
14+
echo "Error: laravel/pint is not installed. Run 'composer install' first."
15+
exit 1
16+
fi
17+
18+
echo "Running Pint on staged PHP files..."
19+
./vendor/bin/pint $STAGED_PHP
20+
21+
# Re-stage any files that Pint modified
22+
for FILE in $STAGED_PHP; do
23+
if [ -f "$FILE" ]; then
24+
git add "$FILE"
25+
fi
26+
done

0 commit comments

Comments
 (0)