/** * 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 * @param none * @return bool True if setup, False otherwise. */ function verify_setup() { global $CFG, $DB, $USER; if (ELIS_FILES_DEBUG_TRACE) mtrace('verify_setup()'); if (!$this->get_defaults()) { return false; } if (self::is_version('3.2')) { if (!elis_files_get_services()) { return false; } // Set up the root node $response = elis_files_request(elis_files_get_uri('', 'sites')); $response = preg_replace('/(&[^amp;])+/', '&', $response); $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->loadXML($response); $nodes = $dom->getElementsByTagName('entry'); $type = ''; $this->root = elis_files_process_node($dom, $nodes->item(0), $type); } else if (self::is_version('3.4')) { if (empty($this->cmis)) { $this->cmis = new CMISService(elis_files_base_url() . '/api/cmis', $this->config->server_username, $this->config->server_password); if (empty($this->cmis->authenticated)) { return false; } if (!$root = $this->cmis->getObjectByPath('/')) { return false; } $type = ''; $this->root = elis_files_process_node_new($root, $type); } } // If there is no root folder saved or it's set to default, // make sure there is a default '/moodle' folder. if (empty($this->config->root_folder) || ($this->config->root_folder == '/moodle')) { $root = $this->get_root(); if ($root == false || !isset($root->uuid)) { return false; } $dir = $this->read_dir($root->uuid, true); if (!empty($dir->folders)) { foreach ($dir->folders as $folder) { if ($folder->title == 'moodle') { $muuid = $folder->uuid; } } } // Create the main Moodle directory. if (empty($muuid)) { $muuid = $this->create_dir('moodle', $root->uuid, '', true); if ($muuid === false) { return false; } } if (empty($muuid)) { debugging(get_string('invalidpath', 'repository_elisfiles')); return false; } $this->muuid = $muuid; $this->node_inherit($muuid, false); // Otherwise, use the folder that the plug-in has been configured with. } else { if (!$uuid = elis_files_uuid_from_path($this->config->root_folder)) { debugging(get_string('invalidpath', 'repository_elisfiles')); return false; } $this->muuid = $uuid; $this->node_inherit($uuid, false); } // Attempt to find the UUID of the main storage folders within the "moodle" folder. $dir = $this->read_dir($this->muuid, true); if (!empty($dir->folders)) { foreach ($dir->folders as $folder) { if ($folder->title == 'shared') { $this->suuid = $folder->uuid; } else if ($folder->title == 'course') { $this->cuuid = $folder->uuid; } else if ($folder->title == 'userset') { $this->ouuid = $folder->uuid; } } } // Attemping to find the UUID of any storage folders within the top-level folder. $dir = $this->read_dir($this->root->uuid); if (!empty($dir->folders)) { foreach ($dir->folders as $folder) { if ($folder->title == 'User Homes') { $this->uhomesuid = $folder->uuid; } } } // Create the shared storage directory. if (empty($this->suuid)) { $suuid = $this->create_dir('shared', $this->muuid, true); if ($suuid === false) { return false; } $this->suuid = $suuid; $this->node_inherit($suuid, false); } // Create the course space directory. if (empty($this->cuuid)) { $cuuid = $this->create_dir('course', $this->muuid, true); if ($cuuid === false) { return false; } $this->cuuid = $cuuid; $this->node_inherit($cuuid, false); } // Create the userset shared storage directory. if (empty($this->ouuid)) { $ouuid = $this->create_dir('userset', $this->muuid, true); if ($ouuid === false) { return false; } $this->ouuid = $ouuid; $this->node_inherit($ouuid, false); } // We no longer will automatically create the course space directory as it's no longer needed. // Make sure the temp directory is enabled. if (!is_dir($CFG->dataroot . '/temp/alfresco')) { mkdir($CFG->dataroot . '/temp/alfresco', $CFG->directorypermissions, true); } if ($username = $DB->get_field('user', 'username', array('id' => $USER->id))) { //mtrace("ELIS_files::verify_setup(): username = {$username}\n"); $this->uuuid = elis_files_get_home_directory($username); //error_log("verify_setup:: elis_files_get_home_directory({$username}) = {$this->uuuid}"); } return true; }
/** * Return service url for ticket based authentication. * $op Option for refreshing ticket or not. * @param string $username The username to use for user authentication. */ function elis_files_utils_get_wc_url($url, $op = 'norefresh', $username = '') { $endpoint = elis_files_base_url(); $ticket = elis_files_utils_get_ticket($op, $username); if (false === strstr($url, '?') ) { return $endpoint . $url . '?alf_ticket=' . $ticket; } else { return $endpoint . str_replace('?', '?alf_ticket=' . $ticket . '&', $url); } }
/** * Test the elis_files_process_node function with links. * @dataProvider nodelink_fields_provider * @param string $field a node property * @param string $field2 a node property */ public function test_process_node_links($field1, $field2) { $dom = $this->load_folder_dom_from_xml(); $nodes = $dom->getElementsByTagName('entry'); foreach ($nodes as $node) { $value = ''; $links = $node->getElementsByTagName('link'); foreach ($links as $link) { if ($link->getAttribute('rel') === $field1) { $value = str_replace(elis_files_base_url(), '', $link->getAttribute('href')); break; } } } $contentnode = elis_files_process_node($dom, $nodes->item(0), $type); $this->assertEquals($value, $contentnode->links[$field2]); }