function get_content() { global $CFG, $USER; if ($this->content !== NULL) { return $this->content; } $content = ''; $footer = ''; $nologin_auths = block_repository_nopasswd_auths(); if (!empty($USER->auth) && in_array($USER->auth, $nologin_auths)) { return ''; } if (isloggedin() && file_exists($CFG->dirroot . '/file/repository/alfresco/repository.php')) { require_once $CFG->dirroot . '/file/repository/repository.class.php'; if (isset($CFG->repository_plugins_enabled) && strstr($CFG->repository_plugins_enabled, 'alfresco')) { if ($repo = repository_factory::factory('alfresco')) { if ($repo->alfresco_userdir($USER->username) !== false) { // Fix username $username = repository_plugin_alfresco::fix_username($USER->username); // So that we don't conflict with the default Alfresco admin account. $username = $username == 'admin' ? $CFG->repository_alfresco_admin_username : $username; $hastenant = false; // We must include the tenant portion of the username here. if (($tenantname = strpos($CFG->repository_alfresco_server_username, '@')) > 0) { $username .= substr($CFG->repository_alfresco_server_username, $tenantname); $hastenant = true; } // Display a link to access the Alfresco repository directly. $content .= get_string('webappaccess', 'block_repository', $repo->get_webapp_url()) . '<br /><br />'; // Display a link to the configured embedded WebDAV client (if defined). if (!empty($CFG->block_course_repository_webdav_client)) { $content .= get_string('embeddedwebdavlink', 'block_repository', $CFG->block_course_repository_webdav_client) . '<br /><br />'; } if ($hastenant || $username != $USER->username) { $content .= get_string('usernametenantinfo', 'block_repository', $username); } else { $content .= get_string('usernameinfo', 'block_repository', $username); } // Display a link to defined help files if (!empty($CFG->block_course_repository_help_link)) { $footer = get_string('helpfileslink', 'block_repository', $CFG->block_course_repository_help_link); } } } } } // If there is no content and the current user can actually modify the site settings, display some text // in the block explaining what is happening. if (empty($content) && has_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM))) { if (file_exists($CFG->dirroot . '/admin/file/repositories.php')) { $content = get_string('alfresconotconfigured', 'block_repository', $CFG->wwwroot . '/admin/file/' . 'repositories.php'); } else { $content = get_string('norepositorypluginsystem', 'block_repository'); } } $this->content = new stdClass(); $this->content->text = $content; $this->content->footer = $footer; return $this->content; }
/** * Handle the event when a user is created in Moodle. * * @uses $CFG * @param object $user Moodle user record object. * @return bool True on success, False otherwise. */ function block_repository_user_created($user) { global $CFG; $result = true; // Only proceed here if the Alfresco plug-in is actually enabled. if (!isset($CFG->repository_plugins_enabled) || strstr($CFG->repository_plugins_enabled, 'alfresco') === false || !($repo = repository_factory::factory('alfresco')) || !$repo->is_configured() || !$repo->verify_setup()) { error_log("block_repository_user_created(): Alfresco NOT enabled!"); return true; // TBD } // create a random password for certain authentications $auths = block_repository_nopasswd_auths(); if (!empty($user->auth) && in_array($user->auth, $auths)) { $passwd = random_string(8); //$user->password = md5($passwd); // TBD: or reversible encrypt //update_record('user', $user); //error_log("block_repository_user_created(): generating password for {$user->id} ({$user->auth}) => {$passwd}"); $result = $repo->migrate_user($user, $passwd); } return $result; }
function xmldb_block_repository_upgrade($oldversion = 0) { $result = true; if ($oldversion < 2010090901) { $errors = false; $auths = block_repository_nopasswd_auths(); $authlist = "'" . implode("', '", $auths) . "'"; $users = get_records_select('user', "auth IN ({$authlist})", '', 'id, auth'); if (!empty($users)) { foreach ($users as $user) { $user = get_complete_user_data('id', $user->id); $migrate_ok = block_repository_user_created($user); if (!$migrate_ok) { $errors = true; error_log("xmldb_block_repository_upgrade({$oldversion}) - failed migrating user ({$user->id}) to Alfresco."); } } } if (!$errors) { set_config('initialized', 1, repository_plugin_alfresco::$plugin_name); } } return $result; }
function repository_plugin_alfresco() { global $CFG, $USER; if (ALFRESCO_DEBUG_TRACE) { mtrace('repository_plugin_alfresco()'); } if (!$this->is_configured()) { return false; } if (!$this->is_running()) { return false; } if (!$this->get_defaults()) { return false; } $result = $this->verify_setup(); // Check if we need to initialize non-password users (openid, cas, ...) if ($result && !self::$init && is_siteadmin($USER->id) && !get_config(self::$plugin_name, 'initialized')) { require_once $CFG->dirroot . '/blocks/repository/lib.php'; error_log('repository_plugin_alfresco() - INFO: initializing users ...'); self::$init = true; $errors = 0; $auths = block_repository_nopasswd_auths(); $authlist = "'" . implode("', '", $auths) . "'"; $users = get_records_select('user', "auth IN ({$authlist})", '', 'id, auth'); if (!empty($users)) { foreach ($users as $user) { $user = get_complete_user_data('id', $user->id); $migrate_ok = block_repository_user_created($user); if (!$migrate_ok) { $errors++; error_log("repository_plugin_alfresco() - failed migrating user ({$user->id}) to Alfresco."); } } } error_log("repository_plugin_alfresco() - INFO: initialization complete ({$errors} errors)"); if (!$errors) { set_config('initialized', 1, self::$plugin_name); } } return $result; }