Commit 98ca273e authored by Aaron Wells's avatar Aaron Wells

Bug 1620879: Remove extraneous "/webservice" from end of plugin components

Currently, a plugin has to list its component as e.g.
"module/mobileapi/webservice". This could just be "module/mobileapi".

Since we're using the component string as part of the automated token
request system, it's better to change this now to something more sensible.

behatnotneeded: Tests to come later

Change-Id: Ia7663065b79598d92c3bf8450c5539efb6aa3e2d
parent 2bffb229
......@@ -506,6 +506,47 @@ function xmldb_auth_webservice_upgrade($oldversion=0) {
if (!field_exists($table, $field)) {
add_field($table, $field);
}
// The old code listed the components with "/webservice"
// on the end of them, e.g. "artefact/internal/webservice".
// This is redundant and makes for a poorer user interface.
log_debug('Change in "component" format for plugins');
$oldtail = '/webservice';
$length = strlen($oldtail);
// Functions
execute_sql(
"UPDATE {external_functions}
SET
component = LEFT(
component,
LENGTH(component) - {$length}
)
WHERE
component <> 'webservice'
AND RIGHT(
component,
{$length}
) = '{$oldtail}'
"
);
// Services
execute_sql(
"UPDATE {external_services}
SET
component = LEFT(
component,
LENGTH(component) - {$length}
)
WHERE
component <> 'webservice'
AND RIGHT(
component,
{$length}
) = '{$oldtail}'
"
);
}
// sweep for webservice updates everytime
......
......@@ -1501,8 +1501,11 @@ function check_dir_exists($dir, $create=true, $recursive=true) {
* @param string $filename the name of the file to include within the plugin structure
* @param string $function (optional, defaults to require) the require/include function to use
* @param string $nonfatal (optional, defaults to false) just returns false if the file doesn't exist
* @param array $returnvars (optional, defaults to null) Variables (defined in the file) to return.
* Useful for files like version.php that simply define variables. If null, instead returns the
* value of the include/require operation.
*/
function safe_require($plugintype, $pluginname, $filename='lib.php', $function='require_once', $nonfatal=false) {
function safe_require($plugintype, $pluginname, $filename='lib.php', $function='require_once', $nonfatal=false, $returnvars = null) {
$plugintypes = plugin_types();
if (!in_array($plugintype, $plugintypes)) {
throw new SystemException("\"$plugintype\" is not a valid plugin type");
......@@ -1561,11 +1564,17 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
throw new SystemException ("File $fullpath was outside document root!");
}
if ($function == 'require') { return require($realpath); }
if ($function == 'include') { return include($realpath); }
if ($function == 'require_once') { return require_once($realpath); }
if ($function == 'include_once') { return include_once($realpath); }
if ($function == 'require') { $isloaded = require($realpath); }
if ($function == 'include') { $isloaded = include($realpath); }
if ($function == 'require_once') { $isloaded = require_once($realpath); }
if ($function == 'include_once') { $isloaded = include_once($realpath); }
if ($isloaded && $returnvars && is_array($returnvars)) {
return compact($returnvars);
}
else {
return $isloaded;
}
}
/**
......@@ -1583,11 +1592,13 @@ function safe_require($plugintype, $pluginname, $filename='lib.php', $function='
* @param string $filename the name of the file to include within the plugin structure
* @param string $function (optional, defaults to require) the require/include function to use
* @param string $nonfatal (optional, defaults to false) just returns false if the file doesn't exist
* @param array $returnvars (optional, defaults to null) Variables (defined in the file) to return.
* Useful for files like version.php that simply define variables. If null, instead returns the
* value of the include/require operation.
*/
function safe_require_plugin($plugintype, $pluginname, $filename='lib.php', $function='require_once', $nonfatal=false) {
function safe_require_plugin($plugintype, $pluginname, $filename='lib.php', $function='require_once', $nonfatal=false, $returnvars = null) {
try {
safe_require($plugintype, $pluginname, $filename, $function, $nonfatal);
return true;
return safe_require($plugintype, $pluginname, $filename, $function, $nonfatal, $returnvars);
}
catch (SystemException $e) {
if (get_field($plugintype . '_installed', 'active', 'name', $pluginname) == 1) {
......@@ -3618,7 +3629,7 @@ function get_my_tags($limit=null, $cloud=true, $sort='freq') {
array($id, $id, $id)
);
if (!$tagrecords) {
return false;
return array();
}
if ($cloud) {
$minfreq = $tagrecords[count($tagrecords) - 1]->count;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment