Use UID for find_content(); code cleanups

This commit is contained in:
Jörg Lehrke 2009-12-01 11:21:44 +00:00
parent a1ee7d5cbf
commit 54fd41a16a
6 changed files with 76 additions and 49 deletions

View File

@ -119,6 +119,12 @@ class addressbook_bo extends addressbook_so
* @var boolean * @var boolean
*/ */
var $default_private; var $default_private;
/**
* Categories object
*
* @var object
*/
var $categories;
function __construct($contact_app='addressbook') function __construct($contact_app='addressbook')
{ {
@ -245,6 +251,7 @@ class addressbook_bo extends addressbook_so
{ {
$this->org_fields = unserialize($GLOBALS['egw_info']['server']['org_fileds_to_update']); $this->org_fields = unserialize($GLOBALS['egw_info']['server']['org_fileds_to_update']);
} }
$this->categories = new categories($this->user,'addressbook');
} }
/** /**
@ -1418,8 +1425,6 @@ class addressbook_bo extends addressbook_so
return $adr_format; return $adr_format;
} }
var $categories;
/** /**
* Find existing categories in database by name or add categories that do not exist yet * Find existing categories in database by name or add categories that do not exist yet
* currently used for vcard import * currently used for vcard import
@ -1431,11 +1436,6 @@ class addressbook_bo extends addressbook_so
*/ */
function find_or_add_categories($catname_list, $contact_id=null) function find_or_add_categories($catname_list, $contact_id=null)
{ {
if (!is_object($this->categories))
{
$this->categories = new categories($this->owner,'addressbook');
}
if($contact_id && $contact_id > 0) if($contact_id && $contact_id > 0)
{ {
// preserve categories without users read access // preserve categories without users read access
@ -1549,9 +1549,25 @@ class addressbook_bo extends addressbook_so
*/ */
function find_contact($contact, $relax=false) 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']))) if ($contact['id'] && ($found = $this->read($contact['id'])))
{ {
// We only do a simple consistency check // 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']) if ((empty($found['n_family']) || $found['n_family'] == $contact['n_family'])
&& (empty($found['n_given']) || $found['n_given'] == $contact['n_given']) && (empty($found['n_given']) || $found['n_given'] == $contact['n_given'])
&& (empty($found['org_name']) || $found['org_name'] == $contact['org_name'])) && (empty($found['org_name']) || $found['org_name'] == $contact['org_name']))
@ -1561,12 +1577,10 @@ class addressbook_bo extends addressbook_so
} }
unset($contact['id']); unset($contact['id']);
$columns_to_search = array('contact_id', $columns_to_search = array('n_family', 'n_given', 'n_middle', 'n_prefix', 'n_suffix',
'n_family', 'n_given', 'n_middle', 'n_prefix', 'n_suffix',
'bday', 'org_name', 'org_unit', 'title', 'role', 'bday', 'org_name', 'org_unit', 'title', 'role',
'email', 'email_home'); 'email', 'email_home');
$tolerance_fields = array('contact_id', $tolerance_fields = array('n_middle', 'n_prefix', 'n_suffix',
'n_middle', 'n_prefix', 'n_suffix',
'bday', 'org_unit', 'title', 'role', 'bday', 'org_unit', 'title', 'role',
'email', 'email_home'); 'email', 'email_home');
$addr_one_fields = array('adr_one_street', $addr_one_fields = array('adr_one_street',

View File

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

View File

@ -163,6 +163,12 @@ class calendar_bo
* @var egw_datetime * @var egw_datetime
*/ */
var $datetime; var $datetime;
/**
* Instance of the categories class
*
* @var $categories
*/
var $categories;
/** /**
* Constructor * Constructor
@ -209,6 +215,8 @@ class calendar_bo
//echo "registered resources="; _debug_array($this->resources); //echo "registered resources="; _debug_array($this->resources);
$this->config = config::read('calendar'); $this->config = config::read('calendar');
$this->categories = new categories($this->user,'calendar');
} }
/** /**
@ -1567,17 +1575,14 @@ class calendar_bo
static $id2cat = array(); static $id2cat = array();
$cats = array(); $cats = array();
$color = 0; $color = 0;
if (!is_object($this->cats))
{
$this->cats = CreateObject('phpgwapi.categories','','calendar');
}
foreach(explode(',',$category) as $cat_id) foreach(explode(',',$category) as $cat_id)
{ {
if (!$cat_id) continue; if (!$cat_id) continue;
if (!isset($id2cat[$cat_id])) if (!isset($id2cat[$cat_id]))
{ {
list($id2cat[$cat_id]) = $this->cats->return_single($cat_id); list($id2cat[$cat_id]) = $this->categories->return_single($cat_id);
$id2cat[$cat_id]['data'] = unserialize($id2cat[$cat_id]['data']); $id2cat[$cat_id]['data'] = unserialize($id2cat[$cat_id]['data']);
} }
$cat = $id2cat[$cat_id]; $cat = $id2cat[$cat_id];

View File

@ -1050,8 +1050,6 @@ class calendar_boupdate extends calendar_bo
return $this->so->delete_alarm($id, $this->now_su); return $this->so->delete_alarm($id, $this->now_su);
} }
var $categories;
/** /**
* Find existing categories in database by name or add categories that do not exist yet * Find existing categories in database by name or add categories that do not exist yet
* currently used for ical/sif import * currently used for ical/sif import
@ -1063,11 +1061,6 @@ class calendar_boupdate extends calendar_bo
*/ */
function find_or_add_categories($catname_list, $cal_id=-1) 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 // preserve categories without users read access
@ -1124,11 +1117,6 @@ class calendar_boupdate extends calendar_bo
function get_categories($cat_id_list) function get_categories($cat_id_list)
{ {
if (!is_object($this->categories))
{
$this->categories = new categories($this->user,'calendar');
}
if (!is_array($cat_id_list)) if (!is_array($cat_id_list))
{ {
$cat_id_list = explode(',',$cat_id_list); $cat_id_list = explode(',',$cat_id_list);
@ -1155,10 +1143,15 @@ class calendar_boupdate extends calendar_bo
*/ */
function find_event($event, $relax=false) function find_event($event, $relax=false)
{ {
$query = array( $query = array();
'cal_start='.$event['start'], if (isset($event['start']))
'cal_end='.$event['end'], {
); $query[] = 'cal_start='.$event['start'];
}
if (isset($event['end']))
{
$query[] = 'cal_end='.$event['end'];
}
foreach (array('title', 'location', foreach (array('title', 'location',
'public', 'non_blocking', 'category') as $key) 'public', 'non_blocking', 'category') as $key)
@ -1189,7 +1182,7 @@ class calendar_boupdate extends calendar_bo
{ {
// Do we work with a pseudo exception here? // Do we work with a pseudo exception here?
$match = true; $match = true;
foreach (array('start', 'end', 'title', 'description', 'priority', foreach (array('start', 'end', 'title', 'priority',
'location', 'public', 'non_blocking') as $key) 'location', 'public', 'non_blocking') as $key)
{ {
if (isset($event[$key]) if (isset($event[$key])

View File

@ -1425,6 +1425,10 @@ class calendar_ical extends calendar_boupdate
} }
break; break;
case 'funambol':
$this->supportedFields = $defaultFields['synthesis'];
break;
// the fallback for SyncML // the fallback for SyncML
default: default:
error_log("Unknown calendar SyncML client: manufacturer='$this->productManufacturer' product='$this->productName'"); error_log("Unknown calendar SyncML client: manufacturer='$this->productManufacturer' product='$this->productName'");

View File

@ -704,7 +704,8 @@ class infolog_bo
); );
} }
$values['info_id'] = $info_id; $values['info_id'] = $info_id;
// if the info responbsible array is not passed, fetch it from old.
if (!array_key_exists('info_responsible',$values)) $values['info_responsible'] = $old['info_responsible'];
if (!is_array($values['info_responsible'])) // this should not happen, bug it does ;-) if (!is_array($values['info_responsible'])) // this should not happen, bug it does ;-)
{ {
$values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array(); $values['info_responsible'] = $values['info_responsible'] ? explode(',',$values['info_responsible']) : array();
@ -723,6 +724,11 @@ class infolog_bo
{ {
$this->tracking = new infolog_tracking($this); $this->tracking = new infolog_tracking($this);
} }
if (($missing_fields = array_diff_key($old,$values)))
{
$values = array_merge($values,$missing_fields);
}
$this->tracking->track($values,$old,$this->user,$values['info_status'] == 'deleted' || $old['info_status'] == 'deleted'); $this->tracking->track($values,$old,$this->user,$values['info_status'] == 'deleted' || $old['info_status'] == 'deleted');
} }
if ($info_from_set) $values['info_from'] = ''; if ($info_from_set) $values['info_from'] = '';
@ -1360,13 +1366,15 @@ class infolog_bo
*/ */
function findVTODO($egwData, $relax=false) function findVTODO($egwData, $relax=false)
{ {
$myfilter = array('col_filter' => array('info_uid'=>$egwData['info_uid'])) ; if (!empty($egwData['info_uid']))
if ($egwData['info_uid']
&& ($found = $this->search($myfilter))
&& ($uidmatch = array_shift($found)))
{ {
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']); unset($egwData['info_uid']);
$filter = array(); $filter = array();