-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2 Add basic reporting on file status
- Loading branch information
1 parent
2779c85
commit 99df3e1
Showing
5 changed files
with
164 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters