/** * Migrate a user account from the old style of personal file storage to the new, SSO-based, approach. * * @param $CFG * @param object|string $userorusername The Moodle DB user record object or username. * @param string $password Optionally specify a password for the Alfresco account. * @return bool True on success, False otherwise. */ function migrate_user($userorusername, $password = '') { global $CFG; if (ALFRESCO_DEBUG_TRACE) { mtrace('migrate_user(' . (is_object($userorusername) ? 'object' : $userorusername) . ')'); } if (is_string($userorusername)) { if (!($user = get_record('user', 'username', $userorusername, 'mnethostid', $CFG->mnet_localhost_id))) { return false; } } else { if (is_object($userorusername)) { $user = $userorusername; } else { return false; } } // Create the user's Alfresco account (if one does not already exist). if (!alfresco_create_user($user, $password)) { return false; } // Fix username $username = $this->fix_username($user->username); // If the user has an old-style user directory, migrate it's contents and delete the directory. if ($this->has_old_user_store($user->id)) { $uuid = $this->get_user_store($user->id, true); if (($touuid = alfresco_get_home_directory($username)) === false) { debugging(get_string('couldnotgetalfrescouserdirectory', 'repository_alfresco', $username)); return false; } $dir = $this->read_dir($uuid, true); if (!empty($dir->folders)) { foreach ($dir->folders as $folder) { if (!alfresco_move_node($folder->uuid, $touuid)) { debugging(get_string('couldnotmovenode', 'repository_alfresco')); return false; } } } if (!empty($dir->files)) { foreach ($dir->files as $file) { if (!alfresco_move_node($file->uuid, $touuid)) { debugging(get_string('couldnotmovenode', 'repository_alfresco')); return false; } } } // Redmove the old-style user storage directory. if (!alfresco_delete($uuid, true)) { debugging(get_string('couldnotdeletefile', 'repository_alfresco', $user->id)); return false; } } return true; }
$USER->fileop = $action; $USER->filesource = $uuid; echo "<p align=\"center\">"; print_string("selectednowmove", "moodle", $count); echo "</p>"; } displaydir($uuid, $wdir, $id); html_footer(); break; case 'paste': html_header($course, $wdir); if (isset($USER->fileop) and $USER->fileop == "move" and confirm_sesskey()) { foreach ($USER->filelist as $file) { /// Determine if the content being moved is an Alfresco UUID or a moodledata file. if (preg_match('/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/', $file) > 0) { if (!alfresco_move_node($file, $uuid)) { if ($properties = $repo->get_info($file)) { echo '<p>Error: ' . $properties->title . ' not moved'; } else { echo '<p>Error: File not moved'; } } } else { if ($file[0] != '/') { $basedir .= '/'; } if (is_dir($basedir . $file)) { $status = $repo->upload_dir($basedir . $file, $uuid); } else { $status = $repo->upload_file('', $basedir . $file, $uuid); }