Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting List of Changes of calender items #12

Closed
pjwj opened this issue Feb 25, 2016 · 5 comments
Closed

Getting List of Changes of calender items #12

pjwj opened this issue Feb 25, 2016 · 5 comments

Comments

@pjwj
Copy link

pjwj commented Feb 25, 2016

Hi,
I tried to get changed calender items using the code in the example in "getListOfChanges.php".
The response I got for the SyncFolderItems request was right at first and the SyncState Attribute was changed. However, when I tried to get further changes from the calender using the changed SyncState, I got the exact same response containing the same changes again.
Do you know of anything I need to do between to calls SyncFolderItems to not get the same changes again? Or is my understanding of syncing items with the server wrong?

(I tried syncing twice in a row with EWS Editor and it worked as I expected it, I got no changes anymore on second call.)

@Garethp
Copy link
Owner

Garethp commented Feb 26, 2016

Huh, weird. Can you show me your code where you try do do the tdwo syncs with different SyncStates?

@pjwj
Copy link
Author

pjwj commented Feb 29, 2016

This is how I use listChanges with sync state:

$api = API::withUsernameAndPassword($server, $user, $pass, $options);
$calendar = $api->getCalendar();

$changes = $calendar->listChanges();

$syncState = $changes->getSyncState();

//first call of listChanges() with syncState
$changesSinceLastCheck = $calendar->listChanges($syncState);
$syncState2 = $changesSinceLastCheck->getSyncState();

//second call of listChanges() with syncState
$changesSinceLastCheck2 = $calendar->listChanges($syncState2);

$createdElements = $changesSinceLastCheck->getChanges()->getCreate();
$createdElements2 = $changesSinceLastCheck->getChanges()->getCreate();


//dump subject texts for elements listed by first call
foreach ($createdElements as $element) {
    $elementWithBody = $calendar->getCalendarItem($element->getCalendarItem()->getItemId()->getId(), $element->getCalendarItem()->getItemId()->getChangeKey());
    var_dump($elementWithBody->getSubject());
}

//dump subject texts for elements listed by second call
foreach ($createdElements2 as $element) {
    $elementWithBody = $calendar->getCalendarItem($element->getCalendarItem()->getItemId()->getId(), $element->getCalendarItem()->getItemId()->getChangeKey());
    var_dump($elementWithBody->getSubject());
}

@Garethp
Copy link
Owner

Garethp commented Feb 29, 2016

Just to double check, is that what you've got in your source code? Because

$createdElements = $changesSinceLastCheck->getChanges()->getCreate();
$createdElements2 = $changesSinceLastCheck->getChanges()->getCreate();

are both reading from the same $changesSinceLastCheck, when $createdElements2 should be reading from $changesSinceLastCheck2 instead.

Also, a tip: If you already have the completed itemId (like from getItemId()), you can bypass the getCalendarItem() function for more readability. For example

$elementWithBody = $calendar->getItem($element->getCalendarItem()->getItemId());

Also, maybe it would be a good idea to dump the ItemId of the elements instead of the subject? That way you have a better way to see if they're the same item or just two items with the same subject?

@pjwj
Copy link
Author

pjwj commented Feb 29, 2016

Thank you! It works now, changing the second $changesSinceLastCheck to $changesSinceLastCheck2, my dumb mistake.

@pjwj pjwj closed this as completed Feb 29, 2016
@Garethp
Copy link
Owner

Garethp commented Feb 29, 2016

No problem :) I'm glad it worked for you. I don't use that function, so I didn't know if there was a bug or not. I realized that I didn't unit test fetching changes when you pass in an existing syncState, so I'm writing those tests now.

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

No branches or pull requests

2 participants