Skip to content

Commit

Permalink
#2 Add basic reporting on file status
Browse files Browse the repository at this point in the history
  • Loading branch information
kenneth-hendricks committed Dec 8, 2016
1 parent 2779c85 commit 99df3e1
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 1 deletion.
64 changes: 64 additions & 0 deletions classes/sss_file_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* File status renderable object.
*
* @package tool_sssfs
* @author Kenneth Hendricks <kennethhendricks@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_sssfs;

class sss_file_status implements \renderable {

public $statusdata;

public function __construct () {
$this->get_file_status();
}

public function get_file_status() {
global $DB;

$statusdata = array();

// TODO: refactor constants so i dont have to do this.
$filesystem = \tool_sssfs\sss_file_system::instance();

$sql = 'SELECT count(*) as filecount, COALESCE(SUM(F.filesize),0) as filesum
FROM {tool_sssfs_filestate} SFS
JOIN {files} F ON F.contenthash=sfs.contenthash
WHERE SFS.state = ?';

$result = $DB->get_records_sql($sql, array(SSS_FILE_STATE_DUPLICATED));
$statusdata['duplicate'] = reset($result);

$result = $DB->get_records_sql($sql, array(SSS_FILE_STATE_EXTERNAL));
$statusdata['s3'] = reset($result);

$sql = 'SELECT count(DISTINCT contenthash) as filecount, SUM(filesize) as filesum from {files}';
$result = $DB->get_records_sql($sql);
$statusdata['disk'] = reset($result);

$statusdata['disk']->filecount -= $statusdata['duplicate']->filecount + $statusdata['s3']->filecount;
$statusdata['disk']->filesum -= $statusdata['duplicate']->filesum + $statusdata['s3']->filesum;

$this->statusdata = $statusdata;
}
}
43 changes: 43 additions & 0 deletions file_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* File status page - stats on where files are b/w local file system and s3
*
* @package tool_sssfs
* @author Kenneth Hendricks <kennethhendricks@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require('../../../config.php');
require_once($CFG->libdir.'/adminlib.php');

admin_externalpage_setup('tool_sssfs');

$output = $PAGE->get_renderer('tool_sssfs');

echo $output->header();

echo $output->heading(get_string('file_status_page', 'tool_sssfs'));

$filestatus = new \tool_sssfs\sss_file_status();
echo $output->render($filestatus);

echo $output->footer();



1 change: 1 addition & 0 deletions lang/en/tool_sssfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@

$string['pluginname'] = 'S3 File System';
$string['push_to_sss_task'] = 'S3 file system upload task';
$string['file_status_page'] = 'S3 file status';
44 changes: 44 additions & 0 deletions renderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\

/**
* File status renderer.
*
* @package tool_sssfs
* @author Kenneth Hendricks <kennethhendricks@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

class tool_sssfs_renderer extends plugin_renderer_base {
protected function render_sss_file_status(tool_sssfs\sss_file_status $filestatus) {
$output = '';

$table = new html_table();
// TODO: Make these lang strings.
// TODO: Convert size to readable format.
$table->head = array('File location', 'Files', 'Total size');

foreach ($filestatus->statusdata as $filetype => $filetypedata) {
$table->data[] = array($filetype, $filetypedata->filecount, $filetypedata->filesum);
}
$output .= html_writer::table($table);

return $output;
}


}
13 changes: 12 additions & 1 deletion settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();
defined('MOODLE_INTERNAL') || die();

if ($hassiteconfig) {

$externalpage = new admin_externalpage('tool_sssfs',
get_string('file_status_page', 'tool_sssfs'),
new moodle_url('/admin/tool/sssfs/file_status.php'));

$ADMIN->add('reports', $externalpage);

$settings = null;
}

0 comments on commit 99df3e1

Please sign in to comment.