MDL-49543 badges: minor tweaks
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 25 Mar 2015 00:37:33 +0000 (01:37 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Wed, 25 Mar 2015 00:37:33 +0000 (01:37 +0100)
Fix restore to support old criteria not having descriptions.
Plus delete not-needed cast (now $params is always already array).

backup/moodle2/restore_stepslib.php
badges/criteria/award_criteria.php

index 014cfb4..209f97d 100644 (file)
@@ -2272,8 +2272,8 @@ class restore_badges_structure_step extends restore_structure_step {
                 'badgeid'           => $this->get_new_parentid('badge'),
                 'criteriatype'      => $data->criteriatype,
                 'method'            => $data->method,
-                'description'       => $data->description,
-                'descriptionformat' => $data->descriptionformat,
+                'description'       => isset($data->description) ? $data->description : '',
+                'descriptionformat' => isset($data->descriptionformat) ? $data->descriptionformat : 0,
         );
         $newid = $DB->insert_record('badge_criteria', $params);
         $this->set_mapping('criterion', $data->id, $newid);
index 2d102dc..58ccf86 100644 (file)
@@ -373,7 +373,7 @@ abstract class award_criteria {
 
         // Pick only params that are required by this criterion.
         // Filter out empty values first.
-        $params = array_filter((array)$params);
+        $params = array_filter($params);
         // Find out which param matches optional and required ones.
         $match = array_merge($this->optional_params, array($this->required_param));
         $regex = implode('|', array_map(create_function('$a', 'return $a . "_";'), $match));