Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
    /**
     * 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);
                }
            }
        }
    }
Ejemplo n.º 3
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);
    }
Ejemplo n.º 4
0
    public function get_folder_listing($encodedpath, $cid = SITEID, $uid = 0, $shared = 0, $oid = 0) {
        global $COURSE, $OUTPUT, $USER;

    // Decode path and retrieve parameters
        if (!empty($encodedpath)) {
            $params = unserialize(base64_decode($encodedpath));
            if (is_array($params)) {
                $uuid    = empty($params['path']) ? NULL : clean_param($params['path'], PARAM_PATH);
                $shared  = empty($params['shared']) ? 0 : clean_param($params['shared'], PARAM_BOOL);
                $oid     = empty($params['oid']) ? 0 : clean_param($params['oid'], PARAM_INT);
                $cid     = empty($params['cid']) ? 0 : clean_param($params['cid'], PARAM_INT);
                $uid     = empty($params['uid']) ? 0 : clean_param($params['uid'], PARAM_INT);
            }
        } else {
            $uuid = NULL;
            $shared = 0;
            $oid = 0;
            $cid = 0;
            $uid = 0;
        }
        $children = elis_files_read_dir($uuid);
        $return = array();

        foreach ($children->folders as $child) {
            if (!$this->elis_files->permission_check($child->uuid, $USER->id, false)) {
                continue;
            }
//            $params = array('path'=>$child->uuid,
//                             'shared'=>(boolean)$shared,
//                             'oid'=>(int)$oid,
//                             'cid'=>(int)$cid,
//                             'uid'=>(int)$uid);
//            $encodedpath = base64_encode(serialize($params));
            $return[] = array('title'=>$child->title,
                    'path'      => repository_elisfiles::build_encodedpath($child->uuid, $uid, $cid, $oid, $shared),
                    'name'      => $child->title,
                    'thumbnail' => $OUTPUT->pix_url('f/folder-32') . '',
                    'created'   => '',
                    'modified'  => '',
                    'owner'     => !empty($child->owner) ? $child->owner : '',
                    'children'  => array());
        }
        return $return;
    }
Ejemplo n.º 5
0
/**
 * Get the UUID value of the web scripts extension directory.
 *
 * The path is as follows /Data Dictionary/Web Scripts Extensions/
 *
 * @param bool $moodle Whether to get the UUID of the Moodle web scripts folder (optional)
 * @return string|bool The node UUID value on succes, False otherwise.
 */
function elis_files_get_web_scripts_dir($moodle = false) {
    $dir = elis_files_read_dir();

    if (empty($dir->folders)) {
        return false;
    }

    foreach ($dir->folders as $folder) {
        if ($folder->title == 'Data Dictionary') {
            $dir = elis_files_read_dir($folder->uuid);

            if (empty($dir->folders)) {
                return false;
            }

            foreach ($dir->folders as $folder) {
                if ($folder->title == 'Web Scripts Extensions') {
                    if (!$moodle) {
                        return $folder->uuid;
                    }

                    $dir = elis_files_read_dir($folder->uuid);

                    if (empty($dir->folders)) {
                        return false;
                    }

                    foreach ($dir->folders as $folder) {
                        if ($folder->title == 'org') {
                            $dir = elis_files_read_dir($folder->uuid);

                            if (empty($dir->folders)) {
                                return false;
                            }

                            foreach ($dir->folders as $folder) {
                                if ($folder->title == 'alfresco') {
                                    $dir = elis_files_read_dir($folder->uuid);

                                    if (empty($dir->folders)) {
                                        return false;
                                    }

                                    foreach ($dir->folders as $folder) {
                                        if ($folder->title == 'moodle') {
                                            debugging('Returning UUID for ' . $folder->title . ': ' . $folder->uuid);
                                            return $folder->uuid;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return false;
}
Ejemplo n.º 6
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 7
0
/**
 * Read a directory from the repository server.
 *
 * @param string $uuid     Unique identifier for a node.
 * @param bool   $useadmin Set to false to make sure that the administrative user configured in
 *                         the plug-in is not used for this operation (default: true).
 * @return object|bool An object representing the layout of the directory or
 *                     False on failure.
 */
    function read_dir($uuid = '', $useadmin = true) {
        if (ELIS_FILES_DEBUG_TRACE) mtrace('read_dir(' . $uuid . ', ' . ($useadmin !== true ? 'false' : 'true') . ')');

        if (!$this->get_defaults()) {
            return false;
        }

        if (self::is_version('3.2')) {
            return elis_files_read_dir($uuid, $useadmin);
        } else if (self::is_version('3.4')) {
            if (empty($uuid)) {
                if ($root = $this->get_root()) {
                    $uuid = $root->uuid;
                }
            }

            if (!($result = $this->cmis->getChildren('workspace://SpacesStore/' . $uuid))) {
                return false;
            }

            $return = new stdClass;
            $return->folders = array();
            $return->files   = array();

            foreach ($result->objectsById as $child) {
                $type = '';

                $node =  elis_files_process_node_new($child, $type);

                if ($type == self::$type_folder) {
                    $return->folders[] = $node;
                    // Only include a file in the list if it's title does not start with a period '.'
                    } else if ($type == self::$type_document && !empty($node->title) && $node->title[0] !== '.') {
                    $return->files[] = $node;
                }
            }

            return $return;
        }
    }
Ejemplo n.º 8
0
    /**
     * 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();
    }