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)
$settings = _sharepoint_settings();
$documentSet = _sharepoint_create_documentset('case_'.$case_id, $settings['case_documentset_contenttype_id']);
$documentSet = _sharepoint_update_case_documentset($documentSet, $case_id, $contact_id, $case_title);
}
if (!$documentSet) {
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) {
$documentSet = _sharepoint_get_contact_documentset($contact_id);
if (!$documentSet) {
$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);
$documentSet = _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name);
......@@ -257,14 +256,17 @@ function _sharepoint_get_contact_documentset($contact_id) {
$ctx->load($documentSets);
$ctx->executeQuery();
if ($documentSets->getCount() > 0) {
$documentSet = $documentSets->getItem(0);
$contact_name = _sharepoint_get_foldername_for_contact($contact_id);
if ($documentSet->Title != $contact_name) {
return _sharepoint_update_contact_documentset($documentSet, $contact_id, $contact_name);
foreach($documentSets->getData() as $documentSet) {
if ($documentSet->case_id) {
continue;
}
$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;
}
......@@ -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');
$ctx->load($documentSets);
$ctx->executeQuery();
if ($documentSets->getCount() < 1) {
throw new \Exception('Could not find document set for contact with id: '.$contact_id);
if ($documentSets->getCount() > 0) {
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