Skip to content

Commit

Permalink
MDL-39733 profiling: UI for importing runs
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 28, 2013
1 parent 1d3d4d1 commit 2e07539
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 5 deletions.
66 changes: 66 additions & 0 deletions admin/tool/profiling/import.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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/>.

/**
* Profiling tool import utility.
*
* @package tool_profiling
* @copyright 2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir . '/xhprof/xhprof_moodle.php');
require_once(dirname(__FILE__) . '/import_form.php');

admin_externalpage_setup('toolprofiling');

$PAGE->navbar->add(get_string('import', 'tool_profiling'));

// Calculate export variables.
$tempdir = 'profiling';
make_temp_directory($tempdir);

// URL where we'll end, both on success and failure.
$url = new moodle_url('/admin/tool/profiling/index.php');

// Instantiate the upload profiling runs form.
$mform = new profiling_import_form();

// If there is any file to import.
if ($data = $mform->get_data()) {
$filename = $mform->get_new_filename('mprfile');
$file = $CFG->tempdir . '/' . $tempdir . '/' . $filename;
$status = $mform->save_file('mprfile', $file);
if ($status) {
// File saved properly, let's import it.
$status = profiling_import_runs($file);
}
if ($status) {
// Import ended ok, let's redirect to main profiling page.
redirect($url, get_string('importok', 'tool_profiling', $filename));
}
} else {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('import', 'tool_profiling'));
$mform->display();
echo $OUTPUT->footer();
die;
}

// Something wrong happened, notice it and done.
notice(get_string('importproblem', 'tool_profiling', $filename), $url);
40 changes: 40 additions & 0 deletions admin/tool/profiling/import_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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/>.

/**
* Profiling tool import utility form.
*
* @package tool_profiling
* @copyright 2013 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

require_once($CFG->libdir . '/formslib.php');

class profiling_import_form extends moodleform {
function definition () {
$mform = $this->_form;

$mform->addElement('header', 'settingsheader', get_string('upload'));

$mform->addElement('filepicker', 'mprfile', get_string('file'), null, array('accepted_types' => array('.mpr')));
$mform->addRule('mprfile', null, 'required');

$this->add_action_buttons(false, get_string('import', 'tool_profiling'));
}
}
6 changes: 3 additions & 3 deletions admin/tool/profiling/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@

echo $OUTPUT->heading($header);

// Print the controller block with different options
echo profiling_list_controls($listurl);

// TODO: Fix flexitable to validate tsort/thide/tshow/tifirs/tilast/page
// TODO: Fix table_sql to allow it to work without WHERE clause
// add silly condition (1 = 1) because of table_sql bug
Expand All @@ -178,9 +181,6 @@
$table->define_baseurl($baseurl);
$table->column_suppress('url');
$table->out(PROFILING_RUNSPERPAGE, true);

// Print the controller block with different options
echo profiling_list_controls($listurl);
}

// Footer.
Expand Down
3 changes: 3 additions & 0 deletions admin/tool/profiling/lang/en/tool_profiling.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
$string['export'] = 'Export';
$string['exportproblem'] = 'Some problem happened exporting the profile run "{$a->runid}" corresponding to the request "{$a->listurl}".';
$string['exportthis'] = 'Export this profiling run';
$string['import'] = 'Import';
$string['importok'] = 'File "{$a}" imported successfully.';
$string['importproblem'] = 'Some problem happened importing the file "{$a}".';
$string['lastrunof'] = 'Summary of last run of {$a}';
$string['markreferencerun'] = 'Mark as reference run/comment';
$string['memory'] = 'Memory used';
Expand Down
19 changes: 17 additions & 2 deletions lib/xhprof/xhprof_moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,11 @@ function profiling_print_rundiff($run1, $run2) {
* like deletion/export/import...
*/
function profiling_list_controls($listurl) {
global $CFG, $OUTPUT;
global $CFG;

$output = '';
$output = '<p class="centerpara buttons">';
$output .= '&nbsp;<a href="import.php">[' . get_string('import', 'tool_profiling') . ']</a>';
$output .= '</p>';

return $output;
}
Expand Down Expand Up @@ -478,6 +480,19 @@ function profiling_export_runs(array $runids, $file) {
return $status;
}

/**
* Import a .mpr (moodle profile runs) file into moodle.
*
* See {@link profiling_export_runs()} for more details about the
* implementation of .mpr files.
*
* @param string $file filesystem fullpath to target .mpr file.
* @return boolean the mpr file has been succesfully imported (true) or no (false).
*/
function profiling_import_runs($file) {
return true;
}

/**
* Generate the mpr contents (xml files) in the temporal directory.
*
Expand Down

0 comments on commit 2e07539

Please sign in to comment.