* # FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal
# FIX: CDavLib getSqlCalEvents broken after actioncomm_cdav table removal, Add CalDav tests
Add CalDav tests, which resulted in detecting Issue.
## Issue
The `CDavLib::getSqlCalEvents()` method in `htdocs/dav/dav.class.php` has been generating broken SQL queries, causing the new `CDavLibTest::testGetFullCalendarObjects` test to fail.
## Root Cause
The issue stems from the removal of the `actioncomm_cdav` table. The original code referenced:
- `ac.sourceuid` field (from a non-existent `ac` alias)
- `ac.uuidext` field (from the removed `actioncomm_cdav` table)
- Used incorrect phone field names (`sp.phone`, `sp.phone_perso`, `sp.phone_mobile`)
- Used incorrect country field `sp.fk_pays` instead of `sp.fk_country`
- Missing JOIN for the `user` table (`sp` alias)
## Fixes Applied
### 1. SQL String Concatenation
Upgraded to the use of `$this->db->prefix()` instead of `.MAIN_DB_PREFIX.` literal strings.
### 2. Phone Field Names
Updated phone field names to match current Dolibarr schema:
- `sp.phone` → `sp.office_phone as phone`
- `sp.phone_perso` → `sp.personal_mobile as phone_perso`
- `sp.phone_mobile` → `sp.user_mobile as phone_mobile`
### 3. Country Field
Fixed the country JOIN to use the correct field:
- `sp.fk_pays` → `sp.fk_country`
- `s.fk_pays` remains unchanged (correct for societe table)
### 4. Removed Non-Existent Fields
Removed `ac.sourceuid` and `a.sourceuid` from the SELECT clause as these fields do not exist in the `actioncomm` table. These were likely from the removed `actioncomm_cdav` table.
### 5. Added Missing JOINs
Added proper JOIN for the user table:
```php
LEFT JOIN ' . $this->db->prefix() . 'user as sp ON sp.rowid = a.fk_user_action
```
### 6. OURI Parameter Handling
Fixed the `$ouri` parameter handling to use `a.recurid` instead of the non-existent `ac.uuidext`:
```php
// When both OID and OURI are provided
$sql .= ' AND (a.id = ' . ((int) $oid) . ' OR a.recurid = \''. $this->db->escape($ouri) . '\')';
// When only OURI is provided
} elseif ($ouri !== false) {
$sql .= ' AND a.recurid = \''. $this->db->escape($ouri) . '\'';
}
```
## Test Cases Added
Added test cases to `test/phpunit/CDavLibTest.php` to verify:
1. OID and OURI parameters together produce SQL with both `a.id =` and `a.recurid =` conditions
2. OURI parameter alone produces SQL with only `a.recurid =` condition (no `a.id =`)
## Regression Origin
This regression dates back to when the `actioncomm_cdav` table was removed from Dolibarr. The code was not properly updated to handle the removal, leaving broken references to fields and tables that no longer exist.
## Files Modified
- `htdocs/dav/dav.class.php` - Method `getSqlCalEvents()` (lines 69-111)
- `test/phpunit/CDavLibTest.php` - Method `testGetSqlCalEvents()` (lines 123-138)
## Verification
All CDavLibTest tests pass:
- testCdavLibConstruct
- testGetSqlCalEvents
- testToVCalendar
- testGetFullCalendarObjects
* FIX: Phan type warnings and PHPUnit 7.x compatibility
- Fix Phan type warnings in dav.class.php by casting $ouri to string before escape()
- Add PHPUnit compatibility helper in CommonClassTest for assertMatchesRegularExpression
which was introduced in PHPUnit 8.0, providing backward compatibility with PHPUnit 7.x
Fixes:
- PhanTypeMismatchArgument warnings for $ouri parameter
- assertMatchesRegularExpression undefined method error in CI with PHPUnit < 8.0
|
||
|---|---|---|
| .. | ||
| dav.class.php | ||
| dav.lib.php | ||
| fileserver.php | ||