Use UID for find_content(); code cleanups

This commit is contained in:
Jörg Lehrke 2009-12-01 10:24:55 +00:00
parent c63a538f13
commit dd92e60180
6 changed files with 83 additions and 56 deletions

View File

@ -441,10 +441,10 @@ class addressbook_bo extends addressbook_so
}
return $updated;
}
/**
* Cleanup all contacts db fields of all users (called by Admin >> Addressbook >> Site configuration (Admin only)
*
*
* Cleanup means to truncate all unnecessary chars like whitespaces or tabs,
* remove unneeded carriage returns or set empty fields to NULL
*
@ -457,7 +457,7 @@ class addressbook_bo extends addressbook_so
{
unset($this->somain->grants); // to NOT limit search to contacts readable by current user
}
// fields that must not be touched
$fields_exclude = array(
'id' => true,
@ -475,7 +475,7 @@ class addressbook_bo extends addressbook_so
'calendar_uri' => true,
'photo' => true,
);
// to be able to work on huge contact repositories we read the contacts in chunks of 100
for($n = $updated = $errors = 0; ($contacts = parent::search(array(),false,'','','',false,'OR',array($n*100,100))); ++$n)
{
@ -485,7 +485,7 @@ class addressbook_bo extends addressbook_so
foreach($contact as $field_name => $field_value)
{
if($fields_exclude[$field_name] === true) continue; // dont touch specified field
if (is_string($field_value) && $field_name != 'pubkey' && $field_name != 'jpegphoto')
{
// check if field has to be trimmed
@ -505,7 +505,7 @@ class addressbook_bo extends addressbook_so
$fields_to_update[$field_name] = $field_value = null;
}
}
if(count($fields_to_update) > 0)
{
$contact_to_save = array(
@ -514,7 +514,7 @@ class addressbook_bo extends addressbook_so
'private' => $contact['private'],
'account_id' => $contact['account_id'],
'uid' => $contact['uid']) + $fields_to_update;
if ($this->save($contact_to_save,$ignore_acl))
{
$updated++;
@ -705,7 +705,8 @@ class addressbook_bo extends addressbook_so
return false;
}
// convert categories
if (is_array($contact['cat_id'])) {
if (is_array($contact['cat_id']))
{
$contact['cat_id'] = implode(',',$contact['cat_id']);
}
// last modified
@ -1561,7 +1562,7 @@ class addressbook_bo extends addressbook_so
$cat_id_list[] = $cat_id;
}
}
if(is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
{
$cat_id_list = array_merge($cat_id_list, $old_cats_preserve);
@ -1590,7 +1591,7 @@ class addressbook_bo extends addressbook_so
$cat_list = array();
foreach($cat_id_list as $cat_id)
{
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
{
$cat_list[] = $cat_name;
@ -1635,9 +1636,25 @@ class addressbook_bo extends addressbook_so
*/
function find_contact($contact, $relax=false)
{
if (!empty($contact['uid']))
{
// Try the given UID first
Horde::logMessage('Addressbook find UID: '. $contact['uid'],
__FILE__, __LINE__, PEAR_LOG_DEBUG);
$criteria = array ('contact_uid' => $contact['uid']);
if (($found = parent::search($criteria))
&& ($uidmatch = array_shift($found)))
{
return $uidmatch['contact_id'];
}
}
unset($contact['uid']);
if ($contact['id'] && ($found = $this->read($contact['id'])))
{
// We only do a simple consistency check
Horde::logMessage('Addressbook find ID: '. $contact['id'],
__FILE__, __LINE__, PEAR_LOG_DEBUG);
if ((empty($found['n_family']) || $found['n_family'] == $contact['n_family'])
&& (empty($found['n_given']) || $found['n_given'] == $contact['n_given'])
&& (empty($found['org_name']) || $found['org_name'] == $contact['org_name']))
@ -1647,12 +1664,10 @@ class addressbook_bo extends addressbook_so
}
unset($contact['id']);
$columns_to_search = array('contact_id',
'n_family', 'n_given', 'n_middle', 'n_prefix', 'n_suffix',
$columns_to_search = array('n_family', 'n_given', 'n_middle', 'n_prefix', 'n_suffix',
'bday', 'org_name', 'org_unit', 'title', 'role',
'email', 'email_home');
$tolerance_fields = array('contact_id',
'n_middle', 'n_prefix', 'n_suffix',
$tolerance_fields = array('n_middle', 'n_prefix', 'n_suffix',
'bday', 'org_unit', 'title', 'role',
'email', 'email_home');
$addr_one_fields = array('adr_one_street',

View File

@ -82,9 +82,9 @@ class addressbook_vcal extends addressbook_bo
* Set Logging
*
* @var string
* off = 0;
* off = false;
*/
var $log = 0;
var $log = false;
var $logfile="/tmp/log-vcard";
/**
* Constructor
@ -390,8 +390,11 @@ class addressbook_vcal extends addressbook_bo
}
$result = $vCard->exportvCalendar();
if($this->log)error_log(__LINE__.__METHOD__.__FILE__."'$this->productManufacturer','$this->productName'"."\n",3,$this->logfile);
if($this->log)error_log(__LINE__.__METHOD__.__FILE__."\n".array2string($result)."\n",3,$this->logfile);
if ($this->log)
{
error_log(__LINE__.__METHOD__.__FILE__."'$this->productManufacturer','$this->productName'"."\n",3,$this->logfile);
error_log(__LINE__.__METHOD__.__FILE__."\n".array2string($result)."\n",3,$this->logfile);
}
return $result;
}
@ -403,7 +406,7 @@ class addressbook_vcal extends addressbook_bo
{
if ($contentID)
{
$contact['contact_id'] = $contentID;
$contact['id'] = $contentID;
}
$result = $this->find_contact($contact, $relax);
}

View File

@ -216,6 +216,8 @@ class calendar_bo
$this->config = config::read('calendar'); // only used for horizont, regular calendar config is under phpgwapi
$this->require_acl_invite = $GLOBALS['egw_info']['server']['require_acl_invite'];
$this->categories = new categories($this->user,'calendar');
}
/**
@ -1314,10 +1316,7 @@ class calendar_bo
static $id2cat = array();
$cats = array();
$color = 0;
if (!is_object($this->categories))
{
$this->categories = new categories($this->user,'calendar');
}
foreach(explode(',',$category) as $cat_id)
{
if (!$cat_id) continue;

View File

@ -1135,22 +1135,17 @@ class calendar_boupdate extends calendar_bo
*/
function find_or_add_categories($catname_list, $cal_id=-1)
{
if (!is_object($this->categories))
{
$this->categories = new categories($this->user,'calendar');
}
if($cal_id && $cal_id > 0)
if ($cal_id && $cal_id > 0)
{
// preserve categories without users read access
$old_event = $this->read($cal_id);
$old_categories = explode(',',$old_event['category']);
$old_cats_preserve = array();
if(is_array($old_categories) && count($old_categories) > 0)
if (is_array($old_categories) && count($old_categories) > 0)
{
foreach($old_categories as $cat_id)
foreach ($old_categories as $cat_id)
{
if(!$this->categories->check_perms(EGW_ACL_READ, $cat_id))
if (!$this->categories->check_perms(EGW_ACL_READ, $cat_id))
{
$old_cats_preserve[] = $cat_id;
}
@ -1159,7 +1154,7 @@ class calendar_boupdate extends calendar_bo
}
$cat_id_list = array();
foreach($catname_list as $cat_name)
foreach ($catname_list as $cat_name)
{
$cat_name = trim($cat_name);
$cat_id = $this->categories->name2id($cat_name, 'X-');
@ -1180,7 +1175,7 @@ class calendar_boupdate extends calendar_bo
}
}
if(is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
if (is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
{
$cat_id_list = array_merge($cat_id_list, $old_cats_preserve);
}
@ -1196,17 +1191,12 @@ class calendar_boupdate extends calendar_bo
function get_categories($cat_id_list)
{
if (!is_object($this->categories))
{
$this->categories = new categories($this->user,'calendar');
}
if (!is_array($cat_id_list))
{
$cat_id_list = explode(',',$cat_id_list);
}
$cat_list = array();
foreach($cat_id_list as $cat_id)
foreach ($cat_id_list as $cat_id)
{
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
@ -1227,10 +1217,15 @@ class calendar_boupdate extends calendar_bo
*/
function find_event($event, $relax=false)
{
$query = array(
'cal_start='.$event['start'],
'cal_end='.$event['end'],
);
$query = array();
if (isset($event['start']))
{
$query[] = 'cal_start='.$event['start'];
}
if (isset($event['end']))
{
$query[] = 'cal_end='.$event['end'];
}
foreach (array('title', 'location',
'public', 'non_blocking', 'category') as $key)
@ -1246,7 +1241,7 @@ class calendar_boupdate extends calendar_bo
$query['cal_uid'] = $event['uid'];
$query['cal_recurrence'] = $event['recurrence'];
if($foundEvents = parent::search(array(
if ($foundEvents = parent::search(array(
'query' => $query,
)))
{
@ -1261,7 +1256,7 @@ class calendar_boupdate extends calendar_bo
{
// Do we work with a pseudo exception here?
$match = true;
foreach (array('start', 'end', 'title', 'description', 'priority',
foreach (array('start', 'end', 'title', 'priority',
'location', 'public', 'non_blocking') as $key)
{
if (isset($event[$key])

View File

@ -24,6 +24,15 @@ class calendar_ical extends calendar_boupdate
*/
var $supportedFields;
var $recur_days_1_0 = array(
MCAL_M_MONDAY => 'MO',
MCAL_M_TUESDAY => 'TU',
MCAL_M_WEDNESDAY => 'WE',
MCAL_M_THURSDAY => 'TH',
MCAL_M_FRIDAY => 'FR',
MCAL_M_SATURDAY => 'SA',
MCAL_M_SUNDAY => 'SU',
);
/**
* @var array $status_egw2ical conversation of the participant status egw => ical
*/
@ -1356,6 +1365,10 @@ class calendar_ical extends calendar_boupdate
}
break;
case 'funambol':
$this->supportedFields = $defaultFields['synthesis'];
break;
// the fallback for SyncML
default:
error_log("Unknown calendar SyncML client: manufacturer='$this->productManufacturer' product='$this->productName'");

View File

@ -1088,7 +1088,7 @@ class infolog_bo
{
$this->categories = new categories($this->user,'infolog');
}
if($info_id && $info_id > 0)
{
// preserve categories without users read access
@ -1112,7 +1112,7 @@ class infolog_bo
{
$cat_name = trim($cat_name);
$cat_id = $this->categories->name2id($cat_name, 'X-');
if (!$cat_id)
{
// some SyncML clients (mostly phones) add an X- to the category names
@ -1128,7 +1128,7 @@ class infolog_bo
$cat_id_list[] = $cat_id;
}
}
if(is_array($old_cats_preserve) && count($old_cats_preserve) > 0)
{
$cat_id_list = array_merge($old_cats_preserve, $cat_id_list);
@ -1165,7 +1165,7 @@ class infolog_bo
$cat_list = array();
foreach($cat_id_list as $cat_id)
{
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
if ($cat_id && $this->categories->check_perms(EGW_ACL_READ, $cat_id) &&
($cat_name = $this->categories->id2name($cat_id)) && $cat_name != '--')
{
$cat_list[] = $cat_name;
@ -1366,13 +1366,15 @@ class infolog_bo
*/
function findVTODO($egwData, $relax=false)
{
$myfilter = array('col_filter' => array('info_uid'=>$egwData['info_uid'])) ;
if ($egwData['info_uid']
&& ($found = $this->search($myfilter))
&& ($uidmatch = array_shift($found)))
if (!empty($egwData['info_uid']))
{
return $uidmatch['info_id'];
};
$filter = array('col_filter' => array('info_uid' => $egwData['info_uid']));
if (($found = $this->search($filter))
&& ($uidmatch = array_shift($found)))
{
return $uidmatch['info_id'];
}
}
unset($egwData['info_uid']);
$filter = array();