6.0.0-beta1
8/10/25

[#13268] Kolab_Storage: PHP error on modifying contact picture
Summary Kolab_Storage: PHP error on modifying contact picture
Queue Horde Framework Packages
Queue Version Git master
Type Bug
State Resolved
Priority 1. Low
Owners jan (at) horde (dot) org
Requester thomas.jarosch (at) intra2net (dot) com
Created 06/18/2014 (4071 days ago)
Due
Updated 03/24/2015 (3792 days ago)
Assigned 06/20/2014 (4069 days ago)
Resolved 03/23/2015 (3793 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
03/24/2015 12:44:51 PM Thomas Jarosch Comment #13 Reply to this comment
Sweet! I'm glad you found and fixed the second issue.

03/24/2015 11:22:39 AM Git Commit Comment #12 Reply to this comment
Changes have been made in Git (master):

commit 984ec55759dd59390686122d37722dfb4b9f4884
Author: Jan Schneider <jan@horde.org>
Date:   Tue Mar 24 12:18:53 2015 +0100

     Deal with both formats of the _attachments hash (Bug #13268).

     In the end I was able to reproducable that edge case.
     There is no use in trying to clean this mess up, because it would 
break the
     _attachments API that is used outside of Kolab_Storage. This 
needs refactoring
     for H6.

  .../lib/Horde/Kolab/Storage/Cache/Data.php         |    8 +++++++-
  1 files changed, 7 insertions(+), 1 deletions(-)

http://github.com/horde/horde/commit/984ec55759dd59390686122d37722dfb4b9f4884
03/23/2015 04:09:43 PM Thomas Jarosch Comment #11 Reply to this comment
I haven't been able to reproduce the edge cases anymore that we 
talked about. Probably just some stale and broken cache entries from 
development.
good! I'll try to break it again with your latest changes + a clean cache.
(will take some time though until I get to it)

03/23/2015 02:30:40 PM Jan Schneider Comment #10
Assigned to Jan Schneider
State ⇒ Resolved
Reply to this comment
I haven't been able to reproduce the edge cases anymore that we talked 
about. Probably just some stale and broken cache entries from 
development.
03/23/2015 02:21:42 PM Git Commit Comment #9 Reply to this comment
Changes have been made in Git (master):

commit 6aec869cebdc7e7315f4dfd3624901363449bb60
Author: Jan Schneider <jan@horde.org>
Date:   Fri Mar 20 19:47:38 2015 +0100

     [jan] Fix deleting object attachments from cache (Bug #13268).

  .../lib/Horde/Kolab/Storage/Cache/Data.php         |    2 +-
  framework/Kolab_Storage/package.xml                |    4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)

http://github.com/horde/horde/commit/6aec869cebdc7e7315f4dfd3624901363449bb60
08/04/2014 01:56:23 PM Thomas Jarosch Comment #8 Reply to this comment
ping

07/01/2014 02:46:16 PM Thomas Jarosch Comment #7
New Attachment: 0001-Correctly-remove-old-attachments-from-cache-during-u.patch Download
Reply to this comment
Ok, I've added the usual lot of debug statements
and found out what's going on:

The $delete() array contains a list of "IMAP uids" (=backend IDs)
that got deleted - including the corresponding object uid.

When you update a contact in turba, $_data[self::OBJECTS][$object_id]
will contain the *current* datastructure as passed on by the turba 
Kolab driver.

There is no 'id' column in '_attachments' as
the '_attachments' datastructure looks like this:
-------------------------
Array
(
     [photo.jpg] => Array
         (
             [type] => image/jpeg
             [content] => Resource id #331
         )
)
-------------------------


The transformation of that data structure for the on-disc format
of the cache happens a few lines below.

Things are different when you delete a contact,
'_attachments' then looks like this as it's not
updated by the turba Kolab driver itself:
-------------------------------------------------------
[_attachments] => Array
(
     [id] => Array
         (
             [0] => photo.jpg
         )

     [type] => Array
         (
             [image/jpeg] => Array
                 (
                     [0] => photo.jpg
                 )

         )

)
-------------------------------------------------------

Please apply the attached patch to handle both cases.

I've tested the patch with debug statements in place
to verify it does delete the correct attachment
in both the modify and delete case of a contact object.

06/30/2014 04:12:19 PM Jan Schneider Comment #6 Reply to this comment
There is a difference between how the attachments are passed to 
store() ($objects array with '_attachments' being an ID->attachment 
hash) and how they are stored in the Data object ($this->_data with 
'_attachments' being a list of attachment hashes).
06/20/2014 01:24:34 PM Thomas Jarosch Comment #5 Reply to this comment
IIRC those are different data structures in different situations. 
How did you actually trigger an error with the current code? Editing 
a contact picture with the Horde_Form image editing buttons worked 
without problems.
while editing works fine and there's only one attachment in the 
produced email,
it triggers the given warning for me every time on modification (using 
git "master").

The foreach() calls I provided are in the same function "store()", so 
it's the same datastructure.
To me it looks like $object[_attachments[]['id']] is used before it's 
actually built.

If you look at the code, the second iteration is filling in the 'id' field.
--------------------------------------------------------
foreach ($object['_attachments'] as $id => $attachment) {
     $attachments['id'][] = $id;
--------------------------------------------------------

06/20/2014 01:15:22 PM Jan Schneider Comment #4 Reply to this comment
IIRC those are different data structures in different situations. How 
did you actually trigger an error with the current code? Editing a 
contact picture with the Horde_Form image editing buttons worked 
without problems.
06/20/2014 12:50:18 PM Thomas Jarosch Comment #3 Reply to this comment
Cannot reproduce. Works perfectly fine here and without any errors 
or notices.
should there be an 'id' field in the datastructure? I thought the key 
of the '_attachments' array is already the id?

The code in question iterates of the attachments like this:
------------------------------------------
foreach ($object['_attachments']['id'] as $id) {
------------------------------------------

Other pieces of code iterate like this:
------------------------------------------
foreach ($object['_attachments'] as $id => $attachment) {
------------------------------------------

06/20/2014 12:34:02 PM Jan Schneider Comment #2
State ⇒ Feedback
Reply to this comment
Cannot reproduce. Works perfectly fine here and without any errors or notices.
06/18/2014 01:57:15 PM Thomas Jarosch Comment #1
Patch ⇒ No
State ⇒ Unconfirmed
Milestone ⇒
Queue ⇒ Horde Framework Packages
Summary ⇒ Kolab_Storage: PHP error on modifying contact picture
Type ⇒ Bug
Priority ⇒ 1. Low
Reply to this comment
Hi,

when you modify a contact picture in turba (say: rotate it), the 
following error is logged:

2014-06-19T15:52:34+02:00 WARN: HORDE [turba] PHP ERROR: Invalid 
argument supplied for foreach() [pid 2863 on line 461 of 
"/datastore/DEVEL/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Cache/Data.php"]

The structure of $object['_attachments'] looks like this:
---------------------------------
Array
(
     [photo.jpg] => Array
         (
             [type] => image/jpeg
             [content] => Resource id #331
         )

)
---------------------------------

-> no "id" value in there.

Cheers,
Thomas

Saved Queries