function services_get_updates in Services 7.3
Returns an array of available updates versions for a resource.
Return value
If services has updates, an array of available updates sorted by version. Otherwise, array().
4 calls to services_get_updates()
- ServicesVersionTests::testVersion in tests/
functional/ ServicesVersionTests.test - Test connect method.
- services_get_update_versions in plugins/
export_ui/ services_ctools_export_ui.class.php - Returns the updates for a given resource method.
- services_request_apply_version in ./
services.module - Apply versions to the controller.
- _services_version_header_options in ./
services.module - Determine if any potential versions exist as valid headers. returns false if no version is present in the header for the specific call.
File
- ./
services.module, line 701 - Provides a generic but powerful API for web services.
Code
function services_get_updates() {
$updates =& drupal_static(__FUNCTION__, array());
if (!isset($updates) || empty($updates)) {
$updates = array();
module_load_include('inc', 'services', 'includes/services.resource_build');
// Load the resources for services.
_services_core_resources();
// Prepare regular expression to match all possible defined
// _resource_resource_method_update_N_N().
$regexp = '/_(?P<resource>.+)_resource_(?P<method>.+)_update_(?P<major>\\d+)_(?P<minor>\\d+)$/';
$functions = get_defined_functions();
// Narrow this down to functions ending with an integer, since all
// _resource_resource_method_update_N_N() functions end this way, and there are other
// possible functions which match '_update_'. We use preg_grep() here
// instead of foreaching through all defined functions, since the loop
// through all PHP functions can take significant page execution time.
// Luckily this only happens when the cache is cleared for an endpoint
// and resources are re-generated.
$functions = preg_grep('/_\\d+$/', $functions['user']);
// Sort functions in alphabetical order, so functions with a larger version
// number will be used when needed
asort($functions);
foreach ($functions as $function) {
// If this function is a service update function, add it to the list of
// services updates.
if (preg_match($regexp, $function, $matches)) {
$resource = $matches['resource'];
$method = $matches['method'];
$major = $matches['major'];
$minor = $matches['minor'];
$updates[$resource][$method][] = array(
'version' => $major . '_' . $minor,
'major' => $major,
'minor' => $minor,
'callback' => $function,
'resource' => $resource,
'method' => $method,
);
}
}
}
return $updates;
}