__('Page Trash', __FILE__), // getModuleInfo title 'summary' => __('Handles emptying of Page trash', __FILE__), // getModuleInfo summary 'version' => 103, 'permanent' => true, ); } /** * Check if an empty request has been received and delete if so, otherwise render a confirmation form * */ public function ___execute() { if(!$this->wire()->user->isSuperuser()) throw new WirePermissionException(); $input = $this->wire()->input; $timeLimit = abs((int) $input->post('time_limit')); if($timeLimit > 0) $this->session->setFor($this, 'timeLimit', $timeLimit); if(!$input->post('submit_empty') || !$input->post('confirm_empty')) { // render a form showing what pages are in the trash and confirming they want to empty it if($input->post('submit_empty')) $this->warning($this->_('You must check the box to confirm')); return $this->render(); } $this->session->CSRF->validate(); $options = array( 'verbose' => true, 'timeLimit' => $timeLimit > 0 ? $timeLimit : self::defaultTimeLimit, ); $result = $this->wire()->pages->emptyTrash($options); if(self::debug) $this->warning($result); $error = false; $message = sprintf($this->_n('Deleted %d page', 'Deleted %d pages', $result['numDeleted']), $result['numDeleted']); if($result['numDeleted'] && $result['pagesPerSecond'] && $result['numDeleted'] > $result['pagesPerSecond']) { $message .= ' ' . sprintf($this->_('(%d pages per second)'), $result['pagesPerSecond']); } if($result['numRemain'] > 0) { $message .= ' - ' . sprintf($this->_('Not all pages could be deleted (%d remain)'), $result['numRemain']); $error = true; } if($result['timeExpired']) { $message .= ' - ' . sprintf($this->_('Time limit reached (%d seconds)'), "$options[timeLimit]"); $error = true; } $session = $this->wire()->session; if($error) { $session->warning($message); $session->redirect('./'); } else { // redirect to admin root after emptying trash $session->message($message); $session->redirect($this->wire()->config->urls('admin')); } return ''; // unreachable due to redirects above } /** * Render a form showing what pages are in the trash and confirming they want to empty it * */ protected function render() { $modules = $this->wire()->modules; $trashTotal = $this->pages->trasher()->getTrashTotal(); /** @var InputfieldForm $form */ $form = $modules->get("InputfieldForm"); $form->attr('action', './'); $form->attr('method', 'post'); if(!$trashTotal) return "