/** * This function removes any initialized data. */ protected function tearDown() { if ($dir = elis_files_read_dir()) { foreach ($dir->folders as $folder) { if (strpos($folder->title, FOLDER_NAME_PREFIX) === 0) { elis_files_delete($folder->uuid); break 1; } } } parent::tearDown(); }
/** * Remove temporary files that were created on the Alfresco instance during testing. * * @param string $uuid The UUID of the directory where test files were uploaded (optional). */ public function cleanup_files($uuid = '') { if (empty($this->fileuuid)) { return; } if (empty($uuid) && ($node = $this->repo->elis_files->get_parent($this->fileuuid)) && !empty($node->uuid)) { $uuid = $node->uuid; } else { return; } if ($dir = elis_files_read_dir($uuid)) { foreach ($dir->files as $file) { if (strpos($file->title, ELIS_FILES_PREFIX) === 0) { elis_files_delete($file->uuid); } } } }
/** * 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 elis_files_delete_user($username, $deletehomedir = false) { global $CFG; $status = true; $username = elis_files_transform_username($username); if ($deletehomedir) { $uuid = elis_files_get_home_directory($username); } $status = (elis_files_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 && elis_files_delete($uuid, true); } return $status; }
/** * This function removes files that are no longer needed. * @param string $uuid a unique file id */ public function cleanup_files($uuid = '') { if ($dir = elis_files_read_dir($uuid)) { foreach ($dir->files as $file) { if (strpos($file->title, ELIS_FILES_PREFIX) === 0) { elis_files_delete($file->uuid); } } } }
/** * 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, $DB; if (ELIS_FILES_DEBUG_TRACE) mtrace('migrate_all_users(' . $limit . ')'); $dir = $this->read_dir($this->uhomesuid); 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 = $DB->get_record('user', array('id'=> $uid, 'deleted'=> 0))) { if (!$this->migrate_user($user)) { debugging(get_string('couldnotmigrateuser', 'repository_elisfiles', $user->username)); return false; } // If this user account in Moodle is deleted, then we will remove their Alfresco storage. } else if ($user = $DB->get_record('user', array('id' => $uid, 'deleted' => 1))) { // The user's directory should have been deleted but their legacy directory may still // be hanging around // TODO: respect the "delete home directories" setting? if (!elis_files_delete($folder->uuid, true)) { debugging(get_string('couldnotdeletefile', 'repository_elisfiles', $folder->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. elis_files_delete($this->uuuid); } } }
/** * This function removes any initialized data. */ protected function tearDown() { foreach ($this->createduuids as $uuid) { elis_files_delete($uuid); } parent::tearDown(); }
/** * This function removes any initialized data. */ protected function tearDown() { global $USER; foreach ($this->createduuids as $uuid) { elis_files_delete($uuid); } if ($dir = elis_files_read_dir()) { foreach ($dir->files as $file) { if (strpos($file->title, FOLDER_NAME_PREFIX) === 0 || strpos($file->title, FILE_NAME_PREFIX) === 0 ) { elis_files_delete($file->uuid); } } } if ($this->testusercreated) { elis_files_delete_user($USER->username, true); } parent::tearDown(); }