Commit ab8c0153 authored by jaapjansma's avatar jaapjansma

Fixed issue with existing cases.

parent 72d09261
...@@ -137,7 +137,6 @@ function _sharepoint_ensure_case_documentset($case_id, $contact_id, $case_title) ...@@ -137,7 +137,6 @@ function _sharepoint_ensure_case_documentset($case_id, $contact_id, $case_title)
$settings = _sharepoint_settings(); $settings = _sharepoint_settings();
$documentSet = _sharepoint_create_documentset('case_'.$case_id, $settings['case_documentset_contenttype_id']); $documentSet = _sharepoint_create_documentset('case_'.$case_id, $settings['case_documentset_contenttype_id']);
$documentSet = _sharepoint_update_case_documentset($documentSet, $case_id, $contact_id, $case_title); $documentSet = _sharepoint_update_case_documentset($documentSet, $case_id, $contact_id, $case_title);
} }
if (!$documentSet) { if (!$documentSet) {
throw new \Exception('Could not ensure document set in sharepoint for contact with id: '.$contact_id); throw new \Exception('Could not ensure document set in sharepoint for contact with id: '.$contact_id);
...@@ -230,7 +229,7 @@ function _sharepoint_ensure_contact_documentset($contact_id) { ...@@ -230,7 +229,7 @@ function _sharepoint_ensure_contact_documentset($contact_id) {
$documentSet = _sharepoint_get_contact_documentset($contact_id); $documentSet = _sharepoint_get_contact_documentset($contact_id);
if (!$documentSet) { if (!$documentSet) {
$settings = _sharepoint_settings(); $settings = _sharepoint_settings();
$documentSet = _sharepoint_create_documentset($contact_id, $settings['contact_documentset_contenttype_id']); $documentSet = _sharepoint_create_documentset('contact_'.$contact_id, $settings['contact_documentset_contenttype_id']);
$contact_name = _sharepoint_get_foldername_for_contact($contact_id); $contact_name = _sharepoint_get_foldername_for_contact($contact_id);
$documentSet = _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name); $documentSet = _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name);
...@@ -257,14 +256,17 @@ function _sharepoint_get_contact_documentset($contact_id) { ...@@ -257,14 +256,17 @@ function _sharepoint_get_contact_documentset($contact_id) {
$ctx->load($documentSets); $ctx->load($documentSets);
$ctx->executeQuery(); $ctx->executeQuery();
if ($documentSets->getCount() > 0) { if ($documentSets->getCount() > 0) {
$documentSet = $documentSets->getItem(0); foreach($documentSets->getData() as $documentSet) {
$contact_name = _sharepoint_get_foldername_for_contact($contact_id); if ($documentSet->case_id) {
continue;
if ($documentSet->Title != $contact_name) { }
return _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name);
$contact_name = _sharepoint_get_foldername_for_contact($contact_id);
if ($documentSet->Title != $contact_name) {
return _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name);
}
return $documentSet;
} }
return $documentSet;
} }
return null; return null;
} }
...@@ -291,10 +293,15 @@ function _sharepoint_update_contact_documentset(\Office365\PHP\Client\Runtime\Cl ...@@ -291,10 +293,15 @@ function _sharepoint_update_contact_documentset(\Office365\PHP\Client\Runtime\Cl
$documentSets = $ctx->getWeb()->getLists()->getByTitle($settings['library'])->getItems()->filter("{$settings['contact_id_field_name']} eq {$contact_id} and startswith(ContentTypeId,'{$settings['contact_documentset_contenttype_id']}')")->expand('Folder'); $documentSets = $ctx->getWeb()->getLists()->getByTitle($settings['library'])->getItems()->filter("{$settings['contact_id_field_name']} eq {$contact_id} and startswith(ContentTypeId,'{$settings['contact_documentset_contenttype_id']}')")->expand('Folder');
$ctx->load($documentSets); $ctx->load($documentSets);
$ctx->executeQuery(); $ctx->executeQuery();
if ($documentSets->getCount() < 1) { if ($documentSets->getCount() > 0) {
throw new \Exception('Could not find document set for contact with id: '.$contact_id); foreach ($documentSets->getData() as $documentSet) {
if (!$documentSet->case_id) {
return $documentSet;
}
}
} }
return $documentSets->getItem(0);
throw new \Exception('Could not find document set for contact with id: '.$contact_id);
} }
/** /**
......
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