/** * Delete an Alfresco user account, optionally * * @param string $username The Alfresco account username to delete. * @param bool $deletehomedir Set to true to delete the user's home directory. * @return bool True on success, False otherwise. */ function alfresco_delete_user($username, $deletehomedir = false) { $status = true; $username = alfresco_transform_username($username); if ($deletehomedir) { $uuid = alfresco_get_home_directory($username); } $status = alfresco_send('/api/people/' . $username, array(), 'DELETE') !== false; // Actually go through with deleting the home directory if it was requested and we found the UUID. if (!empty($uuid)) { $status = $status && alfresco_delete($uuid, true); } return $status; }
} html_footer(); break; case "delete": if (!$canedit) { print_error('youdonothaveaccesstothisfunctionality', 'repository_alfresco'); } if ($confirm and confirm_sesskey()) { html_header($course, $wdir); $puuid = ''; if (!empty($USER->filelist)) { foreach ($USER->filelist as $uuid) { if (empty($puuid)) { $puuid = $repo->get_parent($uuid)->uuid; } if (!alfresco_delete($uuid)) { $node = alfresco_node_properties($uuid); debugging(get_string('couldnotdeletefile', 'repository_alfresco', $a)); } } } clearfilelist(); if ($id != SITEID) { displaydir($puuid, $wdir, $id); } else { displaydir($puuid, $wdir); } html_footer(); } else { html_header($course, $wdir); if (setfilelist($_POST)) {
/** * Migrate all the Moodle users who have an old-style Alfresco storage directory to have their own personal * Alfresco user accounts and storage. * * @param int $limit Limit the number of users migrated to the specified number (default 50). * @return bool True on success, False otherwise. */ function migrate_all_users($limit = 50) { global $CFG; if (ALFRESCO_DEBUG_TRACE) { mtrace('migrate_all_users(' . $limit . ')'); } $dir = $this->read_dir($this->uuuid); if (!empty($dir->folders)) { foreach ($dir->folders as $folder) { // Make sure that the folder name is actually just a Moodle user ID (created automatically by Moodle). preg_match('/^[0-9]+$/', $folder->title, $matches); if (!empty($matches) && is_array($matches) && count($matches) === 1) { $uid = current($matches); // If this user exists, migrate them to a legitimate Alfresco user now. if ($user = get_record('user', 'id', $uid, 'deleted', 0)) { if (!$this->migrate_user($user)) { debugging(get_string('couldnotmigrateuser', 'repository_alfresco', $user->username)); return false; } // If this user account in Moodle is deleted, then we will remove their Alfresco storage. } else { if (record_exists('user', 'id', $uid, 'deleted', 1)) { if (!afresco_delete($dir->uuid, true)) { debugging(get_string('couldnotdeletefile', 'repository_alfresco', $dir->title)); } } } } // Check that we are still within the requested limit of users to process. if ($limit-- <= 0) { return true; } } } // We must have migrated all the users but let's check to be sure. if ($limit > 0) { $dir = $this->read_dir($this->uuuid); if (empty($dir->folders)) { // We no longer need this directory so it may be removed now. alfresco_delete($this->uuuid); } } }