community.egroupware.org: Community wiki

  
Community wiki
Sql FS

SQL FS

SQL File System (Files stored in the database)
SqlFS uses the php pdo interface to access blobs of all possible databases via stream reading/writing (you need to install the pdo extension for php)

Class

  • sqlfs_stream_wrapper
A new way to store files in the database.
  • eGroupWare API: VFS - new DB based VFS stream wrapper

  • The sqlfs stream wrapper has 3 operation modi:
    • content of files is stored in the filesystem (eGW's files_dir) (default)
    • content of files is stored as BLOB in the DB
    • content of files is versioned (and stored in the DB) NOT YET IMPLEMENTED
  • In the future it will be possible to activate eg. versioning in parts of the filesystem, via mount options in the vfs
  • It uses the PDO DB interface, as it allows to access BLOB's as streams (avoiding to hold them complete in memory)
  • The interface is according to the docu on php.net

Database Table

                'egw_sqlfs' => array(
                        'fd' => array(
                                'fs_id' => array('type' => 'auto','nullable' => False),
                                'fs_dir' => array('type' => 'int','precision' => '4','nullable' => False),
                                'fs_name' => array('type' => 'varchar','precision' => '200','nullable' => False),
                                'fs_mode' => array('type' => 'int','precision' => '2','nullable' => False),
                                'fs_uid' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
                                'fs_gid' => array('type' => 'int','precision' => '4','nullable' => False,'default' => '0'),
                                'fs_created' => array('type' => 'timestamp','precision' => '8','nullable' => False ,'default' => 'current_timestamp'),
                                'fs_modified' => array('type' => 'timestamp','precision' => '8','nullable' => False),
                                'fs_mime' => array('type' => 'varchar','precision' => '64','nullable' => False),
                                'fs_size' => array('type' => 'int','precision' => '8','nullable' => False),
                                'fs_creator' => array('type' => 'int','precision' => '4','nullable' => False),
                                'fs_modifier' => array('type' => 'int','precision' => '4'),
                                'fs_active' => array('type' => 'bool','nullable' => False,'default' => 't'),
                                'fs_comment' => array('type' => 'varchar','precision' => '255'),
                                'fs_content' => array('type' => 'blob')
                        ),
                        'pk' => array('fs_id'),
                        'fk' => array(),
                        'ix' => array(array('fs_dir','fs_active','fs_name')),
                        'uc' => array()
                )


Access rights

The function url_stat employs a _sql_readable check to ensure accessability of the URL and its childs retrieved
        /**
         * This method (url_stat) is called in response to stat() calls on the URL paths associated with the wrapper.
         *
         * It should return as many elements in common with the system function as possible.
         * Unknown or unavailable values should be set to a rational value (usually 0).
         *
         * If you plan to use your wrapper in a require_once you need to define stream_stat().
         * If you plan to allow any other tests like is_file()/is_dir(), you have to define url_stat().
         * stream_stat() must define the size of the file, or it will never be included.
         * url_stat() must define mode, or is_file()/is_dir()/is_executable(), and any of those functions affected by clearstatcache() simply won't work.
         * It's not documented, but directories must be a mode like 040777 (octal), and files a mode like 0100666.
         * If you wish the file to be executable, use 7s instead of 6s.
         * The last 3 digits are exactly the same thing as what you pass to chmod.
         * 040000 defines a directory, and 0100000 defines a file. 
         *
         * @param string $path
         * @param int $flags holds additional flags set by the streams API. It can hold one or more of the following values OR'd together:
         * - STREAM_URL_STAT_LINK       For resources with the ability to link to other resource (such as an HTTP Location: forward,
         *                          or a filesystem symlink). This flag specified that only information about the link itself should be returned,
         *                          not the resource pointed to by the link.
         *                          This flag is set in response to calls to lstat(), is_link(), or filetype().
         * - STREAM_URL_STAT_QUIET      If this flag is set, your wrapper should not raise any errors. If this flag is not set,
         *                          you are responsible for reporting errors using the trigger_error() function during stating of the path.
         *                          stat triggers it's own warning anyway, so it makes no sense to trigger one by our stream-wrapper!
         * @return array
         */
 

        /**
         * Return readable check as sql (to be AND'ed into the query), only use if !egw_vfs::$is_root
         *
         * @return string
         */
        private function _sql_readable()
        {
                static $sql_read_acl;

                if (is_null($sql_read_acl))
                {
                        foreach($GLOBALS['egw']->accounts->memberships(egw_vfs::$user,true) as $gid)
                        {
                                $memberships[] = abs($gid);     // sqlfs stores the gid's positiv
                        }
                        // checks for other rights (04), user rights (0400) or grouprights (040)
                        $sql_read_acl = '(fs_mode & 04 OR (fs_mode & 0400 AND fs_uid='.(int)egw_vfs::$user.')'.
                                ' OR (fs_mode & 040 AND fs_gid IN('.implode(',',$memberships).')))';
                }
                return $sql_read_acl;
        }

You are here