2005-02-28 00:29:40 +01:00
< ? php
/*************************************************************************** \
* eGroupWare - content history class *
* http :// www . egroupware . org *
* Written by : Lars Kneschke [ lkneschke @ linux - at - work . de ] *
* ------------------------------------------------- *
* This program is free software ; you can redistribute it and / or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation ; either version 2 of the License . *
\ ***************************************************************************/
/* $Id$ */
/**
* class to maintain history of content
*
* This class contains all logic of the egw content history .
* @ package phpgwapi
* @ author Lars Kneschke
* @ version 1.35
* @ copyright Lars Kneschke 2005
* @ license http :// opensource . org / licenses / gpl - license . php GPL
*/
class contenthistory
{
2005-03-30 10:16:31 +02:00
/**
* @ var db - object $this -> db
*/
var $db ;
function contenthistory ()
{
$this -> db = clone ( $GLOBALS [ 'egw' ] -> db );
$this -> db -> set_app ( 'phpgwapi' );
$this -> table = 'egw_api_content_history' ;
}
2005-02-28 00:29:40 +01:00
2005-06-19 20:07:06 +02:00
/**
* mark mapping as expired
*
* mark a mapping from externel to internal id as expired , when
* a egw entry gets deleted
*
* @ param $_appName string the appname example : infolog_notes
* @ param $_id int the internal egwapp content id
* @ return bool
*/
function expireMapping ( $_appName , $_id )
{
$where = array (
'map_guid' => $GLOBALS [ 'egw' ] -> common -> generate_uid ( $_appName , $_id ),
);
$newData = array (
'map_expired' => 1 ,
);
if ( ! $this -> db -> update ( 'egw_contentmap' , $newData , $where , __LINE__ , __FILE__ ))
return FALSE ;
else
return TRUE ;
}
2005-02-28 00:29:40 +01:00
/**
* get the timestamp for action
*
* find which content changed since $_ts for application $_appName
*
* @ param $_appName string the appname example : infolog_notes
* @ param $_action string can be modify , add or delete
* @ param $_ts string timestamp where to start searching from
* @ return array containing the global UID ' s
*/
function getHistory ( $_appName , $_action , $_ts )
{
2005-06-19 20:07:06 +02:00
$query = " select sync_guid from egw_api_content_history where sync_appname = ' " . $this -> db -> db_addslashes ( $_appName ) . " ' and " ;
2005-02-28 00:29:40 +01:00
switch ( $_action )
{
case 'modify' :
2006-04-07 10:22:46 +02:00
$query .= " sync_modified > ' " . $this -> db -> to_timestamp ( $_ts ) . " ' and (sync_deleted is null or sync_deleted = '0') " ;
2005-02-28 00:29:40 +01:00
break ;
case 'delete' :
2005-06-19 20:07:06 +02:00
$query .= " sync_deleted > ' " . $this -> db -> to_timestamp ( $_ts ) . " ' " ;
2005-02-28 00:29:40 +01:00
break ;
case 'add' :
2006-04-07 10:22:46 +02:00
$query .= " sync_added > ' " . $this -> db -> to_timestamp ( $_ts ) . " ' and (sync_deleted is null or sync_deleted = '0') and (sync_modified is null or sync_modified = '0') " ;
2005-02-28 00:29:40 +01:00
break ;
default :
// no valid $_action set
return array ();
2005-06-19 20:07:06 +02:00
break ;
2005-02-28 00:29:40 +01:00
}
2006-04-07 10:22:46 +02:00
#Horde::logMessage("SymcML: egwcontactssync $query", __FILE__, __LINE__, PEAR_LOG_DEBUG);
2005-06-19 20:07:06 +02:00
$this -> db -> query ( $query , __LINE__ , __FILE__ );
2005-02-28 00:29:40 +01:00
2005-03-30 10:16:31 +02:00
$guidList = array ();
2005-06-19 20:07:06 +02:00
2005-03-30 10:16:31 +02:00
while ( $this -> db -> next_record ())
2005-02-28 00:29:40 +01:00
{
2005-03-30 10:16:31 +02:00
$guidList [] = $this -> db -> f ( 'sync_guid' );
2005-02-28 00:29:40 +01:00
}
2005-06-19 20:07:06 +02:00
2005-03-30 10:16:31 +02:00
return $guidList ;
2005-02-28 00:29:40 +01:00
}
/**
* when got a entry last added / modified / deleted
*
* @ param $_guid string the global uid of the entry
* @ param $_action string can be add , delete or modify
* @ return string the last timestamp
*/
function getTSforAction ( $_guid , $_action )
{
$where = array (
'sync_guid' => $_guid ,
);
2005-03-30 10:16:31 +02:00
$this -> db -> select ( $this -> table , array ( 'sync_added' , 'sync_modified' , 'sync_deleted' ), $where , __LINE__ , __FILE__ );
if ( $this -> db -> next_record ())
2005-02-28 00:29:40 +01:00
{
switch ( $_action )
{
case 'add' :
2005-03-30 10:16:31 +02:00
return $this -> db -> from_timestamp ( $this -> db -> f ( 'sync_added' ));
2005-06-19 20:07:06 +02:00
break ;
2005-02-28 00:29:40 +01:00
case 'delete' :
2005-03-30 10:16:31 +02:00
return $this -> db -> from_timestamp ( $this -> db -> f ( 'sync_deleted' ));
2005-06-19 20:07:06 +02:00
break ;
2005-02-28 00:29:40 +01:00
case 'modify' :
2005-03-30 10:16:31 +02:00
return $this -> db -> from_timestamp ( $this -> db -> f ( 'sync_modified' ));
2005-06-19 20:07:06 +02:00
break ;
default :
return false ;
2005-02-28 00:29:40 +01:00
}
}
return false ;
}
/**
* update a timestamp for action
*
* @ param $_appName string the appname example : infolog_notes
* @ param $_id int the app internal content id
* @ param $_action string can be modify , add or delete
* @ param $_ts string timestamp where to start searching from
* @ return boolean returns allways true
*/
function updateTimeStamp ( $_appName , $_id , $_action , $_ts )
{
2005-03-30 10:16:31 +02:00
$_ts = $this -> db -> to_timestamp ( $_ts );
2005-02-28 00:29:40 +01:00
2005-03-30 10:16:31 +02:00
$newData = array (
'sync_appname' => $_appName ,
'sync_contentid' => $_id ,
'sync_added' => $_ts ,
2005-06-19 20:07:06 +02:00
'sync_guid' => $GLOBALS [ 'egw' ] -> common -> generate_uid ( $_appName , $_id ),
2005-03-30 10:16:31 +02:00
'sync_changedby' => $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ],
);
2006-04-07 10:22:46 +02:00
2005-02-28 00:29:40 +01:00
switch ( $_action )
{
case 'add' :
2005-03-30 10:16:31 +02:00
$this -> db -> insert ( $this -> table , $newData , array (), __LINE__ , __FILE__ );
2005-02-28 00:29:40 +01:00
break ;
2005-03-30 10:16:31 +02:00
case 'modify' :
2005-02-28 00:29:40 +01:00
case 'delete' :
2005-03-30 10:16:31 +02:00
// first check that this entry got ever added to database already
2005-02-28 00:29:40 +01:00
$where = array (
'sync_appname' => $_appName ,
'sync_contentid' => $_id ,
);
2006-03-19 23:13:57 +01:00
2005-03-30 10:16:31 +02:00
$this -> db -> select ( $this -> table , 'sync_contentid' , $where , __LINE__ , __FILE__ );
if ( ! $this -> db -> next_record ())
2005-02-28 00:29:40 +01:00
{
2005-03-30 10:16:31 +02:00
$this -> db -> insert ( $this -> table , $newData , array (), __LINE__ , __FILE__ );
2005-02-28 00:29:40 +01:00
}
2006-03-19 23:13:57 +01:00
$this -> db -> select ( $this -> table , 'sync_added' , $where , __LINE__ , __FILE__ );
$this -> db -> next_record ();
$syncAdded = $this -> db -> f ( 'sync_added' );
2005-02-28 00:29:40 +01:00
// now update the time stamp
$newData = array (
2005-03-30 10:16:31 +02:00
'sync_changedby' => $GLOBALS [ 'egw_info' ][ 'user' ][ 'account_id' ],
$_action == 'modify' ? 'sync_modified' : 'sync_deleted' => $_ts ,
2006-03-19 23:13:57 +01:00
'sync_added' => $syncAdded ,
2005-02-28 00:29:40 +01:00
);
2005-03-30 10:16:31 +02:00
$this -> db -> update ( $this -> table , $newData , $where , __LINE__ , __FILE__ );
2005-02-28 00:29:40 +01:00
break ;
}
return true ;
}
}
2005-06-19 20:07:06 +02:00
?>