I think this is a bug, but I'm not sure.

I have a working API based on the services module for one year now. And today I started working on a second version.
I browsed through the code to find out how I should build my resource files in order to support different versions.

At the moment it works but I had to "hack" the services module.
Look at this function:

/**
 * Returns currently set api version for an endpoint resource method.
 *
 * @param $endpoint
 *   A fully loadded endpoint.
 * @param $resource
 *   A resource name.
 * @param $method
 *   A method name.
 * @return
 *   an array with the major and minor api versions
 */
function services_get_resource_api_version($endpoint, $resource, $method) {
  if (isset($endpoint->resources[$resource]) ) {
    $class_info = services_operation_class_info();
    foreach ($class_info as $class_name => $class) {
      if (!empty($resource[$class_name])) {
        if (isset($endpoint->resources[$resource][$class_name][$method]['settings']['services']['resource_api_version'])) {
          if($version = _services_version_header_options()) {
            $split = explode('.', $version);
          } else {
            $split = explode('.', $endpoint->resources[$resource][$class_name][$method]['settings']['services']['resource_api_version']);
          }
          return array(
            'major' => $split[0],
            'minor' => $split[1],
          );
        }
      }
    }
  }
}

It defines in it's docblock that "@param $resource" is a String, the name of the resource.
In my case it is "frontpage".

A few lines beneath that you'll see the following line

if (!empty($resource[$class_name])) {

I wonder how this can work as

  1. $resource is a string an not an array
  2. $classname can only be one of these: 'operations', 'actions', 'relationships', 'targeted_actions'

After removing that line everything seems to work, but I'm not sure if it causes any problems I can't think off.

Comments

aspilicious’s picture

Issue summary: View changes
kylebrowning’s picture

This is interesting.

I wrote that code a long time ago and can't seem to remember why.

Can you upload a patch with this change and set to needs review? If it passes I will commit.

aspilicious’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

I still wonder why I'm the first to report this :s

aspilicious’s picture

Why is he patch postponed?

kylebrowning’s picture

Its not postponed, i think the issue is our current 7.x-3.x branch is failing.

aspilicious’s picture

Do you have an estimate time of arrival for the testbot fixes?

alejo d’s picture

don't need delete

if (!empty($resource[$class_name])) {

just validate with

if (!empty($endpoint->resources[$resource][$class_name])) {

And at services/plugins/export_ui/services_ctools_export_ui.class.php

Line: 379

Replace the disabled to FALSE, so it can be saved and can be use the header version Services-User-Login-Version: 2.1

if (count($options) !== 1) {
            $controller_settings['services'] = array(
              '#title' => 'Services',
              '#type' => 'item',
              'resource_api_version' => array(
                '#type' => 'select',
                '#options' => $options,
                '#default_value' => $default_api_value,
                '#title' => 'Resource API Version',
                '#disabled' => FALSE,
                  '#attributes' => array(
                      'readonly'=>'readonly',
                      'style'=>'background: none repeat scroll 0 0 #EAEAEA;'
                  )
              ),
            );
          }
kylebrowning’s picture

Please provide a patch.

alejo d’s picture

here is the patch to fix the version selector and use it

alejo d’s picture

can you see my patch ? its working very well :D

kylebrowning’s picture

Status: Needs review » Reviewed & tested by the community
marcingy’s picture

Status: Reviewed & tested by the community » Fixed

Merged thanks!

  • marcingy committed 6d93f73 on 7.x-3.x authored by allcoders
    Issue #2487812 by aspilicious, allcoders: Versioning doesn't work with...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.