From 142ec51fcd8f835f9d7de9f55730f4adc8b2cb9f Mon Sep 17 00:00:00 2001 From: Philip Cali Date: Mon, 14 Mar 2011 13:38:10 -0500 Subject: [PATCH] Added contextid generation... I think. --- backup/util/helper/convert_helper.class.php | 50 ++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/backup/util/helper/convert_helper.class.php b/backup/util/helper/convert_helper.class.php index 993a1ff38bc..ba37d9559ae 100644 --- a/backup/util/helper/convert_helper.class.php +++ b/backup/util/helper/convert_helper.class.php @@ -33,4 +33,52 @@ abstract class convert_helper { throw new restore_controller_exception('cannot_convert_from_unknown_format'); // @todo Change exception class } } -} \ No newline at end of file + + /** + * Inserts an inforef into the conversion temp table + */ + public static function set_inforef($contextid) { + global $DB; + + + } + + public static function get_inforef($contextid) { + } + + /** + * Converts a plain old php object (popo?) into a string... + * Useful for debuging failed db inserts, or anything like that + */ + public static function obj_to_readable($obj) { + $mapper = function($field, $value) { return "$field=$value"; }; + $fields = get_object_vars($obj); + + return implode(", ", array_map($mapper, array_keys($fields), array_values($fields))); + } + + public static function get_contextid($converterid, $itemid, $info='component') { + global $DB; + + // Attempt to retrieve the contextid + $context = $DB->get_record('backup_ids_temp', array('backupid' => $converterid, + 'itemid' => $itemid)); + + if($context) { + return $context->id; + } + + $context = new stdClass; + $context->itemid = $itemid; + $context->backupid = $converterid; + $context->itemname = 'context'; + $context->info = $info; + + if($id = $DB->insert('backup_ids_temp', $context)) { + return $id; + } else { + $msg = self::obj_to_readable($context); + throw new Exception(sprintf("Could not insert context record into temp table: %s", $msg)); + } + } +}