From beb829c315a4892dcf4bb8f86ae1cab7ccb86f78 Mon Sep 17 00:00:00 2001
From: Ralf Becker <ralfbecker@outdoor-training.de>
Date: Tue, 18 Aug 2015 11:45:59 +0000
Subject: [PATCH] drop contenthistroy class and table (egw_api_content_history)
 formerly used by SyncML

---
 addressbook/inc/class.addressbook_bo.inc.php |   6 +-
 calendar/inc/class.calendar_boupdate.inc.php |  10 -
 infolog/inc/class.infolog_bo.inc.php         |  21 +-
 infolog/inc/class.infolog_ical.inc.php       |   6 +-
 phpgwapi/inc/class.contenthistory.inc.php    | 235 -------------------
 phpgwapi/setup/setup.inc.php                 |   2 +-
 phpgwapi/setup/tables_current.inc.php        |  15 --
 phpgwapi/setup/tables_update.inc.php         |  16 ++
 8 files changed, 23 insertions(+), 288 deletions(-)
 delete mode 100644 phpgwapi/inc/class.contenthistory.inc.php

diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php
index 5fc7df43b1..b0d1e420a7 100755
--- a/addressbook/inc/class.addressbook_bo.inc.php
+++ b/addressbook/inc/class.addressbook_bo.inc.php
@@ -813,7 +813,6 @@ class addressbook_bo extends addressbook_so
 				// Don't notify of final purge
 				if ($ok && $old['tid'] != addressbook_so::DELETED_TYPE)
 				{
-					$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $id, 'delete', time());
 					if (!isset($this->tracking)) $this->tracking = new addressbook_tracking($this);
 					$this->tracking->track(array('id' => $id), array('id' => $id), null, true);
 				}
@@ -961,13 +960,12 @@ class addressbook_bo extends addressbook_so
 				unset($to_write['owner']);
 			}
 		}
-		// we dont update the content-history, if we run inside setup (admin-account-creation)
-		if(!($this->error = parent::save($to_write)) && is_object($GLOBALS['egw']->contenthistory))
+
+		if(!($this->error = parent::save($to_write)))
 		{
 			$contact['id'] = $to_write['id'];
 			$contact['uid'] = $to_write['uid'];
 			$contact['etag'] = $to_write['etag'];
-			$GLOBALS['egw']->contenthistory->updateTimeStamp('contacts', $contact['id'],$isUpdate ? 'modify' : 'add', time());
 
 			// if contact is an account and account-relevant data got updated, handle it like account got updated
 			if ($contact['account_id'] && $isUpdate &&
diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php
index a0868d77c3..d0d7d2b4ef 100644
--- a/calendar/inc/class.calendar_boupdate.inc.php
+++ b/calendar/inc/class.calendar_boupdate.inc.php
@@ -1219,7 +1219,6 @@ class calendar_boupdate extends calendar_bo
 			unset($save_event['participants']);
 			$this->set_recurrences($save_event, $set_recurrences_start);
 		}
-		if ($updateTS) $GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, $event['id'] ? 'modify' : 'add', $this->now);
 
 		// create links for new participants from addressbook, if configured
 		if ($cal_id && $GLOBALS['egw_info']['server']['link_contacts'])
@@ -1453,10 +1452,6 @@ class calendar_boupdate extends calendar_bo
 					}
 				}
 			}
-			if ($updateTS)
-			{
-				$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now);
-			}
 
 			static $status2msg = array(
 				'R' => MSG_REJECTED,
@@ -1565,7 +1560,6 @@ class calendar_boupdate extends calendar_bo
 					}
 				}
 			}
-			$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'delete', $this->now);
 
 			// delete or keep (with new uid) exceptions of a recurring event
 			if ($event['recur_type'] != MCAL_RECUR_NONE)
@@ -1828,8 +1822,6 @@ class calendar_boupdate extends calendar_bo
 		}
 		$alarm['time'] = $this->date2ts($alarm['time'],true);	// user to server-time
 
-		$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now);
-
 		return $this->so->save_alarm($cal_id, $alarm, $update_modified);
 	}
 
@@ -1848,8 +1840,6 @@ class calendar_boupdate extends calendar_bo
 			return false;	// no rights to delete the alarm
 		}
 
-		$GLOBALS['egw']->contenthistory->updateTimeStamp('calendar', $cal_id, 'modify', $this->now);
-
 		return $this->so->delete_alarm($id);
 	}
 
diff --git a/infolog/inc/class.infolog_bo.inc.php b/infolog/inc/class.infolog_bo.inc.php
index 2ff036fbe7..0bbec6c88d 100644
--- a/infolog/inc/class.infolog_bo.inc.php
+++ b/infolog/inc/class.infolog_bo.inc.php
@@ -684,8 +684,6 @@ class infolog_bo
 		}
 		if ($info['info_status'] != 'deleted')	// dont notify of final purge of already deleted items
 		{
-			$GLOBALS['egw']->contenthistory->updateTimeStamp('infolog_'.$info['info_type'], $info_id, 'delete', time());
-
 			// send email notifications and do the history logging
 			if(!$skip_notification)
 			{
@@ -914,22 +912,7 @@ class infolog_bo
 			{
 				$values = $this->read($info_id, true, 'server');
 			}
-			if ($values['info_id'] && $old['info_status'] != 'deleted')
-			{
-				// update
-				$GLOBALS['egw']->contenthistory->updateTimeStamp(
-					'infolog_'.$values['info_type'],
-					$info_id, 'modify', time()
-				);
-			}
-			else
-			{
-				// add
-				$GLOBALS['egw']->contenthistory->updateTimeStamp(
-					'infolog_'.$values['info_type'],
-					$info_id, 'add', time()
-				);
-			}
+
 			$values['info_id'] = $info_id;
 			$to_write['info_id'] = $info_id;
 
@@ -1147,7 +1130,7 @@ class infolog_bo
 			$names[] = $address['name'];
 			$emails[] =$address['email'];
 		}
-		
+
 		$type = isset($this->enums['type']['email']) ? 'email' : 'note';
 		$status = isset($this->status['defaults'][$type]) ? $this->status['defaults'][$type] : 'done';
 		$info = array(
diff --git a/infolog/inc/class.infolog_ical.inc.php b/infolog/inc/class.infolog_ical.inc.php
index 261c8d2934..c79c219a75 100644
--- a/infolog/inc/class.infolog_ical.inc.php
+++ b/infolog/inc/class.infolog_ical.inc.php
@@ -326,10 +326,8 @@ class infolog_ical extends infolog_bo
 		}
 
 		$vevent->setAttribute('DTSTAMP',time());
-		$vevent->setAttribute('CREATED', $taskData['info_created'] ? $taskData['info_created'] :
-			$GLOBALS['egw']->contenthistory->getTSforAction('infolog_task',$taskData['info_id'],'add'));
-		$vevent->setAttribute('LAST-MODIFIED', $taskData['info_datemodified'] ? $taskData['info_datemodified'] :
-			$GLOBALS['egw']->contenthistory->getTSforAction('infolog_task',$taskData['info_id'],'modify'));
+		$vevent->setAttribute('CREATED', $taskData['info_created']);
+		$vevent->setAttribute('LAST-MODIFIED', $taskData['info_datemodified']);
 		$vevent->setAttribute('CLASS',$taskData['info_access'] == 'public' ? 'PUBLIC' : 'PRIVATE');
 		$vevent->setAttribute('STATUS',$this->status2vtodo($taskData['info_status']));
 		// we try to preserv the original infolog status as X-INFOLOG-STATUS, so we can restore it, if the user does not modify STATUS
diff --git a/phpgwapi/inc/class.contenthistory.inc.php b/phpgwapi/inc/class.contenthistory.inc.php
deleted file mode 100644
index 97b2d98b0a..0000000000
--- a/phpgwapi/inc/class.contenthistory.inc.php
+++ /dev/null
@@ -1,235 +0,0 @@
-<?php
-/**
- * eGW API - content history class
- *
- * @link http://www.egroupware.org
- * @author Lars Kneschke [lkneschke@linux-at-work.de]
- * @copyright Lars Kneschke 2005
- * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
- * @package api
- * @version $Id$
- */
-
-/**
- * class to maintain history of content
- *
- * This class contains all logic of the egw content history.
- */
-class contenthistory
-{
-	/**
-	 * Name of the content-history table
-	 */
-	const TABLE = 'egw_api_content_history';
-	/**
-	 * @var egw_db
-	 */
-	private $db;
-
-	function __construct()
-	{
-		$this->db = $GLOBALS['egw']->db;
-	}
-
-	/**
-	 * mark mapping as expired
-	 *
-	 * mark a mapping from externel to internal id as expired, when
-	 * a egw entry gets deleted
-	 *
-	 * @param string $_appName the appname example: infolog_notes
-	 * @param int $_id the internal egwapp content id
-	 * @return boolean
-	 */
-	function expireMapping($_appName, $_id)
-	{
-		return !!$this->db->update('egw_contentmap',array (
-				'map_expired'		=> 1,
-			),array (
-				'map_guid'		=> $GLOBALS['egw']->common->generate_uid($_appName, $_id),
-			),__LINE__,__FILE__,'syncml');
-	}
-
-	/**
-	 * Encode app-name for egw_api_content_history.sync_appname only allowing ascii
-	 *
-	 * We encode all non-ascii as "?" for MySQL, as it happend during schema update and for inserts.
-	 *
-	 * @param string $_appname
-	 * @return string
-	 */
-	protected function encode_appname($_appname)
-	{
-		if ($this->db->Type == 'mysql')
-		{
-			$_appname = preg_replace('/[\x80-\xFF]/u', '?', $_appname);
-		}
-		return $_appname;
-	}
-
-	/**
-	 * get the timestamp for action
-	 *
-	 * find which content changed since $_ts for application $_appName
-	 *
-	 * @param string $_appName the appname example: infolog_notes
-	 * @param string $_action can be modify, add or delete
-	 * @param string $_ts timestamp where to start searching from
-	 * @param array $readableItems	(optional) readable items of current user
-	 * @return array containing contentIds with changes
-	 */
-	function getHistory($_appName, $_action, $_ts, $readableItems = false)
-	{
-		$where = array('sync_appname' => $this->encode_appname($_appName));
-		$ts = $this->db->to_timestamp($_ts);
-		$idList = array();
-
-		switch($_action)
-		{
-			case 'modify':
-				$where[] = "sync_modified > '".$ts."' AND sync_deleted IS NULL";
-				break;
-			case 'delete':
-				$where[] = "sync_deleted > '".$ts."'";
-				break;
-			case 'add':
-				$where[] = "sync_added > '".$ts."' AND sync_deleted IS NULL AND sync_modified IS NULL";
-				break;
-			default:
-				// no valid $_action set
-				return array();
-		}
-
-		if (is_array($readableItems))
-		{
-			foreach ($readableItems as $id)
-			{
-				$where['sync_contentid'] = $id;
-				if ($this->db->select(self::TABLE,'sync_contentid',$where,__LINE__,__FILE__)->fetchColumn())
-				{
-					$idList[] = $id;
-				}
-			}
-		}
-		else
-		{
-			foreach ($this->db->select(self::TABLE,'sync_contentid',$where,__LINE__,__FILE__) as $row)
-			{
-				$idList[] = $row['sync_contentid'];
-			}
-		}
-
-		return $idList;
-	}
-
-	/**
-	 * 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($_appName, $_id, $_action)
-	{
-		switch($_action)
-		{
-			case 'add':
-				$col = 'sync_added';
-				break;
-			case 'delete':
-				$col = 'sync_deleted';
-				break;
-			case 'modify':
-				$col = 'sync_modified';
-				break;
-			default:
-				return false;
-		}
-		$where = array (
-			'sync_appname' => $this->encode_appname($_appName),
-			'sync_contentid' => $_id,
-		);
-
-		if (($ts = $this->db->select(self::TABLE,$col,$where,__LINE__,__FILE__)->fetchColumn()))
-		{
-			$ts = $this->db->from_timestamp($ts);
-		}
-		return $ts;
-	}
-
-	/**
-	 * update a timestamp for action
-	 *
-	 * @param string $_appName the appname example: infolog_notes
-	 * @param int $_id the app internal content id
-	 * @param string $_action can be modify, add or delete
-	 * @param string $_ts timestamp where to start searching from
-	 * @return boolean returns allways true
-	 */
-	function updateTimeStamp($_appName, $_id, $_action, $_ts)
-	{
-		$newData = array (
-			'sync_appname'		=> $this->encode_appname($_appName),
-			'sync_contentid'	=> $_id,
-			'sync_added'		=> $this->db->to_timestamp($_ts),
-			'sync_changedby'	=> $GLOBALS['egw_info']['user']['account_id'],
-		);
-
-		switch($_action)
-		{
-			case 'add':
-				$this->db->insert(self::TABLE,$newData,array(),__LINE__,__FILE__);
-				break;
-
-			case 'modify':
-			case 'delete':
-				// first check that this entry got ever added to database already
-				$where = array (
-					'sync_appname'		=> $this->encode_appname($_appName),
-					'sync_contentid'	=> $_id,
-				);
-
-				if (!$this->db->select(self::TABLE,'sync_contentid',$where,__LINE__,__FILE__)->fetchColumn())
-				{
-					$this->db->insert(self::TABLE,$newData,array(),__LINE__,__FILE__);
-				}
-
-				// now update the time stamp
-				$newData = array (
-					'sync_changedby'	=> $GLOBALS['egw_info']['user']['account_id'],
-					$_action == 'delete' ? 'sync_deleted' : 'sync_modified' => $this->db->to_timestamp($_ts),
-				);
-				$this->db->update(self::TABLE, $newData, $where,__LINE__,__FILE__);
-				break;
-		}
-		return true;
-	}
-
-	/**
-	 * get the timestamp of last change for appname
-	 *
-	 * find which content changed since $_ts for application $_appName
-	 *
-	 * @param string$_appName the appname example: infolog_notes
-	 *
-	 * @return timestamp of last change for this application
-	 */
-	function getLastChange($_appName)
-	{
-		$max = 0;
-
-		$where = array('sync_appname' => $this->encode_appname($_appName));
-
-		foreach (array('modified','deleted','added') as $action)
-		{
-			if (($ts = $this->db->select(self::TABLE,'MAX(sync_'.$action.')',$where,__LINE__,__FILE__)->fetchColumn()))
-			{
-				$ts = $this->db->from_timestamp($ts);
-				if ($ts > $max) $max = $ts;
-			}
-		}
-
-		return $max;
-	}
-
-}
diff --git a/phpgwapi/setup/setup.inc.php b/phpgwapi/setup/setup.inc.php
index 1c697d5332..d4c8aa86cc 100755
--- a/phpgwapi/setup/setup.inc.php
+++ b/phpgwapi/setup/setup.inc.php
@@ -12,7 +12,7 @@
 /* Basic information about this app */
 $setup_info['phpgwapi']['name']      = 'phpgwapi';
 $setup_info['phpgwapi']['title']     = 'EGroupware API';
-$setup_info['phpgwapi']['version']   = '14.3.002';
+$setup_info['phpgwapi']['version']   = '14.3.900';
 $setup_info['phpgwapi']['versions']['current_header'] = '1.29';
 $setup_info['phpgwapi']['enable']    = 3;
 $setup_info['phpgwapi']['app_order'] = 1;
diff --git a/phpgwapi/setup/tables_current.inc.php b/phpgwapi/setup/tables_current.inc.php
index 51aefca55d..a7bf2b9c9d 100644
--- a/phpgwapi/setup/tables_current.inc.php
+++ b/phpgwapi/setup/tables_current.inc.php
@@ -199,21 +199,6 @@ $phpgw_baseline = array(
 		'ix' => array(),
 		'uc' => array('async_id')
 	),
-	'egw_api_content_history' => array(
-		'fd' => array(
-			'sync_appname' => array('type' => 'ascii','precision' => '32','nullable' => False,'comment' => 'not just app-names!'),
-			'sync_contentid' => array('type' => 'ascii','precision' => '48','nullable' => False,'comment' => 'eworkflow uses 36-char uuids'),
-			'sync_added' => array('type' => 'timestamp'),
-			'sync_modified' => array('type' => 'timestamp'),
-			'sync_deleted' => array('type' => 'timestamp'),
-			'sync_id' => array('type' => 'auto','nullable' => False),
-			'sync_changedby' => array('type' => 'int','meta' => 'user','precision' => '4','nullable' => False)
-		),
-		'pk' => array('sync_id'),
-		'fk' => array(),
-		'ix' => array('sync_added','sync_modified','sync_deleted','sync_changedby',array('sync_appname','sync_contentid')),
-		'uc' => array()
-	),
 	'egw_links' => array(
 		'fd' => array(
 			'link_id' => array('type' => 'auto','nullable' => False),
diff --git a/phpgwapi/setup/tables_update.inc.php b/phpgwapi/setup/tables_update.inc.php
index b05abb9583..81111980c6 100644
--- a/phpgwapi/setup/tables_update.inc.php
+++ b/phpgwapi/setup/tables_update.inc.php
@@ -813,3 +813,19 @@ function phpgwapi_upgrade14_3_001()
 
 	return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.002';
 }
+
+/**
+ * Updates on the way to 15.1
+ */
+
+/**
+ * Drop egw_api_content_history table used by no longer supported SyncML
+ *
+ * @return string
+ */
+function phpgwapi_upgrade14_3_002()
+{
+	$GLOBALS['egw_setup']->oProc->DropTable('egw_api_content_history');
+
+	return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.900';
+}