Esempio n. 1
0
    /**
     * Validate that the "migrate_all_users" method correctly deletes legacy
     * @uses $CFG, $DB
     * numeric user directories
     */
    public function test_migrate_all_users_handles_deleted_users() {
        $this->resetAfterTest(true);
        $this->setup_test_data_xml();

        global $CFG, $DB;

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

        // Our test username
        $username = '******';

        // Set up the user in Alfresco
        $elisfiles = new ELIS_files();
        $elisfiles->migrate_user($username);

        // Validate that the user exists and that their home directory was set up
        // (for sanity reasons only)
        $userexists = elis_files_request('/api/people/'.$username);
        $this->assertNotEquals(false, $userexists);

        $initialuserhome = elis_files_get_home_directory($username);
        $this->assertNotEquals(false, $initialuserhome);

        // Change the node name to the "old" style
        $test = elis_files_node_rename($initialuserhome, '100');

        // Run the migration method
        $usr = new stdClass();
        $usr->id = 100;
        $usr->deleted = 1;
        $DB->update_record('user', $usr);

        $elisfiles->migrate_all_users();

        // Validate cleanup for the legacy folder
        $legacyuuid = false;
        $dir = elis_files_read_dir($elisfiles->uhomesuid, true);
        foreach ($dir->folders as $folder) {
            if ($folder->title == '100') {
                $legacyuuid = $folder->uuid;
            }
        }

        // Clean up the non-legacy data before final validation
        $elisfiles->delete_user($username);

        $this->assertEquals(false, $legacyuuid);
    }
Esempio n. 2
0
/**
 * Recursively builds a dynamic tree menu for seleting the categories available to
 * filter search results by.
 *
 * @param array $cats     An array of category objects from the DB.
 * @param array $selected An array of currently selected category IDs.
 * @return array An array of completed HTML_TreeMenu nodes.
 */
function elis_files_make_category_select_tree_choose($cats, $selected = array()) {
    global $CFG;
    global $repo;
    static $catlist;

    if (empty($cats)) {
        return;
    }

    if (!isset($catlist)) {
        $catlist = elis_files_make_category_tree();
    }

    $icon  = 'folder.gif';
    $eicon = 'folder-expanded.gif';
    $nodes = array();

    for ($i = 0; $i < count($cats); $i++) {
        if (in_array($cats[$i]->id, $selected)) {
            $checked = ' checked';
        } else {
            $checked = '';
        }

        $text = '<input type="checkbox" name="categories[]" value="' . $cats[$i]->id . '"' . $checked .
                ' />' . $cats[$i]->title;

        if (array_key_exists($cats[$i]->id, $catlist)) {
            $expanded = true;
        } else {
            $expanded = false;
        }

        $node = new HTML_TreeNode(array(
            'text'         => $text,
            'icon'         => $icon,
            'expandedIcon' => $eicon,
            'expanded'     => $expanded
        ));

//            if ($children = $repo->category_get_children($cats[$i]->id)) {
        if ($children = ELIS_files::category_get_children($cats[$i]->id)) {
            if ($cnodes = elis_files_make_category_select_tree_choose($children, $selected)) {
                for ($j = 0; $j < count($cnodes); $j++) {
                    $node->addItem($cnodes[$j]);
                }
            }
        }

        $nodes[] = $node;
    }

    return $nodes;
}
Esempio n. 3
0
    function get_defaults() {
        // Initialize the alfresco version
        if (!(self::$version = elis_files_get_repository_version())) {
            return false;
        }

        // Set the file and folder type
        if (!isset(self::$type_document)) {
            if (self::is_version('3.2')) {
                self::$type_folder   = 'folder';
                self::$type_document = 'document';
            } else if (self::is_version('3.4')) {
                self::$type_folder   = 'cmis:folder';
                self::$type_document = 'cmis:document';
            }
        }

        return true;
    }
Esempio n. 4
0
/**
 * Function to transform Moodle username to Alfresco username
 * converting 'admin' user and adding tenant info.
 * Check to make sure username has NOT already been transformed
 *
 * @param  $username the username to transform
 * @uses   $CFG
 * @uses   $USER
 * @return string    the transformed username.
 */
function elis_files_transform_username($username) {
    global $CFG, $USER;

    $tenantpos = strpos(elis::$config->elisfiles->server_username, '@');
    if ($username == 'admin' || empty($USER->username) || $USER->username == $username ||
        (($atpos = strpos($username, '@')) !== false &&
          ($tenantpos === false ||
           strcmp(substr($username, $atpos),
                  substr(elis::$config->elisfiles->server_username, $tenantpos))))
       || ($atpos === false && $tenantpos !== false)) {

        // Fix username
        $username = ELIS_files::alfresco_username_fix($username);

        // So that we don't conflict with the default Alfresco admin account.
        $username = ($username == 'admin')
                    ? elis::$config->elisfiles->admin_username : $username;

        // We must include the tenant portion of the username here.
        if ($tenantpos > 0) {
            $username .= substr(elis::$config->elisfiles->server_username, $tenantpos);
        }
    }
    return $username;
}
Esempio n. 5
0
    /**
     * Verify that the Alfresco repository is currently setup and ready to be
     * used with Moodle (i.e. the needed directory structure is in place).
     *
     * @uses $CFG
     * @return bool True if setup, False otherwise.
     */
    public function verify_setup() {
        $valid_setup = parent::verify_setup();

        $this->cuuid = "mockcuuid";
        $this->ouuid = "mockouuid";
        $this->uuuid = "testuuid";
        $this->suuid = "mocksuuid";

        return $valid_setup;
    }