/** * Return a list of files from the provided as the requested mimeType (default text/html unordered list, otherwise application/json structure). * * @SideEffects: * Writes content to output buffer. * * @param $path * @param array $mimeTypes * @return number of files listed */ public function execute($mimeTypes = array('text/html')) { $this->checkPerm(); $files = FileSystemTools::nodot_files($this->Path); if (in_array('application/json', $mimeTypes)) { $this->step("Sending results as json"); $body = ''; foreach ($files as $fullPath => $fileName) { $fileInfo = new ReplicantFileInfo($fullPath); $body .= "," . $fileInfo->to_json(); } $body = "[" . substr($body, 1) . "]"; } else { $this->step("Sending results as html"); $body = "<ul>"; foreach ($files as $this->Path => $fileName) { // strip extension, not needed $body .= '<li>' . $fileName . ' <a href="/replicant/files/' . $fileName . '">download</a> <a onclick="javascript: return confirm("Are you sure you want to restore ' . $fileName . ' to this server?);" href="/dev/tasks/ReplicantTask?action=restore&filename=' . $fileName . '">restore to this server</a> </li>'; } $body .= "</ul>"; } echo $body; $this->success("Output " . count($files) . " files"); return count($files); }
public function getCMSFields() { $fields = parent::getCMSFields(); $localFileNames = array_values(FileSystemTools::nodot_files(FileSystemTools::build_path(Director::baseFolder(), Replicant::config()->get('files_path')))); $fields->addFieldToTab('Root.Main', new DropdownField('FileName', 'Database dump to restore', array_combine($localFileNames, $localFileNames))); return $fields; }