How do you reference items in backup_controller’s get_results() output?

How do you reference items in backup_controller’s get_results() output?

by David Leeding -
Number of replies: 1

Hi

I’m writing an experimental script that makes use of the Moodle 2 backup classes, specifically backup_controller. All good so far, except I’m struggling with processing the output from get_results(). (This may well be due to limitations in my understanding of PHP.  smile )

My script includes this snippet:

    $bc = new backup_controller(…params etc...);
    $bc->execute_plan();
    $bc_results = $bc->get_results();

A var_dump on $bc_results shows that it contains lots of useful stuff (see below). What I’d like to do is extract the value from the ["contenthash"] key. I can see it there, but I can’t figure out how to reference it directly from $bc_results, despite trying many things. I’ve worked out an ugly, hacky way of converting the output to a string and processing it… there has to be a much (much, much) better way.

What is the most direct and efficient way of getting this value? Can any Moodle-PHP gurus out there help??

array(2) { ["backup_destination"]=> object(stored_file)#1445 (4) { ["fs":"stored_file":private]=> object(file_storage)#3164 (5) { ["filedir":"file_storage":private]=> string(39) "/mnt/moodle/moodledata-moodle2c/filedir" ["trashdir":"file_storage":private]=> string(40) "/mnt/moodle/moodledata-moodle2c/trashdir" ["tempdir":"file_storage":private]=> string(48) "/mnt/moodle/moodledata-moodle2c/temp/filestorage" ["dirpermissions":"file_storage":private]=> int(511) ["filepermissions":"file_storage":private]=> int(438) } ["file_record":"stored_file":private]=> object(stdClass)#1377 (19) { ["contextid"]=> string(6) "110110" ["component"]=> string(6) "backup" ["filearea"]=> string(9) "automated" ["itemid"]=> int(0) ["filepath"]=> string(1) "/" ["filename"]=> string(10) "backup.mbz" ["timecreated"]=> int(1346805604) ["timemodified"]=> int(1346805604) ["mimetype"]=> string(29) "application/vnd.moodle.backup" ["userid"]=> string(4) "4867" ["source"]=> NULL ["author"]=> NULL ["license"]=> NULL ["status"]=> int(0) ["sortorder"]=> int(0) ["filesize"]=> int(32685038) ["contenthash"]=> string(40) "5c80f779e99aaf98c66ceb9c0038c74b2e1889a4" ["pathnamehash"]=> string(40) "e17583908b116d06c00ec750b219426232648057" ["id"]=> int(643316) } ["filedir":"stored_file":private]=> string(39) "/mnt/moodle/moodledata-moodle2c/filedir" ["repository":"stored_file":private]=> NULL } ["include_file_references_to_external_content"]=> int(0) }

Thanks!!

David

Average of ratings: -
In reply to David Leeding

Re: How do you reference items in backup_controller’s get_results() output?

by David Leeding -

Never mind!

Turns out I can do what I want without the contenthash value:

     $bkpfile = $bc_results['backup_destination'];

Then do stuff with bkpfile. Thanks to Rosario for the uploadusersandcourses.php script which gave me a few clues (well, a lot of clues)!