| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /***************************************************************************\ 3 * eGroupWare - content history class * 4 * http://www.egroupware.org * 5 * Written by : Lars Kneschke [lkneschke@linux-at-work.de] * 6 * ------------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License. * 10 \***************************************************************************/ 11 /* $Id: class.contenthistory.inc.php 21560 2006-05-16 17:15:08Z lkneschke $ */ 12 13 /** 14 * class to maintain history of content 15 * 16 * This class contains all logic of the egw content history. 17 * @package phpgwapi 18 * @author Lars Kneschke 19 * @version 1.35 20 * @copyright Lars Kneschke 2005 21 * @license http://opensource.org/licenses/gpl-license.php GPL 22 */ 23 class contenthistory 24 { 25 /** 26 * @var db-object $this->db 27 */ 28 var $db; 29 30 function contenthistory() 31 { 32 $this->db = clone($GLOBALS['egw']->db); 33 $this->db->set_app('phpgwapi'); 34 $this->table = 'egw_api_content_history'; 35 } 36 37 /** 38 * mark mapping as expired 39 * 40 * mark a mapping from externel to internal id as expired, when 41 * a egw entry gets deleted 42 * 43 * @param $_appName string the appname example: infolog_notes 44 * @param $_id int the internal egwapp content id 45 * @return bool 46 */ 47 function expireMapping($_appName, $_id) 48 { 49 $where = array ( 50 'map_guid' => $GLOBALS['egw']->common->generate_uid($_appName, $_id), 51 ); 52 53 $newData = array ( 54 'map_expired' => 1, 55 ); 56 57 if(!$this->db->update('egw_contentmap',$newData,$where,__LINE__,__FILE__)) 58 return FALSE; 59 else 60 return TRUE; 61 } 62 63 /** 64 * get the timestamp for action 65 * 66 * find which content changed since $_ts for application $_appName 67 * 68 * @param $_appName string the appname example: infolog_notes 69 * @param $_action string can be modify, add or delete 70 * @param $_ts string timestamp where to start searching from 71 * @return array containing the global UID's 72 */ 73 function getHistory($_appName, $_action, $_ts) 74 { 75 $query = "select sync_guid from egw_api_content_history where sync_appname = '".$this->db->db_addslashes($_appName)."' and "; 76 77 switch($_action) 78 { 79 case 'modify': 80 $query .= "sync_modified > '".$this->db->to_timestamp($_ts)."' and sync_deleted is null"; 81 break; 82 case 'delete': 83 $query .= "sync_deleted > '".$this->db->to_timestamp($_ts)."'"; 84 break; 85 case 'add': 86 $query .= "sync_added > '".$this->db->to_timestamp($_ts)."' and sync_deleted is null and sync_modified is null"; 87 break; 88 default: 89 // no valid $_action set 90 return array(); 91 break; 92 } 93 #Horde::logMessage("SymcML: egwcontactssync $query", __FILE__, __LINE__, PEAR_LOG_DEBUG); 94 $this->db->query($query, __LINE__, __FILE__); 95 96 $guidList = array(); 97 98 while($this->db->next_record()) 99 { 100 $guidList[] = $this->db->f('sync_guid'); 101 } 102 103 return $guidList; 104 } 105 106 /** 107 * when got a entry last added/modified/deleted 108 * 109 * @param $_guid string the global uid of the entry 110 * @param $_action string can be add, delete or modify 111 * @return string the last timestamp 112 */ 113 function getTSforAction($_guid, $_action) 114 { 115 $where = array ( 116 'sync_guid' => $_guid, 117 ); 118 119 $this->db->select($this->table,array('sync_added','sync_modified','sync_deleted'),$where,__LINE__,__FILE__); 120 if($this->db->next_record()) 121 { 122 switch($_action) 123 { 124 case 'add': 125 return $this->db->from_timestamp($this->db->f('sync_added')); 126 break; 127 case 'delete': 128 return $this->db->from_timestamp($this->db->f('sync_deleted')); 129 break; 130 case 'modify': 131 return $this->db->from_timestamp($this->db->f('sync_modified')); 132 break; 133 default: 134 return false; 135 } 136 } 137 138 return false; 139 } 140 141 /** 142 * update a timestamp for action 143 * 144 * @param $_appName string the appname example: infolog_notes 145 * @param $_id int the app internal content id 146 * @param $_action string can be modify, add or delete 147 * @param $_ts string timestamp where to start searching from 148 * @return boolean returns allways true 149 */ 150 function updateTimeStamp($_appName, $_id, $_action, $_ts) 151 { 152 $_ts = $this->db->to_timestamp($_ts); 153 154 $newData = array ( 155 'sync_appname' => $_appName, 156 'sync_contentid' => $_id, 157 'sync_added' => $_ts, 158 'sync_guid' => $GLOBALS['egw']->common->generate_uid($_appName, $_id), 159 'sync_changedby' => $GLOBALS['egw_info']['user']['account_id'], 160 ); 161 162 switch($_action) 163 { 164 case 'add': 165 $this->db->insert($this->table,$newData,array(),__LINE__,__FILE__); 166 break; 167 168 case 'modify': 169 case 'delete': 170 // first check that this entry got ever added to database already 171 $where = array ( 172 'sync_appname' => $_appName, 173 'sync_contentid' => $_id, 174 ); 175 176 $this->db->select($this->table,'sync_contentid',$where,__LINE__,__FILE__); 177 if(!$this->db->next_record()) 178 { 179 $this->db->insert($this->table,$newData,array(),__LINE__,__FILE__); 180 } 181 182 #$this->db->select($this->table,'sync_added',$where,__LINE__,__FILE__); 183 #$this->db->next_record(); 184 #$syncAdded = $this->db->f('sync_added'); 185 186 // now update the time stamp 187 $newData = array ( 188 'sync_changedby' => $GLOBALS['egw_info']['user']['account_id'], 189 $_action == 'modify' ? 'sync_modified' : 'sync_deleted' => $_ts , 190 # 'sync_added' => $syncAdded, 191 ); 192 $this->db->update($this->table, $newData, $where,__LINE__,__FILE__); 193 break; 194 } 195 196 return true; 197 } 198 } 199 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |