/
tl_undo.php
166 lines (154 loc) · 3.96 KB
/
tl_undo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/*
* This file is part of Contao.
*
* (c) Leo Feyer
*
* @license LGPL-3.0-or-later
*/
$GLOBALS['TL_DCA']['tl_undo'] = array
(
// Config
'config' => array
(
'dataContainer' => 'Table',
'closed' => true,
'notEditable' => true,
'sql' => array
(
'keys' => array
(
'id' => 'primary'
)
),
'onload_callback' => array
(
array('tl_undo', 'checkPermission')
)
),
// List
'list' => array
(
'sorting' => array
(
'mode' => 2,
'fields' => array('tstamp'),
'panelLayout' => 'sort,search,limit'
),
'label' => array
(
'fields' => array('tstamp', 'query'),
'format' => '<span style="color:#999;padding-right:3px">[%s]</span>%s',
'label_callback' => array('tl_undo', 'ellipsis')
),
'operations' => array
(
'undo' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['undo'],
'href' => '&act=undo',
'icon' => 'undo.svg'
),
'show' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['show'],
'href' => '&act=show',
'icon' => 'show.svg'
)
)
),
// Fields
'fields' => array
(
'id' => array
(
'sql' => "int(10) unsigned NOT NULL auto_increment"
),
'pid' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['pid'],
'sorting' => true,
'foreignKey' => 'tl_user.name',
'sql' => "int(10) unsigned NOT NULL default '0'",
'relation' => array('type'=>'belongsTo', 'load'=>'lazy')
),
'tstamp' => array
(
'sorting' => true,
'flag' => 6,
'sql' => "int(10) unsigned NOT NULL default '0'"
),
'fromTable' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['fromTable'],
'sorting' => true,
'sql' => "varchar(255) NOT NULL default ''"
),
'query' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['query'],
'sql' => "text NULL"
),
'affectedRows' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['affectedRows'],
'sql' => "smallint(5) unsigned NOT NULL default '0'"
),
'data' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_undo']['data'],
'search' => true,
'sql' => "mediumblob NULL"
)
)
);
/**
* Provide miscellaneous methods that are used by the data configuration array.
*
* @author Leo Feyer <https://github.com/leofeyer>
*/
class tl_undo extends Backend
{
/**
* Import the back end user object
*/
public function __construct()
{
parent::__construct();
$this->import('BackendUser', 'User');
}
/**
* Check permissions to use table tl_undo
*
* @throws Contao\CoreBundle\Exception\AccessDeniedException
*/
public function checkPermission()
{
if ($this->User->isAdmin)
{
return;
}
// Show only own undo steps
$objSteps = $this->Database->prepare("SELECT id FROM tl_undo WHERE pid=?")
->execute($this->User->id);
// Restrict the list
$GLOBALS['TL_DCA']['tl_undo']['list']['sorting']['root'] = $objSteps->numRows ? $objSteps->fetchEach('id') : array(0);
// Redirect if there is an error
if (Input::get('act') && !\in_array(Input::get('id'), $GLOBALS['TL_DCA']['tl_undo']['list']['sorting']['root']))
{
throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to ' . Input::get('act') . ' undo step ID ' . Input::get('id') . '.');
}
}
/**
* Add the surrounding ellipsis layer
*
* @param array $row
* @param string $label
*
* @return string
*/
public function ellipsis($row, $label)
{
return '<div class="ellipsis">' . $label . '</div>';
}
}