‪TYPO3CMS  9.5
RecordHistoryStore.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
21 
28 {
29  public const ‪ACTION_ADD = 1;
30  public const ‪ACTION_MODIFY = 2;
31  public const ‪ACTION_MOVE = 3;
32  public const ‪ACTION_DELETE = 4;
33  public const ‪ACTION_UNDELETE = 5;
34 
35  public const ‪USER_BACKEND = 'BE';
36  public const ‪USER_FRONTEND = 'FE';
37  public const ‪USER_ANONYMOUS = '';
38 
42  protected ‪$userId;
43 
47  protected ‪$userType;
48 
52  protected ‪$originalUserId;
53 
57  protected ‪$tstamp;
58 
62  protected ‪$workspaceId;
63 
71  public function ‪__construct(string ‪$userType = self::USER_BACKEND, int ‪$userId = null, int ‪$originalUserId = null, int ‪$tstamp = null, int ‪$workspaceId = 0)
72  {
73  $this->userType = ‪$userType;
74  $this->userId = ‪$userId;
75  $this->originalUserId = ‪$originalUserId;
76  $this->tstamp = ‪$tstamp ?: ‪$GLOBALS['EXEC_TIME'];
77  $this->workspaceId = ‪$workspaceId;
78  }
79 
86  public function ‪addRecord(string $table, int $uid, array $payload): string
87  {
88  $data = [
89  'actiontype' => ‪self::ACTION_ADD,
90  'usertype' => ‪$this->userType,
91  'userid' => ‪$this->userId,
92  'originaluserid' => ‪$this->originalUserId,
93  'tablename' => $table,
94  'recuid' => $uid,
95  'tstamp' => ‪$this->tstamp,
96  'history_data' => json_encode($payload),
97  'workspace' => ‪$this->workspaceId,
98  ];
99  $this->‪getDatabaseConnection()->‪insert('sys_history', $data);
100  return $this->‪getDatabaseConnection()->‪lastInsertId('sys_history');
101  }
102 
109  public function ‪modifyRecord(string $table, int $uid, array $payload): string
110  {
111  $data = [
112  'actiontype' => ‪self::ACTION_MODIFY,
113  'usertype' => ‪$this->userType,
114  'userid' => ‪$this->userId,
115  'originaluserid' => ‪$this->originalUserId,
116  'tablename' => $table,
117  'recuid' => $uid,
118  'tstamp' => ‪$this->tstamp,
119  'history_data' => json_encode($payload),
120  'workspace' => ‪$this->workspaceId,
121  ];
122  $this->‪getDatabaseConnection()->‪insert('sys_history', $data);
123  return $this->‪getDatabaseConnection()->‪lastInsertId('sys_history');
124  }
125 
131  public function ‪deleteRecord(string $table, int $uid): string
132  {
133  $data = [
134  'actiontype' => ‪self::ACTION_DELETE,
135  'usertype' => ‪$this->userType,
136  'userid' => ‪$this->userId,
137  'originaluserid' => ‪$this->originalUserId,
138  'tablename' => $table,
139  'recuid' => $uid,
140  'tstamp' => ‪$this->tstamp,
141  'workspace' => ‪$this->workspaceId,
142  ];
143  $this->‪getDatabaseConnection()->‪insert('sys_history', $data);
144  return $this->‪getDatabaseConnection()->‪lastInsertId('sys_history');
145  }
146 
152  public function ‪undeleteRecord(string $table, int $uid): string
153  {
154  $data = [
155  'actiontype' => ‪self::ACTION_UNDELETE,
156  'usertype' => ‪$this->userType,
157  'userid' => ‪$this->userId,
158  'originaluserid' => ‪$this->originalUserId,
159  'tablename' => $table,
160  'recuid' => $uid,
161  'tstamp' => ‪$this->tstamp,
162  'workspace' => ‪$this->workspaceId,
163  ];
164  $this->‪getDatabaseConnection()->‪insert('sys_history', $data);
165  return $this->‪getDatabaseConnection()->‪lastInsertId('sys_history');
166  }
167 
174  public function ‪moveRecord(string $table, int $uid, array $payload): string
175  {
176  $data = [
177  'actiontype' => ‪self::ACTION_MOVE,
178  'usertype' => ‪$this->userType,
179  'userid' => ‪$this->userId,
180  'originaluserid' => ‪$this->originalUserId,
181  'tablename' => $table,
182  'recuid' => $uid,
183  'tstamp' => ‪$this->tstamp,
184  'history_data' => json_encode($payload),
185  'workspace' => ‪$this->workspaceId,
186  ];
187  $this->‪getDatabaseConnection()->‪insert('sys_history', $data);
188  return $this->‪getDatabaseConnection()->‪lastInsertId('sys_history');
189  }
190 
194  protected function ‪getDatabaseConnection(): ‪Connection
195  {
196  return GeneralUtility::makeInstance(ConnectionPool::class)
197  ->getConnectionForTable('sys_history');
198  }
199 }
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\$workspaceId
‪int $workspaceId
Definition: RecordHistoryStore.php:57
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\addRecord
‪string addRecord(string $table, int $uid, array $payload)
Definition: RecordHistoryStore.php:81
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\modifyRecord
‪string modifyRecord(string $table, int $uid, array $payload)
Definition: RecordHistoryStore.php:104
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\USER_BACKEND
‪const USER_BACKEND
Definition: RecordHistoryStore.php:35
‪TYPO3\CMS\Core\Database\Connection\lastInsertId
‪string lastInsertId($tableName=null, string $fieldName='uid')
Definition: Connection.php:439
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\$userId
‪int null $userId
Definition: RecordHistoryStore.php:41
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\moveRecord
‪string moveRecord(string $table, int $uid, array $payload)
Definition: RecordHistoryStore.php:169
‪TYPO3\CMS\Core\DataHandling\History
Definition: RecordHistoryStore.php:3
‪TYPO3\CMS\Core\Database\Connection\insert
‪int insert($tableName, array $data, array $types=[])
Definition: Connection.php:193
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\$userType
‪string $userType
Definition: RecordHistoryStore.php:45
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_MODIFY
‪const ACTION_MODIFY
Definition: RecordHistoryStore.php:30
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\getDatabaseConnection
‪Connection getDatabaseConnection()
Definition: RecordHistoryStore.php:189
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore
Definition: RecordHistoryStore.php:28
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\$originalUserId
‪int null $originalUserId
Definition: RecordHistoryStore.php:49
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:31
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\$tstamp
‪int null $tstamp
Definition: RecordHistoryStore.php:53
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\undeleteRecord
‪string undeleteRecord(string $table, int $uid)
Definition: RecordHistoryStore.php:147
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_DELETE
‪const ACTION_DELETE
Definition: RecordHistoryStore.php:32
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\deleteRecord
‪string deleteRecord(string $table, int $uid)
Definition: RecordHistoryStore.php:126
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\USER_FRONTEND
‪const USER_FRONTEND
Definition: RecordHistoryStore.php:36
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_ADD
‪const ACTION_ADD
Definition: RecordHistoryStore.php:29
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\__construct
‪__construct(string $userType=self::USER_BACKEND, int $userId=null, int $originalUserId=null, int $tstamp=null, int $workspaceId=0)
Definition: RecordHistoryStore.php:66
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_MOVE
‪const ACTION_MOVE
Definition: RecordHistoryStore.php:31
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\ACTION_UNDELETE
‪const ACTION_UNDELETE
Definition: RecordHistoryStore.php:33
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\DataHandling\History\RecordHistoryStore\USER_ANONYMOUS
‪const USER_ANONYMOUS
Definition: RecordHistoryStore.php:37