Beispiel #1
0
    /**
     * Add Plugin settings input to Moodle form
     * @param object $mform
     */
    public static function type_config_form($mform, $classname = 'repository') {
        global $DB, $CFG, $SESSION, $OUTPUT;

        parent::type_config_form($mform, $classname);

        $mform->addElement('text', 'server_host', get_string('serverurl', 'repository_elisfiles'), array('size' => '40'));
        $mform->setDefault('server_host', 'http://localhost');
        $mform->setType('server_host', PARAM_TEXT);
        $mform->addElement('static', 'server_host_default', '', get_string('elis_files_default_server_host', 'repository_elisfiles'));
        $mform->addElement('static', 'server_host_intro', '', get_string('elis_files_server_host', 'repository_elisfiles'));
        $mform->addRule('server_host', get_string('required'), 'required', null, 'client');

        $mform->addElement('text', 'server_port', get_string('serverport', 'repository_elisfiles'), array('size' => '30'));
        $mform->addElement('static', 'server_port_default', '', get_string('elis_files_default_server_port', 'repository_elisfiles'));
        $mform->addElement('static', 'server_port_intro', '', get_string('elis_files_server_port', 'repository_elisfiles'));

        $mform->addRule('server_port', get_string('required'), 'required', null, 'client');
        $mform->setDefault('server_port', '8080');
        $mform->setType('server_port', PARAM_INT);

        $mform->addElement('text', 'server_username', get_string('serverusername', 'repository_elisfiles'), array('size' => '30'));
        $mform->addElement('static', 'server_username_default', '', get_string('elis_files_default_server_username', 'repository_elisfiles'));
        $mform->addElement('static', 'server_username_intro', '', get_string('elis_files_server_username', 'repository_elisfiles'));
        $mform->addRule('server_username', get_string('required'), 'required', null, 'client');
        $mform->setType('server_username', PARAM_TEXT);

        $mform->addElement('passwordunmask', 'server_password', get_string('serverpassword', 'repository_elisfiles'), array('size' => '30'));
        $mform->addElement('static', 'server_password_intro', '', get_string('elis_files_server_password', 'repository_elisfiles'));
        $mform->addRule('server_password', get_string('required'), 'required', null, 'client');
        $mform->setType('server_password', PARAM_TEXT);

        $options = array(
            ELIS_FILES_XFER_WS  => get_string('webservices', 'repository_elisfiles'),
            ELIS_FILES_XFER_FTP => get_string('ftp', 'repository_elisfiles')
        );

        $mform->addElement('select', 'file_transfer_method', get_string('filetransfermethod', 'repository_elisfiles'), $options);
        $mform->setDefault('file_transfer_method', ELIS_FILES_XFER_FTP);
        $mform->addElement('static', 'file_transfer_method_default', '', get_string('filetransfermethoddefault', 'repository_elisfiles'));
        $mform->addElement('static', 'file_transfer_method_desc', '', get_string('filetransfermethoddesc', 'repository_elisfiles'));

        // Add a green checkmark if FTP connection works, red X on failure
        // (only if transfer method is set to ftp)
        $ftp_indicator = self::get_ftp_config_indicator();
        $mform->addElement('text', 'ftp_port', get_string('ftpport', 'repository_elisfiles'), array('size' => '30'));
        $mform->setDefault('ftp_port', '21');
        $mform->setType('ftp_port', PARAM_INT);
        $mform->addElement('static', 'ftp_port_default', '', $ftp_indicator.'&nbsp'.get_string('ftpportdefault', 'repository_elisfiles'));
        $mform->addElement('static', 'ftp_port_desc', '', get_string('ftpportdesc', 'repository_elisfiles'));

        $mform->addElement('text', 'connect_timeout', get_string('connecttimeout', 'repository_elisfiles'), array('size' => '10'));
        $mform->setType('connect_timeout', PARAM_INT);
        $mform->setDefault('connect_timeout', ELIS_FILES_CURL_CONNECT_TIMEOUT);
        $mform->addElement('static', 'connect_timeout_default', '', get_string('connecttimeoutdefault', 'repository_elisfiles', ELIS_FILES_CURL_CONNECT_TIMEOUT));
        $mform->addElement('static', 'connect_timeout_desc', '', get_string('connecttimeoutdesc', 'repository_elisfiles'));

        $mform->addElement('text', 'response_timeout', get_string('responsetimeout', 'repository_elisfiles'), array('size' => '10'));
        $mform->setType('response_timeout', PARAM_INT);
        $mform->setDefault('response_timeout', ELIS_FILES_CURL_RESPONSE_TIMEOUT);
        $mform->addElement('static', 'response_timeout_default', '', get_string('responsetimeoutdefault', 'repository_elisfiles', ELIS_FILES_CURL_RESPONSE_TIMEOUT));
        $mform->addElement('static', 'response_timeout_desc', '', get_string('responsetimeoutdesc', 'repository_elisfiles'));

        // Check for installed categories table or display 'plugin not yet installed'
        if ($DB->get_manager()->table_exists('repository_elisfiles_cats')) {
        // Need to check for settings to be saved
            $popup_settings ="height=400,width=500,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent";
            $url = $CFG->wwwroot .'/repository/elisfiles/config-categories.php';
            $jsondata = array('url'=>$url,'name'=>'config_categories','options'=>$popup_settings);
            $jsondata = json_encode($jsondata);
            $title = get_string('configurecategoryfilter', 'repository_elisfiles');

            $button = "<input type='button' value='".$title."' alt='".$title."' title='".$title."' onclick='return openpopup(null,$jsondata);'>";
            $mform->addElement('static', 'category_filter', get_string('categoryfilter', 'repository_elisfiles'), $button);
            $mform->addElement('static', 'category_filter_intro', '', get_string('elis_files_category_filter', 'repository_elisfiles'));
        } else {
            $mform->addElement('static', 'category_filter_intro', get_string('categoryfilter', 'repository_elisfiles'), get_string('elisfilesnotinstalled', 'repository_elisfiles'));
        }

        $popup_settings = "height=480,width=640,top=0,left=0,menubar=0,location=0,scrollbars,resizable,toolbar,status,directories=0,fullscreen=0,dependent";

        $root_folder = get_config('elisfiles', 'root_folder');
        $button = self::output_root_folder_html($root_folder);

        $rootfolderarray=array();
        $rootfolderarray[] = $mform->createElement('text', 'root_folder', get_string('rootfolder', 'repository_elisfiles'), array('size' => '30'));
        $rootfolderarray[] = $mform->createElement('button', 'root_folder_popup', get_string('chooserootfolder', 'repository_elisfiles'), $button);

        $mform->addGroup($rootfolderarray, 'rootfolderar', get_string('rootfolder', 'repository_elisfiles'), array(' '), false);
        $mform->setDefault('root_folder', '/moodle');
        $mform->setType('root_folder', PARAM_TEXT);

        // Add checkmark if get root folder works, or whatever...
        $valid = self::root_folder_is_valid($root_folder);
        $mform->addElement('static', 'root_folder_default', '', $valid.'&nbsp;'.get_string('elis_files_default_root_folder', 'repository_elisfiles'));
        $mform->addElement('static', 'root_folder_intro', '', get_string('elis_files_root_folder', 'repository_elisfiles'));

        // Cache time is retrieved from the common cache time and displayed here
        $mform->addElement('text', 'cache_time', get_string('cachetime', 'repository_elisfiles'), array('size' => '10'));
        $mform->addElement('static', 'cache_time_default', '', get_string('elis_files_default_cache_time', 'repository_elisfiles'));
        $mform->setDefault('cache_time', $CFG->repositorycacheexpire);
        $mform->setType('cache_time', PARAM_INT);
        $mform->freeze('cache_time');

        // Generate the list of options for choosing a quota limit size.
        $bytes_1mb = 1048576;

        $sizelist = array(
            -1,
            '',
            $bytes_1mb * 10,
            $bytes_1mb * 20,
            $bytes_1mb * 30,
            $bytes_1mb * 40,
            $bytes_1mb * 50,
            $bytes_1mb * 100,
            $bytes_1mb * 200,
            $bytes_1mb * 500
        );

        foreach ($sizelist as $sizebytes) {
            if ($sizebytes == '') {
                $filesize[$sizebytes] = get_string('quotanotset', 'repository_elisfiles');;
            } else if ($sizebytes == -1 ) {
                $filesize[$sizebytes] = get_string('quotaunlimited', 'repository_elisfiles');
            } else {
                $filesize[$sizebytes] = display_size($sizebytes);
            }
        }

        krsort($filesize, SORT_NUMERIC);

        $mform->addElement('select', 'user_quota', get_string('userquota', 'repository_elisfiles'), $filesize);
        $mform->setDefault('user_quota', '');
        $mform->addElement('static', 'user_quota_default', '', get_string('elis_files_default_user_quota', 'repository_elisfiles'));
        $mform->addElement('static', 'user_quota_intro', '', get_string('configuserquota', 'repository_elisfiles'));

        // Add a toggle to control whether we will delete a user's home directory in Alfresco when their account is deleted.
        $options = array(1 => get_string('yes'), '' => get_string('no'));

        $mform->addElement('select', 'deleteuserdir', get_string('deleteuserdir', 'repository_elisfiles'), $options);
        $mform->setDefault('deleteuserdir', '');
        $mform->addElement('static', 'deleteuserdir_default', '', get_string('elis_files_default_deleteuserdir', 'repository_elisfiles'));
        $mform->addElement('static', 'deleteuserdir_intro', '', get_string('configdeleteuserdir', 'repository_elisfiles'));

        // Menu setting about choosing the default location where users will end up if they don't have a previous file
        // browsing location saved.
        $options = array(
            ELIS_FILES_BROWSE_SITE_FILES   => get_string('repositorysitefiles', 'repository_elisfiles'),
            ELIS_FILES_BROWSE_COURSE_FILES => get_string('repositorycoursefiles', 'repository_elisfiles'),
            ELIS_FILES_BROWSE_USER_FILES   => get_string('repositoryuserfiles', 'repository_elisfiles'),
            ELIS_FILES_BROWSE_SHARED_FILES => get_string('repositorysharedfiles', 'repository_elisfiles')
        );

        $mform->addElement('select', 'default_browse', get_string('defaultfilebrowsinglocation', 'repository_elisfiles'), $options);
        $mform->setDefault('default_browse', ELIS_FILES_BROWSE_USER_FILES);
        $mform->addElement('static', 'default_browse_default', '', get_string('elis_files_default_default_browse', 'repository_elisfiles'));
        $mform->addElement('static', 'default_browse_intro', '', get_string('configdefaultfilebrowsinglocation', 'repository_elisfiles'));

        // Display menu option about overriding the Moodle 'admin' account when creating an Alfresco user account.

        // Check for the existence of a user that will conflict with the default Alfresco administrator account.
        $hasadmin = $DB->record_exists('user', array('username'   => 'admin',
                                                     'mnethostid' => $CFG->mnet_localhost_id));

        $admin_username = trim(get_config('elisfiles', 'admin_username'));
        if (empty($admin_username)) {
            $adminusername = '******';
            set_config('admin_username', $adminusername, 'elisfiles');
        } else {
            $adminusername = $admin_username;
        }

        // Only proceed here if the Alfresco plug-in is actually enabled.
        if (self::is_repo_visible('elisfiles')) {
            if ($repo = repository_factory::factory()) {
                if (elis_files_get_home_directory($adminusername) == false) {
                    $mform->addElement('text', 'admin_username', get_string('adminusername', 'repository_elisfiles'), array('size' => '30'));
                    $mform->setType('admin_username', PARAM_TEXT);
                    $mform->addElement('static', 'admin_username_default', '', get_string('elis_files_default_admin_username', 'repository_elisfiles'));
                    $mform->addElement('static', 'admin_username_intro', '', get_string('configadminusername', 'repository_elisfiles'));
                } else {
                    // Added to prevent an empty value from being stored in the database on form submit
                    $mform->addElement('hidden', 'admin_username', $adminusername);
                    $mform->setType('admin_username', PARAM_TEXT);

                    // An Alfresco account with the specified username has been created, check if a Moodle account exists with that
                    // username and display a warning if that is the case.
                    if (($userid = $DB->get_field('user', 'id', array('username'=> $adminusername, 'mnethostid'=> $CFG->mnet_localhost_id))) !== false) {
                        $a = new stdClass;
                        $a->username = $adminusername;
                        $a->url      = $CFG->wwwroot . '/user/editadvanced.php?id=' . $userid . '&amp;course=' . SITEID;

                        $mform->addElement('static', 'admin_username_intro', get_string('adminusername', 'repository_elisfiles'),
                                           get_string('configadminusernameconflict', 'repository_elisfiles', $a));
                    } else {
                        $mform->addElement('static', 'admin_username_intro', get_string('adminusername', 'repository_elisfiles'),
                                           get_string('configadminusernameset', 'repository_elisfiles', $adminusername));
                    }
                }
            }

            // Attmept to detect users in the system that are authenticated with a plug-in that does not use passwords and display
            // a message indicating the script that can be run to do a bulk synchronise of these users.
            $auths = elis_files_nopasswd_auths();

            if (!empty($auths) && count($auths) > 0) {
                $select = '';
                $params = array();

                if (count($auths) == 1) {
                    $select          = 'auth = :auth1';
                    $params['auth1'] = current($auths);
                } else {
                    $selects = array();

                    for ($i = 1; $i <= count($auths); $i++) {
                        $selects[]        .= ':auth'.$i;
                        $params['auth'.$i] = $auths[$i - 1];
                    }

                    $select = 'auth IN ('.implode(', ', $selects).')';
                }

                $select       .= ' AND deleted = :del';
                $params['del'] = 0;

                if ($DB->record_exists_select('user', $select, $params)) {
                    $mform->addElement('html', '<br />');
                    $mform->addElement('html', '<dl class="healthissues notice"><dt>'.get_string('passwordlessusersync', 'repository_elisfiles').
                                    '</dt> <dd>'.get_string('configpasswordlessusersync', 'repository_elisfiles').'</dd></dl>');
                }
            }
        }

        return true;
    }
Beispiel #2
0
require_once(dirname(__FILE__).'/../../config.php');
require_once($CFG->dirroot.'/repository/elisfiles/ELIS_files_factory.class.php');


$repo = repository_factory::factory('elisfiles');

if (!$repo) {
    mtrace(get_string('couldnotinitializerepository', 'repository_elisfiles'));
    exit;
}

set_time_limit(0);  // This may take a long time.

$errors = 0;
$auths = elis_files_nopasswd_auths();

if (empty($auths) || count($auths) === 0) {
    exit;
}

$select = '';
$params = array();

if (count($auths) == 1) {
    $select          = 'auth = :auth1';
    $params['auth1'] = current($auths);
} else {
    $selects = array();

    for ($i = 1; $i <= count($auths); $i++) {
Beispiel #3
0
 function get_content()
 {
     global $CFG, $USER;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->text = '';
     $this->content->footer = '';
     $content = '';
     $footer = '';
     $nologin_auths = elis_files_nopasswd_auths();
     if (!empty($USER->auth) && in_array($USER->auth, $nologin_auths)) {
         return '';
     }
     // Only proceed here if the Alfresco plug-in is actually enabled.
     if (!isloggedin() || !file_exists($CFG->dirroot . '/repository/elisfiles/ELIS_files_factory.class.php')) {
         return $this->content;
     }
     require_once $CFG->dirroot . '/repository/elisfiles/ELIS_files_factory.class.php';
     if (!($repo = repository_factory::factory())) {
         return $this->content;
     }
     // Get the ELIS Files plugin configuration values
     $pcfg = get_config('elisfiles');
     $username = $USER->username == 'admin' ? $pcfg->admin_username : $USER->username;
     $username = $repo->alfresco_username_fix($username);
     $repo->set_alfresco_username($username);
     if ($repo->elis_files_userdir($username) !== false) {
         // So that we don't conflict with the default Alfresco admin account.
         //            $username = $USER->username == 'admin' ? $pcfg->admin_username : $USER->username;
         $hastenant = false;
         // If the Moodle user's user name has an '@' symbol, then replace it with '_AT_' for Alfresco compatibility
         if (($tenantname = strpos($USER->username, '@')) > 0) {
             $username = $repo->get_alfresco_username_fix();
         }
         // We must include the tenant portion of the username here.
         if (($tenantname = strpos(elis::$config->elisfiles->server_username, '@')) > 0) {
             $username .= substr(elis::$config->elisfiles->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', context_system::instance())) {
         $url = $CFG->wwwroot . '/admin/repository.php?action=edit&amp;repos=elisfiles&amp;sesskey=' . sesskey();
         $content = get_string('alfresconotconfigured', 'block_repository', $url);
     }
     $this->content->text = $content;
     $this->content->footer = $footer;
     return $this->content;
 }
Beispiel #4
0
/**
 * ELIS(TM): Enterprise Learning Intelligence Suite
 * Copyright (C) 2014 onwards Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    repository_elisfiles
 * @author     Remote-Learner.net Inc
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 * @copyright  (C) 2008-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
 *
 */

function xmldb_repository_elisfiles_install() {
    global $CFG, $DB;

    $result = true;
    $dbman = $DB->get_manager();

    // Run upgrade steps from old plugin if applicable
    $oldversion = get_config('repository_elis_files', 'version');
    if ($oldversion !== false) {
        require_once($CFG->dirroot.'/repository/elisfiles/lib/lib.php');

        if ($oldversion < 2011110301) {
            $errors = false;
            $auths = elis_files_nopasswd_auths();
            $authlist = "'". implode("', '", $auths) ."'";
            $users = $DB->get_records_select('user', "auth IN ({$authlist})", array(), 'id, auth');
            if (!empty($users)) {
                foreach ($users as $user) {
                    $user = get_complete_user_data('id', $user->id);
                    $migrate_ok = elis_files_user_created($user);
                    if (!$migrate_ok) {
                        $errors = true;
                        // error_log("xmldb_block_elis_files_upgrade({$oldversion}) - failed migrating user ({$user->id}) to Alfresco.");
                    }
                }
            }
            if (!$errors) {
                set_config('initialized', 1, ELIS_files::$plugin_name);
            }
        }

        if ($result && $oldversion < 2012042300) {
            //check that elis_files_organization_store exists and repository_elisfiles_userset does not exist
            if ($dbman->table_exists('elis_files_organization_store') && !$dbman->table_exists('elis_files_userset_store')) {

                $original_table = new xmldb_table('elis_files_organization_store');

                //rename table
                $dbman->rename_table($original_table, 'elis_files_userset_store');
                $new_table = new xmldb_table('elis_files_userset_store');

                //drop the keys
                $original_uuid_index = new xmldb_index('elisfileorgastor_orguu_uix', XMLDB_INDEX_UNIQUE, array('organizationid', 'uuid'));
                $original_index = new xmldb_index('elisfileorgastor_org_ix', XMLDB_INDEX_NOTUNIQUE, array('organizationid'));
                $dbman->drop_index($new_table, $original_uuid_index);
                $dbman->drop_index($new_table, $original_index);

                //rename field
                $organization = new xmldb_field('organizationid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
                $dbman->rename_field($new_table, $organization, 'usersetid');

                //add the keys
                $new_uuid_index = new xmldb_index('elisfileuserstor_useuu_uix', XMLDB_INDEX_UNIQUE, array('usersetid', 'uuid'));
                $new_index = new xmldb_index('elisfileuserstor_use_ix', XMLDB_INDEX_NOTUNIQUE, array('usersetid'));
                $dbman->add_index($new_table, $new_uuid_index);
                $dbman->add_index($new_table, $new_index);
            }
        }

        if ($result && $oldversion < 2012042500) {
            defined('ELIS_FILES_BROWSE_USERSET_FILES') or define('ELIS_FILES_BROWSE_USERSET_FILES',   60);

            // ELIS-4676 ELIS UserSet Files is no longer valid, so change to default of ELIS User Files
            $select = "plugin = 'elis_files' AND name = 'default_browse'";

            if ($record = $DB->get_record_select('config_plugins', $select)) {
                require_once($CFG->dirroot.'/repository/elisfiles/lib/ELIS_files.php');
                $int_value = (int)$record->value;
                $valid_values = array(
                        ELIS_FILES_BROWSE_SITE_FILES,
                        ELIS_FILES_BROWSE_SHARED_FILES,
                        ELIS_FILES_BROWSE_COURSE_FILES,
                        ELIS_FILES_BROWSE_USER_FILES
                );
                if (!in_array($int_value, $valid_values)) {
                    $record->value = ELIS_FILES_BROWSE_USER_FILES;
                    $DB->update_record('config_plugins', $record);
                }
            }
        }

        if ($result && $oldversion < 2012050200)  {
            // Check for any plug-in settings using an incorrect plug-in name "ELIS_files" instead of "elis_files"
            if ($pcfgs = $DB->get_records('config_plugins', array('plugin' => 'ELIS_files'))) {
                foreach ($pcfgs as $pcfg) {
                    $pcfg->plugin = 'elis_files';
                    $DB->update_record('config_plugins', $pcfg);
                }
            }
        }

        /*
         * This upgrade step removes any possible stale data in the repository_elisfiles_userset and
         * repository_elisfiles_course that not longer have relevant courses or user sets
         */
        if ($result && $oldversion < 2012083000)  {
            $haveuserset = false;
            if (file_exists($CFG->dirroot.'/local/elisprogram/lib/data/userset.class.php')) {
                require_once($CFG->dirroot.'/local/elisprogram/lib/data/userset.class.php');
                $haveuserset = $dbman->table_exists(userset::TABLE);
            }

            $sql = 'DELETE FROM {elis_files_userset_store}';
            if ($haveuserset) {
                $sql .= ' WHERE NOT EXISTS (SELECT *
                                              FROM {'.userset::TABLE.'}
                                             WHERE {elis_files_userset_store}.usersetid = {'.userset::TABLE.'}.id)';

            }
            $DB->execute($sql);

            $sql = 'DELETE FROM {elis_files_course_store}
                    WHERE NOT EXISTS (SELECT *
                                        FROM {course}
                                       WHERE {elis_files_course_store}.courseid = {course}.id)';

            $DB->execute($sql);
        }

        /*
         * This upgrade step removes backslashes from category titles in the repository_elisfiles_cats
         */
        if ($result && $oldversion < 2012090400)  {
            require_once($CFG->dirroot.'/repository/elisfiles/ELIS_files_factory.class.php');
            // Initialize the repo object.
            $repo = repository_factory::factory();
            $table = 'elis_files_categories';
            if ($repo && $dbman->table_exists($table) && $categories = elis_files_get_categories()) {
                $DB->delete_records($table);

                // Perform the back-end category refresh
                $categories = elis_files_get_categories();
                $uuids = array();
                $repo->process_categories($uuids, $categories);
            }
        }

        // If the pre-ELIS 2 Alfresco plugin was present and enabled on this site, then we need to automatically
        // enable the ELIS Files plugin
        $select1 = "name = 'repository' AND ".$DB->sql_compare_text('value')." = 'alfresco'";
        $select2 = "name = 'repository_plugins_enabled' AND ".$DB->sql_compare_text('value')." = 'alfresco'";

        if ($DB->record_exists_select('config', $select1) && $DB->record_exists_select('config', $select2)) {
            require_once($CFG->dirroot.'/repository/lib.php');

            $elis_files = new repository_type('elisfiles', array(), true);

            if (!empty($elis_files)) {
                $elis_files->update_visibility(true);
                $elis_files->create();
            }

            $DB->delete_records_select('config', "(name = 'repository' OR name = 'repository_plugins_enabled')");
        }

        // ELIS-3677, ELIS-3802 Moodle files is no longer valid, so change to default of ELIS User Files
        $select = "plugin = 'elis_files' AND name = 'default_browse'";

        if ($record = $DB->get_record_select('config_plugins', $select)) {
            require_once($CFG->dirroot.'/repository/elisfiles/lib/ELIS_files.php');
            $int_value = (int)$record->value;
            $valid_values = array(
                    ELIS_FILES_BROWSE_SITE_FILES,
                    ELIS_FILES_BROWSE_SHARED_FILES,
                    ELIS_FILES_BROWSE_COURSE_FILES,
                    ELIS_FILES_BROWSE_USER_FILES
            );
            if (!in_array($int_value, $valid_values)) {
                $record->value = ELIS_FILES_BROWSE_USER_FILES;
                $DB->update_record('config_plugins', $record);
            }
        }

        $ignoreresult = elis_files_update_references_in_database();
    }

    // Convert old tables to new
    static $tablemap = array(
        'elis_files_categories'    => 'repository_elisfiles_cats',
        'elis_files_course_store'  => 'repository_elisfiles_course',
        'elis_files_userset_store' => 'repository_elisfiles_userset'
    );
    foreach ($tablemap as $oldtable => $newtable) {
        $oldtableobj = new xmldb_table($oldtable);
        if ($dbman->table_exists($oldtableobj)) {
            $newtableobj = new xmldb_table($newtable);
            $dbman->drop_table($newtableobj);
            $dbman->rename_table($oldtableobj, $newtable);
        }
    }

    // Migrate capabilities
    $oldcapprefix = 'repository/elis_files';
    $newcapprefix = 'repository/elisfiles';
    $sql = 'SELECT * FROM {role_capabilities} WHERE capability LIKE ?';
    $params = array($oldcapprefix.'%');
    $rolecaps = $DB->get_recordset_sql($sql, $params);
    foreach ($rolecaps as $rolecaprec) {
        $updaterec = new stdClass;
        $updaterec->id = $rolecaprec->id;
        $updaterec->capability = str_replace($oldcapprefix, $newcapprefix, $rolecaprec->capability);
        $DB->update_record('role_capabilities', $updaterec);
    }
    $sql = 'SELECT * FROM {capabilities} WHERE name LIKE ?';
    $caps = $DB->get_recordset_sql($sql, $params);
    foreach ($caps as $cap) {
        $cap->name = str_replace($oldcapprefix, $newcapprefix, $cap->name);
        $cap->component = str_replace('repository_elis_files', 'repository_elisfiles', $cap->component);
        $DB->update_record('capabilities', $cap);
    }

    // Migrate language strings
    $migrator = new \local_eliscore\install\migration\migrator('repository_elis_files', 'repository_elisfiles');
    $migrator->migrate_language_strings();

    // Copy any settings from old plugin
    $oldconfig = get_config('elis_files');
    foreach ($oldconfig as $name => $value) {
        set_config($name, $value, 'elisfiles');
    }
    unset_all_config_for_plugin('elis_files');
    unset_all_config_for_plugin('repository_elis_files');

    // Update repository table
    $sql = 'UPDATE {repository} SET type = "elisfiles" WHERE type = "elis_files"';
    $DB->execute($sql);

    return $result;
}
Beispiel #5
0
/**
 * 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 elis_files_user_created($user) {
    global $CFG;

    // Only proceed here if the Alfresco plug-in is actually enabled.
    if (!($repo = repository_factory::factory('elisfiles')) || !$repo->is_configured() || !$repo->verify_setup()) {
        //error_log("elis_files_user_created(): Alfresco NOT enabled!");
    } else {
        // create a random password for certain authentications
        $auths = elis_files_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("elis_files_user_created(): generating password for {$user->id} ({$user->auth}) => {$passwd}");
            $repo->migrate_user($user, $passwd);
        }
    }

    return true;
}