MDL-38509 Add new tool_installaddon_installer::get_plugintype_root() method

This commit is contained in:
David Mudrák
2013-03-28 11:54:06 +01:00
parent a4fcf56f0a
commit 30bec5ba8d
3 changed files with 35 additions and 17 deletions
+29 -5
View File
@@ -115,13 +115,15 @@ class tool_installaddon_installer {
}
/**
* Is it possible to create a new plugin directory for the given plugin type?
* Returns the full path of the root of the given plugin type
*
* Null is returned if the plugin type is not known. False is returned if the plugin type
* root is expected but not found. Otherwise, string is returned.
*
* @throws coding_exception for invalid plugin types or non-existing plugin type locations
* @param string $plugintype
* @return boolean
* @return string|bool|null
*/
public function is_plugintype_writable($plugintype) {
public function get_plugintype_root($plugintype) {
$plugintypepath = null;
foreach (get_plugin_types() as $type => $fullpath) {
@@ -131,10 +133,32 @@ class tool_installaddon_installer {
}
}
if (is_null($plugintypepath)) {
throw new coding_exception('Unknown plugin type!');
return null;
}
if (!is_dir($plugintypepath)) {
return false;
}
return $plugintypepath;
}
/**
* Is it possible to create a new plugin directory for the given plugin type?
*
* @throws coding_exception for invalid plugin types or non-existing plugin type locations
* @param string $plugintype
* @return boolean
*/
public function is_plugintype_writable($plugintype) {
$plugintypepath = $this->get_plugintype_root($plugintype);
if (is_null($plugintypepath)) {
throw new coding_exception('Unknown plugin type!');
}
if ($plugintypepath === false) {
throw new coding_exception('Plugin type location does not exist!');
}
@@ -78,8 +78,7 @@ class tool_installaddon_installfromzip extends moodleform {
$errors = parent::validation($data, $files);
if (!$installer->is_plugintype_writable($data['plugintype'])) {
$paths = get_plugin_types(true);
$path = $paths[$data['plugintype']];
$path = $installer->get_plugintype_root($data['plugintype']);
$errors['plugintype'] = get_string('permcheckresultno', 'tool_installaddon', array('path' => $path));
}
+5 -10
View File
@@ -53,20 +53,15 @@ if (is_null($plugintype)) {
die();
}
$plugintypepath = null;
foreach (get_plugin_types() as $type => $fullpath) {
if ($type === $plugintype) {
$plugintypepath = $fullpath;
break;
}
}
if (is_null($plugintypepath)) {
$installer = tool_installaddon_installer::instance();
$plugintypepath = $installer->get_plugintype_root($plugintype);
if (empty($plugintypepath)) {
header('HTTP/1.1 400 Bad Request');
die();
}
$installer = tool_installaddon_installer::instance();
$response = array('path' => $plugintypepath);
if ($installer->is_plugintype_writable($plugintype)) {