MDL-22414 Added new method to get the list of existing stashes

This commit is contained in:
David Mudrak
2011-06-03 18:54:57 +02:00
parent a4158f8d93
commit cd92d83bf2
2 changed files with 25 additions and 0 deletions
+15
View File
@@ -443,6 +443,21 @@ class moodle1_converter extends base_converter {
}
}
/**
* Returns the list of existing stashes
*
* @return array
*/
public function get_stash_names() {
global $DB;
$search = array(
'backupid' => $this->get_id(),
);
return array_keys($DB->get_records('backup_ids_temp', $search, '', 'itemname'));
}
/**
* Returns the list of stashed $itemids in the given stash
*
@@ -109,9 +109,19 @@ class moodle1_converter_test extends UnitTestCase {
$converter = convert_factory::get_converter('moodle1', $this->tempdir);
$converter->create_stash_storage();
// no implicit stashes
$stashes = $converter->get_stash_names();
$this->assertIsA($stashes, 'array');
$this->assertTrue(empty($stashes));
// test stashes without itemid
$converter->set_stash('tempinfo1', 12);
$converter->set_stash('tempinfo2', array('a' => 2, 'b' => 3));
$stashes = $converter->get_stash_names();
$this->assertIsA($stashes, 'array');
$this->assertEqual(2, count($stashes));
$this->assertTrue(in_array('tempinfo1', $stashes));
$this->assertTrue(in_array('tempinfo2', $stashes));
$this->assertIdentical(12, $converter->get_stash('tempinfo1'));
$this->assertIdentical(array('a' => 2, 'b' => 3), $converter->get_stash('tempinfo2'));