Skip to content

fix(activesync): avoid foreach on string after calendar instance delete#213

Merged
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/activesync-calendar-instance-delete-foreach
Jul 24, 2026
Merged

fix(activesync): avoid foreach on string after calendar instance delete#213
ralflang merged 1 commit into
FRAMEWORK_6_0from
fix/activesync-calendar-instance-delete-foreach

Conversation

@TDannhauer

Copy link
Copy Markdown
Contributor

Summary

  • Fix PHP warning in ActiveSync deleteMessage() when a recurring calendar instance delete fails and the recovery path iterates a string UID.
  • Correct the $instanceids docblock to match callers (uids => instanceids).
  • Add regression tests for the instance-delete error path.

Motivation

An iPhone SYNC that removed a recurring instance (AirSyncBase:InstanceId) caused calendar_delete to throw (item not found). The catch block then ran foreach ($ids as $uid) after $ids had been overwritten with key($ids) (a string), producing:

foreach() argument must be of type array|object, string given

Changes

  • Keep the original $ids array; use $deleteIds for the connector call.
  • Normalize $deleteIds to an array before the recovery foreach.
  • Unit tests covering failed instance delete with and without a successful action timestamp.

Test plan

  • vendor/bin/phpunit --bootstrap /tmp/core-test-bootstrap.php -c vendor/horde/core/phpunit.xml.dist vendor/horde/core/test/Unit/ActiveSync/DriverDeleteMessageInstanceTest.php
  • Reproduce: ActiveSync Remove of a recurring instance that is already gone — confirm no PHP warning in /tmp-horde/horde.log

When deleting a recurring calendar instance, deleteMessage() overwrote
$ids with key($ids) (a string UID). If calendar_delete() then threw,
the recovery foreach triggered a PHP warning. Use a separate $deleteIds
and normalize to an array before iterating.
@TDannhauer
TDannhauer requested a review from ralflang July 24, 2026 10:09
* @param array $ids The message ids to delete
* @param boolean $instanceids If true, $ids is a hash of
* instanceids => uids. @since 2.23.0
* uids => instanceids. @since 2.23.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking this is a signature BC break.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6_1?

@ralflang ralflang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to re-read this later. The print_r is not great but I must make sure if this is only correcting wrong docs or if you really changed the signature in a BC-incompatible way.

sprintf(
'calendar_delete: %s %s %s',
print_r($ids, true),
print_r($deleteIds, true),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't print_r to the general logger. If you really must dump this data, make it a configurable extra file.

@ralflang

Copy link
Copy Markdown
Member

Confirmed: This is just a docs fix.

We can handle the print_r issue later - I vote for merging.

@ralflang
ralflang merged commit 2a4b0eb into FRAMEWORK_6_0 Jul 24, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants