Commit 9b513386 authored by Sebastian Kummer's avatar Sebastian Kummer

ZO-28 Fixes from comments.

parent ed5b5180
...@@ -58,7 +58,7 @@ class Zarafa extends SyncWorker { ...@@ -58,7 +58,7 @@ class Zarafa extends SyncWorker {
* Creates the hidden folder. * Creates the hidden folder.
* *
* @access protected * @access protected
* @return boolean * @return string
*/ */
protected function CreateHiddenFolder() { protected function CreateHiddenFolder() {
$parentfolder = $this->getRootFolder(); $parentfolder = $this->getRootFolder();
...@@ -108,7 +108,7 @@ class Zarafa extends SyncWorker { ...@@ -108,7 +108,7 @@ class Zarafa extends SyncWorker {
* Returns the internal identfier (folder-id) of the hidden folder. * Returns the internal identfier (folder-id) of the hidden folder.
* *
* @access protected * @access protected
* @return string * @return string|boolean on error
*/ */
protected function GetHiddenFolderId() { protected function GetHiddenFolderId() {
$parentfolder = $this->getRootFolder(); $parentfolder = $this->getRootFolder();
...@@ -128,7 +128,7 @@ class Zarafa extends SyncWorker { ...@@ -128,7 +128,7 @@ class Zarafa extends SyncWorker {
} }
/** /**
* Removes all messages that have not the same chunkType (chunk configuration changed!) * Removes all messages that have not the same chunkType (chunk configuration changed!).
* *
* @param string $folderid * @param string $folderid
* *
...@@ -159,12 +159,8 @@ class Zarafa extends SyncWorker { ...@@ -159,12 +159,8 @@ class Zarafa extends SyncWorker {
protected function ClearAllNotCurrentChunkType($folderid) { protected function ClearAllNotCurrentChunkType($folderid) {
$folder = $this->getFolder($folderid); $folder = $this->getFolder($folderid);
$table = mapi_folder_getcontentstable($folder); $table = mapi_folder_getcontentstable($folder);
if (!$table) if (!$table)
$this->Terminate("Zarafa->ClearAllNotCurrentChunkType: Error, unable to read contents table."); $this->Terminate(sprintf("Zarafa->ClearAllNotCurrentChunkType: Error, unable to read contents table: 0x%08X", mapi_last_hresult()));
$mapiprops = array("location" =>"PT_STRING8:PSETID_Appointment:0x8208");
$mapiprops = getPropIdsFromStrings($this->store, $this->mapiprops);
$restriction = array(RES_PROPERTY, array(RELOP => RELOP_NE, ULPROPTAG => $this->mapiprops['chunktype'], VALUE => $this->chunkType)); $restriction = array(RES_PROPERTY, array(RELOP => RELOP_NE, ULPROPTAG => $this->mapiprops['chunktype'], VALUE => $this->chunkType));
mapi_table_restrict($table, $restriction); mapi_table_restrict($table, $restriction);
...@@ -176,17 +172,21 @@ class Zarafa extends SyncWorker { ...@@ -176,17 +172,21 @@ class Zarafa extends SyncWorker {
$this->Log(sprintf("Zarafa->ClearAllNotCurrentChunkType: found %d invalid items, deleting", $querycnt)); $this->Log(sprintf("Zarafa->ClearAllNotCurrentChunkType: found %d invalid items, deleting", $querycnt));
$deleted = 0; $deleted = 0;
while($deleted <= $querycnt) { while($deleted <= $querycnt) {
$entries = mapi_table_queryallrows($table, array(PR_ENTRYID, $this->mapiprops['chunktype'])); $entries = mapi_table_queryrows($table, array(PR_ENTRYID, $this->mapiprops['chunktype']), $deleted, 20);
$entry_ids = array_reduce($entries, function ($result, $item) { $entry_ids = array_reduce($entries, function ($result, $item) {
$result[] = $item[PR_ENTRYID]; $result[] = $item[PR_ENTRYID];
return $result; return $result;
}, array()); }, array());
mapi_folder_deletemessages($folder, array_values($entry_ids)); $toDelete = count($entry_ids);
$deleted += 20; if ($toDelete > 0) {
mapi_folder_deletemessages($folder, array_values($entry_ids));
}
$deleted += $toDelete;
} }
$this->Log("Zarafa->ClearAllNotCurrentChunkType: done"); $this->Log("Zarafa->ClearAllNotCurrentChunkType: done");
} }
$this->Log(""); $this->Log("");
return true;
} }
/** /**
...@@ -204,19 +204,17 @@ class Zarafa extends SyncWorker { ...@@ -204,19 +204,17 @@ class Zarafa extends SyncWorker {
$data = array(); $data = array();
$addrbook = mapi_openaddressbook($this->session); $addrbook = mapi_openaddressbook($this->session);
$result = mapi_last_hresult(); if (mapi_last_hresult())
if ($result) $this->Terminate(sprintf("Zarafa->GetGAB: Error opening addressbook 0x%08X", mapi_last_hresult()));
$this->Terminate(sprintf("Zarafa->GetGAB: Error opening addressbook 0x%08X", $result)); $ab_entryid = mapi_ab_getdefaultdir($addrbook);
if (mapi_last_hresult())
if ($addrbook) $this->Terminate(sprintf("Zarafa->GetGAB: Error, could not get default address directory: 0x%08X", mapi_last_hresult()));
$ab_entryid = mapi_ab_getdefaultdir($addrbook); $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
if ($ab_entryid) if (mapi_last_hresult())
$ab_dir = mapi_ab_openentry($addrbook, $ab_entryid); $this->Terminate(sprintf("Zarafa->GetGAB: Error, could not open default address directory: 0x%08X", mapi_last_hresult()));
if ($ab_dir) $table = mapi_folder_getcontentstable($ab_dir);
$table = mapi_folder_getcontentstable($ab_dir); if (mapi_last_hresult())
$this->Terminate(sprintf("Zarafa->GetGAB: error, could not open addressbook content table: 0x%08X", mapi_last_hresult()));
if (!$table)
$this->Terminate(sprintf("Zarafa->GetGAB: error, could not open addressbook: 0x%08X", $result));
// restrict the table if we should only return one // restrict the table if we should only return one
if ($uniqueId) { if ($uniqueId) {
...@@ -381,7 +379,8 @@ class Zarafa extends SyncWorker { ...@@ -381,7 +379,8 @@ class Zarafa extends SyncWorker {
$folder = $this->getFolder($folderid); $folder = $this->getFolder($folderid);
$table = mapi_folder_getcontentstable($folder); $table = mapi_folder_getcontentstable($folder);
if (!$table) if (!$table)
$this->Log("Zarafa->findChunk: Error, unable to read contents table to select and set chunk: ". $chunkId); $this->Log(sprintf("Zarafa->findChunk: Error, unable to read contents table to find chunk '%d': 0x%08X", $chunkId, mapi_last_hresult()));
$restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_SUBJECT, VALUE => $chunkName)); $restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_SUBJECT, VALUE => $chunkName));
mapi_table_restrict($table, $restriction); mapi_table_restrict($table, $restriction);
...@@ -432,25 +431,21 @@ class Zarafa extends SyncWorker { ...@@ -432,25 +431,21 @@ class Zarafa extends SyncWorker {
else else
$entryid = @mapi_msgstore_createentryid($this->defaultstore, $user); $entryid = @mapi_msgstore_createentryid($this->defaultstore, $user);
if($entryid) { if(!$entryid) {
$store = @mapi_openmsgstore($this->session, $entryid); $this->Terminate(sprintf("Zarafa->openMessageStore(): No store found for user '%s': 0x%08X - Aborting.", $user, mapi_last_hresult));
if (!$store) {
$this->Terminate(sprintf("Zarafa->openMessageStore(): Could not open store for '%s'. Aborting.", $user));
return false;
}
$this->Log(sprintf("Zarafa->openMessageStore(): Found '%s' store of user '%s': '%s'", (($return_public)?'PUBLIC':'DEFAULT'), $user, $store));
return $store;
} }
else {
$this->Terminate(sprintf("Zarafa->openMessageStore(): No store found for user '%s'. Aborting.", $user)); $store = @mapi_openmsgstore($this->session, $entryid);
return false; if (!$store) {
$this->Terminate(sprintf("Zarafa->openMessageStore(): Could not open store for '%s': 0x%08X - Aborting.", $user, mapi_last_hresult));
} }
$this->Log(sprintf("Zarafa->openMessageStore(): Found '%s' store of user '%s': '%s'", (($return_public)?'PUBLIC':'DEFAULT'), $user, $store));
return $store;
} }
/** /**
* Opens the root folder, either in a users' store or of the public folder. * Opens the root folder, either in a user's store or of the public folder.
* *
* @access private * @access private
* @return ressource * @return ressource
...@@ -474,11 +469,11 @@ class Zarafa extends SyncWorker { ...@@ -474,11 +469,11 @@ class Zarafa extends SyncWorker {
} }
if (!$parentfentryid) if (!$parentfentryid)
$this->Terminate("Zarafa->getRootFolder(): Error, unable to open parent folder (no entry id)"); $this->Terminate(sprintf("Zarafa->getRootFolder(): Error, unable to open parent folder (no entry id): 0x%08X", mapi_last_hresult()));
$parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid); $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
if (!$parentfolder) if (!$parentfolder)
$this->Terminate("Zarafa->CreateHiddenPublicFolder(): Error, unable to open parent folder (open entry)"); $this->Terminate(sprintf("Zarafa->CreateHiddenPublicFolder(): Error, unable to open parent folder (open entry): 0x%08X", mapi_last_hresult()));
$this->folderCache[$rootId] = $parentfolder; $this->folderCache[$rootId] = $parentfolder;
} }
...@@ -496,7 +491,7 @@ class Zarafa extends SyncWorker { ...@@ -496,7 +491,7 @@ class Zarafa extends SyncWorker {
if (!isset($this->folderCache[$folderid])) { if (!isset($this->folderCache[$folderid])) {
$folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid)); $folderentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($folderid));
if (!$folderentryid) if (!$folderentryid)
$this->Terminate("Zarafa->getFolder: Error, unable to open folder (no entry id)."); $this->Terminate(sprintf("Zarafa->getFolder: Error, unable to open folder (no entry id): 0x%08X", mapi_last_hresult()));
$this->folderCache[$folderid] = mapi_msgstore_openentry($this->store, $folderentryid); $this->folderCache[$folderid] = mapi_msgstore_openentry($this->store, $folderentryid);
} }
...@@ -509,7 +504,7 @@ class Zarafa extends SyncWorker { ...@@ -509,7 +504,7 @@ class Zarafa extends SyncWorker {
* *
* @param string $value * @param string $value
* *
* @access public * @access private
* @return mapi property * @return mapi property
*/ */
private function getPropertyForGABvalue($value) { private function getPropertyForGABvalue($value) {
...@@ -534,10 +529,10 @@ class Zarafa extends SyncWorker { ...@@ -534,10 +529,10 @@ class Zarafa extends SyncWorker {
* @param MAPIMessage $message * @param MAPIMessage $message
* @param long $prop * @param long $prop
* *
* @access public * @access private
* @return string * @return string
*/ */
public function readPropStream($message, $prop) { private function readPropStream($message, $prop) {
$stream = mapi_openproperty($message, $prop, IID_IStream, 0, 0); $stream = mapi_openproperty($message, $prop, IID_IStream, 0, 0);
$ret = mapi_last_hresult(); $ret = mapi_last_hresult();
if ($ret == MAPI_E_NOT_FOUND) { if ($ret == MAPI_E_NOT_FOUND) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment