* AD: use thumbmailPhoto, if jpegPhoto is empty

This commit is contained in:
ralf 2023-08-24 13:35:35 +02:00
parent 705554ec14
commit c6b77bea91
3 changed files with 33 additions and 13 deletions

View File

@ -274,7 +274,7 @@ class Import
do do
{ {
$contact = $reconnected = null; $contact = $reconnected = null;
foreach ($this->contacts->search('', false, '', 'account_lid', '', '', 'AND', $start, $filter) as $contact) foreach ($this->contacts->search('', false, '', ['account_lid', 'jpegphoto'], '', '', 'AND', $start, $filter) as $contact)
{ {
// if we have a regexp to filter the DN, continue on non-match // if we have a regexp to filter the DN, continue on non-match
if (!empty($GLOBALS['egw_info']['server']['account_import_dn_regexp']) && if (!empty($GLOBALS['egw_info']['server']['account_import_dn_regexp']) &&
@ -288,7 +288,9 @@ class Import
$last_modified = $contact['modified']; $last_modified = $contact['modified'];
} }
$account = $this->accounts->read($contact['account_id']); $account = $this->accounts->read($contact['account_id']);
$this->logger(++$num.'. User: '.json_encode($contact + $account, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE), 'debug'); // do NOT log binary content of image
$hide_binary = ['jpegphoto' => $contact['jpegphoto'] ? bytes($contact['jpegphoto']).' bytes binary data' : null];
$this->logger(++$num.'. User: '.json_encode($hide_binary + $contact + $account, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE), 'debug');
// check if account exists in sql // check if account exists in sql
if (!($account_id = $this->accounts_sql->name2id($account['account_lid']))) if (!($account_id = $this->accounts_sql->name2id($account['account_lid'])))
{ {

View File

@ -144,6 +144,7 @@ class Ads extends Ldap
$this->all_attributes = array_merge($this->all_attributes,array_values($attributes)); $this->all_attributes = array_merge($this->all_attributes,array_values($attributes));
} }
$this->all_attributes = array_values(array_unique($this->all_attributes)); $this->all_attributes = array_values(array_unique($this->all_attributes));
$this->all_attributes[] = 'thumbnailphoto'; // read as alternative to jpegphoto
$this->charset = Api\Translation::charset(); $this->charset = Api\Translation::charset();
} }
@ -226,7 +227,9 @@ class Ads extends Ldap
(isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']); (isset ($_contact_id['id']) ? $_contact_id['id'] : $_contact_id['uid']);
try { try {
$rows = $this->_searchLDAP($this->allContactsDN, $filter = $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL); $start = null;
$rows = $this->_searchLDAP($this->allContactsDN, $this->id_filter($contact_id), $this->all_attributes, Ldap::ALL,
null, null, $start, true);
} }
catch (Api\Exception\AssertionFailed $e) { catch (Api\Exception\AssertionFailed $e) {
$rows = null; $rows = null;

View File

@ -516,8 +516,9 @@ class Ldap
if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid']; if (is_array($contact_id)) $contact_id = isset ($contact_id['id']) ? $contact_id['id'] : $contact_id['uid'];
$filter = $this->id_filter($contact_id); $filter = $this->id_filter($contact_id);
} }
$rows = $this->_searchLDAP($this->allContactsDN, $start = null;
$filter, $this->all_attributes, self::ALL, array('_posixaccount2egw')); $rows = $this->_searchLDAP($this->allContactsDN, $filter, $this->all_attributes, self::ALL,
['_posixaccount2egw'], null, $start, true);
return $rows ? $rows[0] : false; return $rows ? $rows[0] : false;
} }
@ -821,7 +822,7 @@ class Ldap
function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false) function &search($criteria,$only_keys=True,$order_by='',$extra_cols='',$wildcard='',$empty=False,$op='AND',$start=false,$filter=null,$join='',$need_full_no_count=false)
{ {
//error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).")"); //error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).")");
unset($only_keys, $extra_cols, $empty, $join, $need_full_no_count); // not used, but required by function signature $read_photo = $extra_cols ? in_array('jpegphoto', is_array($extra_cols) ? $extra_cols : explode(',', $extra_cols)) : false;
if (is_array($filter['owner'])) if (is_array($filter['owner']))
{ {
@ -955,7 +956,7 @@ class Ldap
$colFilter = $this->_colFilter($filter); $colFilter = $this->_colFilter($filter);
$ldapFilter = "(&$objectFilter$searchFilter$colFilter$datefilter)"; $ldapFilter = "(&$objectFilter$searchFilter$colFilter$datefilter)";
//error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).") --> ldapFilter='$ldapFilter'"); //error_log(__METHOD__."(".array2string($criteria).", ".array2string($only_keys).", '$order_by', ".array2string($extra_cols).", '$wildcard', '$empty', '$op', ".array2string($start).", ".array2string($filter).") --> ldapFilter='$ldapFilter'");
if (!($rows = $this->_searchLDAP($searchDN, $ldapFilter, $this->all_attributes, $addressbookType, [], $order_by, $start))) if (!($rows = $this->_searchLDAP($searchDN, $ldapFilter, $this->all_attributes, $addressbookType, [], $order_by, $start, $read_photo)))
{ {
return $rows; return $rows;
} }
@ -1212,9 +1213,10 @@ class Ldap
* @param array $_skipPlugins =null schema-plugins to skip * @param array $_skipPlugins =null schema-plugins to skip
* @param string $order_by sql order string eg. "contact_email ASC" * @param string $order_by sql order string eg. "contact_email ASC"
* @param null|int|array $start [$start, $num_rows], on return null, if result sorted and limited by server * @param null|int|array $start [$start, $num_rows], on return null, if result sorted and limited by server
* @param bool $read_photo true: return the binary content of the image, false: return true or false if there is an image or not
* @return array/boolean with eGW contacts or false on error * @return array/boolean with eGW contacts or false on error
*/ */
function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null, $order_by=null, &$start=null) function _searchLDAP($_ldapContext, $_filter, $_attributes, $_addressbooktype, array $_skipPlugins=null, $order_by=null, &$start=null, bool $read_photo=false)
{ {
$_attributes[] = 'entryUUID'; $_attributes[] = 'entryUUID';
$_attributes[] = 'objectClass'; $_attributes[] = 'objectClass';
@ -1300,6 +1302,11 @@ class Ldap
{ {
if (!is_int($i)) continue; // eg. count if (!is_int($i)) continue; // eg. count
if ($read_photo)
{
$result_entry = $i ? ldap_next_entry($this->ds, $result_entry) : ldap_first_entry($this->ds, $result);
}
$contact = array( $contact = array(
'id' => $entry['uid'][0] ?? $entry['entryuuid'][0], 'id' => $entry['uid'][0] ?? $entry['entryuuid'][0],
'dn' => $entry['dn'], 'dn' => $entry['dn'],
@ -1329,15 +1336,23 @@ class Ldap
$this->$objectclass2egw($contact,$entry); $this->$objectclass2egw($contact,$entry);
} }
} }
// read binary jpegphoto only for one result == call by read // read photos from both jpegphoto and thumbnailphoto
if ($this->total == 1 && isset($entry['jpegphoto'][0])) if (isset($entry[$photo='jpegphoto'][0]) || isset($entry[$photo='thumbnailphoto'][0]))
{ {
$bin = ldap_get_values_len($this->ds,ldap_first_entry($this->ds,$result),'jpegphoto'); // read binary jpegphoto only for one result == call by read
$contact['jpegphoto'] = $bin[0]; if ($read_photo)
{
$bin = ldap_get_values_len($this->ds, $result_entry, $photo);
$contact['jpegphoto'] = $bin[0];
}
else
{
$contact['jpegphoto'] = true;
}
} }
else else
{ {
$contact['jpegphoto'] = isset($entry['jpegphoto'][0]); $contact['jpegphoto'] = false;
} }
$matches = null; $matches = null;
if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches)) if(preg_match('/cn=([^,]+),'.preg_quote($this->personalContactsDN,'/').'$/i',$entry['dn'],$matches))