f2d8ed45e3
This is not really new class. Originally, the validator was implemented in the scope of the tool_installaddon plugin. But we need its features in other parts at the core level (e.g. during the upgrade to validate available missing dependencies or available updates). Looking back, it was a mistake to have it implemented at the plugin level rather than the core level. So this patch moves the tool_installaddon_validator class to \core\update\validator class, together with associated unit tests, fixture files and strings. There were changes made in the tool_installaddon to make use of this new class instead of the old one. This is a great step towards the bright future, hopefully there won't be many regressions. AMOS BEGIN MOV [validationmsg_componentmatch,tool_installaddon],[validationmsg_componentmatch,core_plugin] MOV [validationmsg_componentmismatchname,tool_installaddon],[validationmsg_componentmismatchname,core_plugin] MOV [validationmsg_componentmismatchname_help,tool_installaddon],[validationmsg_componentmismatchname_help,core_plugin] MOV [validationmsg_componentmismatchname_info,tool_installaddon],[validationmsg_componentmismatchname_info,core_plugin] MOV [validationmsg_componentmismatchtype,tool_installaddon],[validationmsg_componentmismatchtype,core_plugin] MOV [validationmsg_componentmismatchtype_info,tool_installaddon],[validationmsg_componentmismatchtype_info,core_plugin] MOV [validationmsg_filenotexists,tool_installaddon],[validationmsg_filenotexists,core_plugin] MOV [validationmsg_filesnumber,tool_installaddon],[validationmsg_filesnumber,core_plugin] MOV [validationmsg_filestatus,tool_installaddon],[validationmsg_filestatus,core_plugin] MOV [validationmsg_filestatus_info,tool_installaddon],[validationmsg_filestatus_info,core_plugin] MOV [validationmsg_foundlangfile,tool_installaddon],[validationmsg_foundlangfile,core_plugin] MOV [validationmsg_maturity,tool_installaddon],[validationmsg_maturity,core_plugin] MOV [validationmsg_maturity_help,tool_installaddon],[validationmsg_maturity_help,core_plugin] MOV [validationmsg_missingcomponent,tool_installaddon],[validationmsg_missingcomponent,core_plugin] MOV [validationmsg_missingcomponent_help,tool_installaddon],[validationmsg_missingcomponent_help,core_plugin] MOV [validationmsg_missingcomponent_link,tool_installaddon],[validationmsg_missingcomponent_link,core_plugin] MOV [validationmsg_missingexpectedlangenfile,tool_installaddon],[validationmsg_missingexpectedlangenfile,core_plugin] MOV [validationmsg_missingexpectedlangenfile_info,tool_installaddon],[validationmsg_missingexpectedlangenfile_info,core_plugin] MOV [validationmsg_missinglangenfile,tool_installaddon],[validationmsg_missinglangenfile,core_plugin] MOV [validationmsg_missinglangenfolder,tool_installaddon],[validationmsg_missinglangenfolder,core_plugin] MOV [validationmsg_missingversion,tool_installaddon],[validationmsg_missingversion,core_plugin] MOV [validationmsg_missingversionphp,tool_installaddon],[validationmsg_missingversionphp,core_plugin] MOV [validationmsg_multiplelangenfiles,tool_installaddon],[validationmsg_multiplelangenfiles,core_plugin] MOV [validationmsg_onedir,tool_installaddon],[validationmsg_onedir,core_plugin] MOV [validationmsg_onedir_help,tool_installaddon],[validationmsg_onedir_help,core_plugin] MOV [validationmsg_pathwritable,tool_installaddon],[validationmsg_pathwritable,core_plugin] MOV [validationmsg_pluginversion,tool_installaddon],[validationmsg_pluginversion,core_plugin] MOV [validationmsg_release,tool_installaddon],[validationmsg_release,core_plugin] MOV [validationmsg_requiresmoodle,tool_installaddon],[validationmsg_requiresmoodle,core_plugin] MOV [validationmsg_rootdir,tool_installaddon],[validationmsg_rootdir,core_plugin] MOV [validationmsg_rootdir_help,tool_installaddon],[validationmsg_rootdir_help,core_plugin] MOV [validationmsg_rootdirinvalid,tool_installaddon],[validationmsg_rootdirinvalid,core_plugin] MOV [validationmsg_rootdirinvalid_help,tool_installaddon],[validationmsg_rootdirinvalid_help,core_plugin] MOV [validationmsg_targetexists,tool_installaddon],[validationmsg_targetexists,core_plugin] MOV [validationmsg_targetexists_help,tool_installaddon],[validationmsg_targetexists_help,core_plugin] MOV [validationmsg_unknowntype,tool_installaddon],[validationmsg_unknowntype,core_plugin] MOV [validationmsg_versionphpsyntax,tool_installaddon],[validationmsg_versionphpsyntax,core_plugin] MOV [validationmsglevel_debug,tool_installaddon],[validationmsglevel_debug,core_plugin] MOV [validationmsglevel_error,tool_installaddon],[validationmsglevel_error,core_plugin] MOV [validationmsglevel_info,tool_installaddon],[validationmsglevel_info,core_plugin] MOV [validationmsglevel_warning,tool_installaddon],[validationmsglevel_warning,core_plugin] AMOS END
359 lines
12 KiB
PHP
359 lines
12 KiB
PHP
<?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/>.
|
|
|
|
/**
|
|
* Output rendering for the plugin.
|
|
*
|
|
* @package tool_installaddon
|
|
* @category output
|
|
* @copyright 2013 David Mudrak <david@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Implements the plugin renderer
|
|
*
|
|
* @copyright 2013 David Mudrak <david@moodle.com>
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class tool_installaddon_renderer extends plugin_renderer_base {
|
|
|
|
/** @var tool_installaddon_installer */
|
|
protected $installer = null;
|
|
|
|
/** @var \core\update\validator */
|
|
protected $validator = null;
|
|
|
|
/**
|
|
* Sets the tool_installaddon_installer instance being used.
|
|
*
|
|
* @throws coding_exception if the installer has been already set
|
|
* @param tool_installaddon_installer $installer
|
|
*/
|
|
public function set_installer_instance(tool_installaddon_installer $installer) {
|
|
if (is_null($this->installer)) {
|
|
$this->installer = $installer;
|
|
} else {
|
|
throw new coding_exception('Attempting to reset the installer instance.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Sets the \core\update\validator instance being used.
|
|
*
|
|
* @throws coding_exception if the validator has been already set
|
|
* @param \core\update\validator $validator
|
|
*/
|
|
public function set_validator_instance(\core\update\validator $validator) {
|
|
if (is_null($this->validator)) {
|
|
$this->validator = $validator;
|
|
} else {
|
|
throw new coding_exception('Attempting to reset the validator instance.');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Defines the index page layout
|
|
*
|
|
* @return string
|
|
*/
|
|
public function index_page() {
|
|
|
|
if (is_null($this->installer)) {
|
|
throw new coding_exception('Installer instance has not been set.');
|
|
}
|
|
|
|
$permcheckurl = new moodle_url('/admin/tool/installaddon/permcheck.php');
|
|
$this->page->requires->yui_module('moodle-tool_installaddon-permcheck', 'M.tool_installaddon.permcheck.init',
|
|
array(array('permcheckurl' => $permcheckurl->out())));
|
|
$this->page->requires->strings_for_js(
|
|
array('permcheckprogress', 'permcheckresultno', 'permcheckresultyes', 'permcheckerror', 'permcheckrepeat'),
|
|
'tool_installaddon');
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->index_page_heading();
|
|
$out .= $this->index_page_repository();
|
|
$out .= $this->index_page_upload();
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Defines the validation results page layout
|
|
*
|
|
* @return string
|
|
*/
|
|
public function validation_page() {
|
|
|
|
if (is_null($this->installer)) {
|
|
throw new coding_exception('Installer instance has not been set.');
|
|
}
|
|
|
|
if (is_null($this->validator)) {
|
|
throw new coding_exception('Validator instance has not been set.');
|
|
}
|
|
|
|
$out = $this->validation_page_heading();
|
|
$out .= $this->validation_page_messages();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Inform the user about invalid remote installation request.
|
|
*
|
|
* @param moodle_url $continueurl
|
|
* @return string
|
|
*/
|
|
public function remote_request_invalid_page(moodle_url $continueurl) {
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->box(get_string('remoterequestinvalid', 'tool_installaddon'), 'generalbox', 'notice');
|
|
$out .= $this->output->continue_button($continueurl, 'get');
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Inform the user that such plugin is already installed
|
|
*
|
|
* @param stdClass $data decoded request data
|
|
* @param moodle_url $continueurl
|
|
* @return string
|
|
*/
|
|
public function remote_request_alreadyinstalled_page(stdClass $data, moodle_url $continueurl) {
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->box(get_string('remoterequestalreadyinstalled', 'tool_installaddon', $data), 'generalbox', 'notice');
|
|
$out .= $this->output->continue_button($continueurl, 'get');
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Let the user confirm the remote installation request.
|
|
*
|
|
* @param stdClass $data decoded request data
|
|
* @param moodle_url $continueurl
|
|
* @param moodle_url $cancelurl
|
|
* @return string
|
|
*/
|
|
public function remote_request_confirm_page(stdClass $data, moodle_url $continueurl, moodle_url $cancelurl) {
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->confirm(get_string('remoterequestconfirm', 'tool_installaddon', $data), $continueurl, $cancelurl);
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Inform the user that the target plugin type location is not writable.
|
|
*
|
|
* @param stdClass $data decoded request data
|
|
* @param string $plugintypepath full path to the plugin type location
|
|
* @param moodle_url $continueurl to repeat the write permission check
|
|
* @param moodle_url $cancelurl to cancel the installation
|
|
* @return string
|
|
*/
|
|
public function remote_request_permcheck_page(stdClass $data, $plugintypepath, moodle_url $continueurl, moodle_url $cancelurl) {
|
|
|
|
$data->typepath = $plugintypepath;
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->confirm(get_string('remoterequestpermcheck', 'tool_installaddon', $data), $continueurl, $cancelurl);
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Inform the user about pluginfo service call failure
|
|
*
|
|
* @param stdClass $data decoded request data
|
|
* @param moodle_url $continueurl
|
|
* @return string
|
|
*/
|
|
public function remote_request_pluginfo_failure(stdClass $data, moodle_url $continueurl) {
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->box(get_string('remoterequestpluginfoexception', 'tool_installaddon', $data), 'generalbox', 'notice');
|
|
$out .= $this->output->continue_button($continueurl, 'get');
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Inform the user about the installer exception
|
|
*
|
|
* This implementation does not actually use the passed exception. Custom renderers might want to
|
|
* display additional data obtained via {@link get_exception_info()}. Also note, this method is called
|
|
* in non-debugging mode only. If debugging is allowed at the site, default exception handler is triggered.
|
|
*
|
|
* @param tool_installaddon_installer_exception $e thrown exception
|
|
* @param moodle_url $continueurl
|
|
* @return string
|
|
*/
|
|
public function installer_exception(tool_installaddon_installer_exception $e, moodle_url $continueurl) {
|
|
|
|
$out = $this->output->header();
|
|
$out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon'));
|
|
$out .= $this->output->box(get_string('installexception', 'tool_installaddon'), 'generalbox', 'notice');
|
|
$out .= $this->output->continue_button($continueurl, 'get');
|
|
$out .= $this->output->footer();
|
|
|
|
return $out;
|
|
}
|
|
|
|
// End of the external API /////////////////////////////////////////////////
|
|
|
|
/**
|
|
* Renders the index page heading
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function index_page_heading() {
|
|
return $this->output->heading(get_string('pluginname', 'tool_installaddon'));
|
|
}
|
|
|
|
/**
|
|
* Renders the widget for browsing the add-on repository
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function index_page_repository() {
|
|
|
|
$url = $this->installer->get_addons_repository_url();
|
|
|
|
$out = $this->box(
|
|
$this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get').
|
|
$this->output->help_icon('installfromrepo', 'tool_installaddon'),
|
|
'generalbox', 'installfromrepobox'
|
|
);
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Renders the widget for uploading the add-on ZIP package
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function index_page_upload() {
|
|
|
|
$form = $this->installer->get_installfromzip_form();
|
|
|
|
ob_start();
|
|
$form->display();
|
|
$out = ob_get_clean();
|
|
|
|
$out = $this->box($out, 'generalbox', 'installfromzipbox');
|
|
|
|
return $out;
|
|
}
|
|
|
|
/**
|
|
* Renders the page title and the overall validation verdict
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function validation_page_heading() {
|
|
|
|
$heading = $this->output->heading(get_string('validation', 'tool_installaddon'));
|
|
|
|
if ($this->validator->get_result()) {
|
|
$status = $this->output->container(
|
|
html_writer::span(get_string('validationresult1', 'tool_installaddon'), 'verdict').
|
|
$this->output->help_icon('validationresult1', 'tool_installaddon'),
|
|
array('validationresult', 'success')
|
|
);
|
|
} else {
|
|
$status = $this->output->container(
|
|
html_writer::span(get_string('validationresult0', 'tool_installaddon'), 'verdict').
|
|
$this->output->help_icon('validationresult0', 'tool_installaddon'),
|
|
array('validationresult', 'failure')
|
|
);
|
|
}
|
|
|
|
return $heading . $status;
|
|
}
|
|
|
|
/**
|
|
* Renders validation log messages.
|
|
*
|
|
* @return string
|
|
*/
|
|
protected function validation_page_messages() {
|
|
|
|
$validator = $this->validator; // We need this to be able to use their constants.
|
|
$messages = $validator->get_messages();
|
|
|
|
if (empty($messages)) {
|
|
return '';
|
|
}
|
|
|
|
$table = new html_table();
|
|
$table->attributes['class'] = 'validationmessages generaltable';
|
|
$table->head = array(
|
|
get_string('validationresultstatus', 'tool_installaddon'),
|
|
get_string('validationresultmsg', 'tool_installaddon'),
|
|
get_string('validationresultinfo', 'tool_installaddon')
|
|
);
|
|
$table->colclasses = array('msgstatus', 'msgtext', 'msginfo');
|
|
|
|
$stringman = get_string_manager();
|
|
|
|
foreach ($messages as $message) {
|
|
|
|
if ($message->level === $validator::DEBUG and !debugging()) {
|
|
continue;
|
|
}
|
|
|
|
$msgstatus = $validator->message_level_name($message->level);
|
|
$msgtext = $validator->message_code_name($message->msgcode);
|
|
$msginfo = $validator->message_code_info($message->msgcode, $message->addinfo);
|
|
if (empty($msginfo) and $message->addinfo !== null) {
|
|
$msginfo = html_writer::tag('pre', s(print_r($message->addinfo, true)));
|
|
}
|
|
$msghelpicon = $validator->message_help_icon($message->msgcode);
|
|
if ($msghelpicon) {
|
|
$msghelp = $this->output->render($msghelpicon);
|
|
} else {
|
|
$msghelp = '';
|
|
}
|
|
|
|
$row = new html_table_row(array($msgstatus, $msgtext.$msghelp, $msginfo));
|
|
$row->attributes['class'] = 'level-'.$message->level.' '.$message->msgcode;
|
|
|
|
$table->data[] = $row;
|
|
}
|
|
|
|
return html_writer::table($table);
|
|
}
|
|
}
|