MDL-36580 backup: Avoid PHP notice restoring old backups
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Oct 2017 20:49:10 +0000 (22:49 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 24 Oct 2017 20:49:10 +0000 (22:49 +0200)
Before this implementation, both resourcekey and password
were not being included in the backups, so old backups are
missing them. To keep upwards compatibility and avoid a PHP
Notice (undefined property), existence is checked via isset(),
that is the usual way all over the restore process.

mod/lti/backup/moodle2/restore_lti_stepslib.php

index 4a27592..f57186a 100644 (file)
@@ -89,8 +89,8 @@ class restore_lti_activity_structure_step extends restore_activity_structure_ste
 
         // Try to decrypt resourcekey and password. Null if not possible (DB default).
         // Note these fields were originally encrypted on backup using {link @encrypted_final_element}.
-        $data->resourcekey = $this->decrypt($data->resourcekey);
-        $data->password = $this->decrypt($data->password);
+        $data->resourcekey = isset($data->resourcekey) ? $this->decrypt($data->resourcekey) : null;
+        $data->password = isset($data->password) ? $this->decrypt($data->password) : null;
 
         $newitemid = $DB->insert_record('lti', $data);