Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-21999

Web service do not support optional parameter (break some Zend calls)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: Web Services
    • Labels:
      None
    • Difficulty:
      Difficult
    • Affected Branches:
      MOODLE_20_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE

      Description

      They currently support optional attribut but not optional param.

      For example a generated class with two optional param should be:

        $code ="
      /**
       * Virtual class web services for user id 11 in context 1.
       */
      class webservices_virtual_class_000000 {
       
          /**
           * Return hubs found against some parameters, return all visible hubs if no parameters
           *
           * @param string $search String that will be compare to hub name and hub description
           * @param string $language language code
           * @return array Found hubs
           */
          public function hubdirectory_get_hubs($search=null, $language=null) {
          if (local_hubdirectory_external::get_hubs_returns() == null)  {
                              return null;
                          }
                          return external_api::clean_returnvalue(local_hubdirectory_external::get_hubs_returns(), local_hubdirectory_external::get_hubs($search, $language));
          }
       
      }

      but it's currently generated as :

        $code ="
      /**
       * Virtual class web services for user id 11 in context 1.
       */
      class webservices_virtual_class_000000 {
       
          /**
           * Return hubs found against some parameters, return all visible hubs if no parameters
           *
           * @param string $search String that will be compare to hub name and hub description
           * @param string $language language code
           * @return array Found hubs
           */
          public function hubdirectory_get_hubs($search, $language) {
          if (local_hubdirectory_external::get_hubs_returns() == null)  {
                              return null;
                          }
                          return external_api::clean_returnvalue(local_hubdirectory_external::get_hubs_returns(), local_hubdirectory_external::get_hubs($search, $language));
          }
       
      }

      You can see in the function definition it misses =null

      The fix is :
      during class generation on the fly, check if the param is VALUE_DEFAULT/VALUE_OPTIONAL into the description and putting =the_default or =null next to the params (as it is in the hard coded function)

        Attachments

          Activity

            People

            Assignee:
            jerome Jérôme Mouneyrac
            Reporter:
            jerome Jérôme Mouneyrac
            Tester:
            Nobody
            Participants:
            Component watchers:
            Juan Leyva, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              24/Nov/10