Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

The source passed to the migrate_directory() may not exist

In case the source $rootpath passed to the migrate_directory() does not
exist, an empty array is returned by the method. Note that if the
directory exists and is empty, the directory itself is converter so
there would be a new record created. However, the restore process
ignores these records anyway, as the directory records are created
automatically by certain file api methods.
  • Loading branch information...
commit 93264625f2eb4dcd77280efb077b7e3580c38b53 1 parent 214c492
@mudrd8mz mudrd8mz authored
View
6 backup/converter/moodle1/lib.php
@@ -1120,10 +1120,14 @@ public function migrate_file($sourcepath, $filepath = '/', $filename = null, $ti
*
* @param string $rootpath path within the backup archive to the root directory containing the files {@example 'course_files'}
* @param string $relpath relative path used during the recursion - do not provide when calling this!
- * @return array ids of the migrated files
+ * @return array ids of the migrated files, empty array if the $rootpath not found
*/
public function migrate_directory($rootpath, $relpath='/') {
+ if (!file_exists($this->basepath.'/'.$rootpath.$relpath)) {
+ return array();
+ }
+
$fileids = array();
// make the fake file record for the directory itself
View
7 backup/converter/moodle1/simpletest/testlib.php
@@ -205,6 +205,13 @@ public function test_migrate_file() {
$fileids = $fileman->get_fileids();
$this->assertIsA($fileids, 'array');
$this->assertEqual(0, count($fileids));
+ // try to migrate a non-existing directory
+ $returned = $fileman->migrate_directory('not/existing/directory');
+ $this->assertIsA($returned, 'array');
+ $this->assertEqual(0, count($returned));
+ $fileids = $fileman->get_fileids();
+ $this->assertIsA($fileids, 'array');
+ $this->assertEqual(0, count($fileids));
// migrate a single file
$fileman->itemid = 4;
$fileman->migrate_file('moddata/unittest/4/icon.gif');
Please sign in to comment.
Something went wrong with that request. Please try again.