|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package midgard.admin.asgard |
|
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
|
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Undelete/purge interface |
|
13
|
|
|
* |
|
14
|
|
|
* @package midgard.admin.asgard |
|
15
|
|
|
*/ |
|
16
|
|
|
class midgard_admin_asgard_handler_undelete extends midcom_baseclasses_components_handler |
|
17
|
|
|
{ |
|
18
|
|
|
use midgard_admin_asgard_handler; |
|
19
|
|
|
|
|
20
|
|
|
private $type = ''; |
|
21
|
|
|
|
|
22
|
3 |
|
public function _on_initialize() |
|
23
|
|
|
{ |
|
24
|
3 |
|
midcom::get()->head->add_jsfile(MIDCOM_STATIC_URL . '/jQuery/jquery.tablesorter.pack.js'); |
|
25
|
3 |
|
midcom::get()->head->add_jsfile(MIDCOM_STATIC_URL . '/midgard.admin.asgard/jquery.batch_process.js'); |
|
26
|
3 |
|
$this->add_stylesheet(MIDCOM_STATIC_URL . '/midgard.admin.asgard/tablewidget.css'); |
|
27
|
3 |
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Trash view |
|
31
|
|
|
* |
|
32
|
|
|
* @param array $data The local request data. |
|
33
|
|
|
*/ |
|
34
|
1 |
|
public function _handler_trash(array &$data) |
|
35
|
|
|
{ |
|
36
|
1 |
|
midcom::get()->auth->require_admin_user(); |
|
37
|
|
|
|
|
38
|
1 |
|
$data['view_title'] = $this->_l10n->get('trash'); |
|
39
|
|
|
|
|
40
|
1 |
|
$data['types'] = []; |
|
41
|
1 |
|
foreach (midcom_connection::get_schema_types() as $type) { |
|
42
|
|
|
// Objects that don't have metadata should not be shown in trash. |
|
43
|
1 |
|
if (!midgard_reflector_object::has_metadata_class($type)) { |
|
44
|
1 |
|
debug_add("{$type} has no metadata, skipping"); |
|
45
|
1 |
|
continue; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$qb = new midgard_query_builder($type); |
|
49
|
1 |
|
$qb->include_deleted(); |
|
50
|
1 |
|
$qb->add_constraint('metadata.deleted', '=', true); |
|
51
|
1 |
|
$data['types'][$type] = $qb->count(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// Set the breadcrumb data |
|
55
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get('midgard.admin.asgard')); |
|
56
|
1 |
|
$this->add_breadcrumb($this->router->generate('trash'), $this->_l10n->get('trash')); |
|
57
|
1 |
|
return $this->get_response(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Shows the loaded object in editor. |
|
62
|
|
|
* |
|
63
|
|
|
* @param mixed $handler_id The ID of the handler. |
|
64
|
|
|
* @param array $data The local request data. |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function _show_trash($handler_id, array &$data) |
|
67
|
|
|
{ |
|
68
|
1 |
|
midcom_show_style('midgard_admin_asgard_trash'); |
|
69
|
1 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Trash view |
|
73
|
|
|
* |
|
74
|
|
|
* @param Request $request The request object |
|
75
|
|
|
* @param string $type The MgdSchema type |
|
76
|
|
|
* @param array $data The local request data. |
|
77
|
|
|
*/ |
|
78
|
2 |
|
public function _handler_trash_type(Request $request, $type, array &$data) |
|
79
|
|
|
{ |
|
80
|
2 |
|
midcom::get()->auth->require_admin_user(); |
|
81
|
|
|
|
|
82
|
2 |
|
$this->type = $type; |
|
83
|
|
|
|
|
84
|
2 |
|
$data['view_title'] = sprintf($this->_l10n->get('%s trash'), midgard_admin_asgard_plugin::get_type_label($type)); |
|
85
|
|
|
|
|
86
|
2 |
|
$dummy = new $type; |
|
87
|
2 |
|
$data['midcom_dba_classname'] = midcom::get()->dbclassloader->get_midcom_class_name_for_mgdschema_object($dummy); |
|
88
|
2 |
|
$data['type'] = $type; |
|
89
|
2 |
|
$data['reflector'] = midcom_helper_reflector::get($data['type']); |
|
90
|
2 |
|
$data['label_property'] = $data['reflector']->get_label_property(); |
|
91
|
|
|
|
|
92
|
2 |
|
if ($request->request->has('undelete')) { |
|
93
|
1 |
|
$guids = $request->request->get('undelete'); |
|
94
|
1 |
|
if ($request->request->has('purge')) { |
|
95
|
1 |
|
$this->_purge($guids); |
|
96
|
|
|
} else { |
|
97
|
|
|
$this->_undelete($guids); |
|
98
|
|
|
} |
|
99
|
1 |
|
return new midcom_response_relocate($this->router->generate('trash_type', ['type' => $type])); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
$qb = new org_openpsa_qbpager_direct($data['type'], "{$data['type']}_trash"); |
|
103
|
1 |
|
$qb->include_deleted(); |
|
104
|
1 |
|
$qb->add_constraint('metadata.deleted', '=', true); |
|
105
|
1 |
|
$qb->add_order('metadata.revised', 'DESC'); |
|
106
|
1 |
|
$data['qb'] = $qb; |
|
107
|
1 |
|
$data['trash'] = $qb->execute_unchecked(); |
|
108
|
|
|
|
|
109
|
|
|
// Set the breadcrumb data |
|
110
|
1 |
|
$this->add_breadcrumb($this->router->generate('welcome'), $this->_l10n->get($this->_component)); |
|
111
|
1 |
|
$this->add_breadcrumb($this->router->generate('trash'), $this->_l10n->get('trash')); |
|
112
|
1 |
|
$this->add_breadcrumb($this->router->generate('trash_type', ['type' => $type]), midgard_admin_asgard_plugin::get_type_label($type)); |
|
113
|
1 |
|
return $this->get_response(); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
1 |
|
private function _purge(array $guids) |
|
117
|
|
|
{ |
|
118
|
1 |
|
$purged_size = 0; |
|
119
|
|
|
|
|
120
|
1 |
|
if (!$this->_request_data['midcom_dba_classname']) { |
|
121
|
|
|
// No DBA class for the type, use plain Midgard undelete API |
|
122
|
|
|
foreach ($guids as $guid) { |
|
123
|
|
|
$qb = new midgard_query_builder($this->type); |
|
124
|
|
|
$qb->add_constraint('guid', '=', $guid); |
|
125
|
|
|
$qb->include_deleted(); |
|
126
|
|
|
foreach ($qb->execute() as $object) { |
|
127
|
|
|
if ($object->purge()) { |
|
128
|
|
|
$purged_size += $object->metadata->size; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
} else { |
|
133
|
|
|
// Delegate purging to DBA |
|
134
|
1 |
|
$purged_size = midcom_baseclasses_core_dbobject::purge($guids, $this->type); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
1 |
|
if ($purged_size) { |
|
138
|
|
|
midcom::get()->uimessages->add($this->_l10n->get('midgard.admin.asgard'), sprintf($this->_l10n->get('in total %s purged'), midcom_helper_misc::filesize_to_string($purged_size)), 'info'); |
|
139
|
|
|
} |
|
140
|
1 |
|
} |
|
141
|
|
|
|
|
142
|
|
|
private function _undelete(array $guids) |
|
143
|
|
|
{ |
|
144
|
|
|
// Delegate undeletion to DBA |
|
145
|
|
|
$undeleted_size = midcom_baseclasses_core_dbobject::undelete($guids); |
|
146
|
|
|
if ($undeleted_size > 0) { |
|
147
|
|
|
midcom::get()->uimessages->add($this->_l10n->get('midgard.admin.asgard'), sprintf($this->_l10n->get('in total %s undeleted'), midcom_helper_misc::filesize_to_string($undeleted_size)), 'info'); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Shows the loaded object in editor. |
|
153
|
|
|
* |
|
154
|
|
|
* @param mixed $handler_id The ID of the handler. |
|
155
|
|
|
* @param array $data The local request data. |
|
156
|
|
|
*/ |
|
157
|
1 |
|
public function _show_trash_type($handler_id, array &$data) |
|
158
|
|
|
{ |
|
159
|
1 |
|
$data['current_type'] = $this->type; |
|
160
|
|
|
|
|
161
|
1 |
|
midcom_show_style('midgard_admin_asgard_trash_type'); |
|
162
|
1 |
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|