XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
trash.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
12 {
18  function insertTrash($obj)
19  {
20  if(!Context::get('is_logged'))
21  {
22  return new BaseObject(-1, 'msg_not_permitted');
23  }
24 
25  $logged_info = Context::get('logged_info');
26 
27  $oTrashVO = new TrashVO();
28  $oTrashVO = &$obj;
29 
30  if(!$oTrashVO->getTrashSrl()) $oTrashVO->setTrashSrl(getNextSequence());
31  if(!is_string($oTrashVO->getSerializedObject())) $oTrashVO->setSerializedObject(serialize($oTrashVO->getSerializedObject()));
32  $oTrashVO->setIpaddress($_SERVER['REMOTE_ADDR']);
33  $oTrashVO->setRemoverSrl($logged_info->member_srl);
34  $oTrashVO->setRegdate(date('YmdHis'));
35 
36  return executeQuery('trash.insertTrash', $oTrashVO);
37  }
38 
45  {
46  global $lang;
47  $isAll = Context::get('is_all');
48  $originModule = Context::get('origin_module');
49  $tmpTrashSrls = Context::get('cart');
50 
51  $trashSrls = array();
52  if($isAll != 'true')
53  {
54  if(is_array($tmpTrashSrls)) $trashSrls = $tmpTrashSrls;
55  else $trashSrls = explode('|@|', $tmpTrashSrls);
56  }
57 
58  //module relation data delete...
59  $output = $this->_relationDataDelete($isAll, $trashSrls);
60  if(!$output->toBool()) return new BaseObject(-1, $output->message);
61 
62  if(!$this->_emptyTrash($trashSrls)) return new BaseObject(-1, $lang->fail_empty);
63 
64  $this->setMessage('success_deleted', 'info');
65 
66  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList', 'origin_module', $originModule);
67  $this->setRedirectUrl($returnUrl, $output);
68  }
69 
76  function _relationDataDelete($isAll, &$trashSrls)
77  {
78  $oTrashModel = getModel('trash');
79  if($isAll == 'true')
80  {
81  $output = $oTrashModel->getTrashAllList(array());
82  if(!$output->toBool())
83  {
84  return new BaseObject(-1, $output->message);
85  }
86 
87  if(is_array($output->data))
88  {
89  foreach($output->data as $value)
90  {
91  $trashSrls[] = $value->getTrashSrl();
92  }
93  }
94  }
95  else
96  {
97  $args = new stdClass();
98  $args->trashSrl = $trashSrls;
99  $output = $oTrashModel->getTrashList($args);
100  if(!$output->toBool())
101  {
102  return new BaseObject(-1, $output->message);
103  }
104  }
105 
106  if(is_array($output->data))
107  {
108  foreach($output->data as $oTrashVO)
109  {
110  //class file check
111  $classPath = ModuleHandler::getModulePath($oTrashVO->getOriginModule());
112  if(!is_dir(FileHandler::getRealPath($classPath))) return new BaseObject(-1, 'not exist restore module directory');
113 
114  $classFile = sprintf('%s%s.admin.controller.php', $classPath, $oTrashVO->getOriginModule());
115  $classFile = FileHandler::getRealPath($classFile);
116  if(!file_exists($classFile)) return new BaseObject(-1, 'not exist restore module class file');
117 
118  $oAdminController = getAdminController($oTrashVO->getOriginModule());
119  if(!method_exists($oAdminController, 'emptyTrash')) return new BaseObject(-1, 'not exist restore method in module class file');
120 
121  $output2 = $oAdminController->emptyTrash($oTrashVO->getSerializedObject());
122  if(!$output2->toBool()) return new BaseObject(-1, $output2->message);
123  }
124  }
125  return new BaseObject(0, $lang->success_deleted);
126  }
127 
133  {
134  global $lang;
135  $trashSrlList = Context::get('cart');
136 
137  if(is_array($trashSrlList))
138  {
139  // begin transaction
140  $oDB = &DB::getInstance();
141  $oDB->begin();
142  // eache restore method call in each classfile
143  foreach($trashSrlList as $value)
144  {
145  $oTrashModel = getModel('trash');
146  $output = $oTrashModel->getTrash($value);
147  if(!$output->toBool()) return new BaseObject(-1, $output->message);
148 
149  //class file check
150  $classPath = ModuleHandler::getModulePath($output->data->getOriginModule());
151  if(!is_dir(FileHandler::getRealPath($classPath))) return new BaseObject(-1, 'not exist restore module directory');
152 
153  $classFile = sprintf('%s%s.admin.controller.php', $classPath, $output->data->getOriginModule());
154  $classFile = FileHandler::getRealPath($classFile);
155  if(!file_exists($classFile)) return new BaseObject(-1, 'not exist restore module class file');
156 
157  $oAdminController = getAdminController($output->data->getOriginModule());
158  if(!method_exists($oAdminController, 'restoreTrash')) return new BaseObject(-1, 'not exist restore method in module class file');
159 
160  $originObject = unserialize($output->data->getSerializedObject());
161  $output = $oAdminController->restoreTrash($originObject);
162 
163  if(!$output->toBool())
164  {
165  $oDB->rollback();
166  return new BaseObject(-1, $output->message);
167  }
168  }
169 
170  // restore object delete in trash box
171  if(!$this->_emptyTrash($trashSrlList)) {
172  $oDB->rollback();
173  return new BaseObject(-1, $lang->fail_empty);
174  }
175  $oDB->commit();
176  }
177 
178  $this->setMessage('success_restore', 'info');
179 
180  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList');
181  $this->setRedirectUrl($returnUrl);
182  }
183 
189  {
190  if(!Context::get('is_logged')) return new BaseObject(-1,'msg_not_permitted');
191  $trashSrls = Context::get('trash_srls');
192  if($trashSrls) $trashSrlList = explode(',', $trashSrls);
193 
194  if(count($trashSrlList) > 0)
195  {
196  $oTrashModel = getModel('trash');
197  $args = new stdClass();
198  $args->trashSrl = $trashSrlList;
199  $output = $oTrashModel->getTrashList($args);
200  $trashList = $output->data;
201  }
202  else
203  {
204  global $lang;
205  $trashList = array();
206  $this->setMessage($lang->no_documents);
207  }
208 
209  $oSecurity = new Security($trashList);
210  $oSecurity->encodeHTML('..');
211  $this->add('trash_list', $trashList);
212  }
213 
219  function _emptyTrash($trashSrls)
220  {
221  if(!is_array($trashSrls)) return false;
222  $args = new stdClass();
223  $args->trashSrls = $trashSrls;
224  $output = executeQuery('trash.deleteTrash', $args);
225  if(!$output->toBool()) return false;
226 
227  return true;
228  }
229 }
230 /* End of file trash.admin.controller.php */
231 /* Location: ./modules/trash/trash.admin.controller.php */
setMessage($message= 'success', $type=NULL)
$obj
Definition: ko.install.php:262
$output
Definition: ko.install.php:193
add($key, $val)
getNotEncodedUrl()
Definition: func.inc.php:316
$args
Definition: ko.install.php:185
setRedirectUrl($url= './', $output=NULL)
getInstance($db_type=NULL)
Definition: DB.class.php:142
getRealPath($source)
getNextSequence()
Definition: func.inc.php:236
getModel($module_name)
Definition: func.inc.php:145
_relationDataDelete($isAll, &$trashSrls)
$oAdminController
Definition: ko.install.php:249
getAdminController($module_name)
Definition: func.inc.php:101
executeQuery($query_id, $args=NULL, $arg_columns=NULL)
Definition: func.inc.php:203
if(isset($_REQUEST['encode'])) if(isset($_REQUEST['decode'])) $lang
Definition: example.php:23