Skip to content

Commit

Permalink
MDL-70139 core_badges: fix invalid request when sending to backpack
Browse files Browse the repository at this point in the history
Having mixed $data in badge exporters is causing some issues.
As all these exporters are using $data as an object, $data can be
converted to object in the constructor, to avoid errors and get
the expected behaviour always.
  • Loading branch information
sarjona committed Nov 6, 2020
1 parent ea32d65 commit e85c717
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions badges/classes/external/assertion_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@
*/
class assertion_exporter extends exporter {

/**
* Constructor - saves the persistent object, and the related objects.
*
* @param mixed $data - Either an stdClass or an array of values.
* @param array $related - An optional list of pre-loaded objects related to this object.
*/
public function __construct($data, $related = array()) {
// Having mixed $data is causing some issues. As this class is treating $data as an object everywhere, it can be converted
// to object at this point, to avoid errors and get the expected behaviour always.
// $data is an array when this class is a request exporter in backpack_api_mapping, but it is an object when this is
// used as a response exporter.
parent::__construct((object) $data, $related);
}

/**
* Map from a request response data to the internal structure.
*
Expand Down
6 changes: 6 additions & 0 deletions badges/classes/external/badgeclass_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class badgeclass_exporter extends exporter {
* @param array $related - An optional list of pre-loaded objects related to this object.
*/
public function __construct($data, $related = array()) {
// Having mixed $data is causing some issues. As this class is treating $data as an object everywhere, it can be converted
// to object at this point, to avoid errors and get the expected behaviour always.
// $data is an array when this class is a request exporter in backpack_api_mapping, but it is an object when this is
// used as a response exporter.
$data = (object) $data;

$pick = $this->pick_related();
foreach ($pick as $one) {
$isarray = false;
Expand Down

0 comments on commit e85c717

Please sign in to comment.