2012-06-15 21:56:15 +04:00
< ? php
/**
* Copyright ( c ) 2012 Robin Appelman < icewind @ owncloud . com >
* This file is licensed under the Affero General Public License version 3 or
* later .
* See the COPYING - README file .
*/
/**
* get data from the filecache without checking for updates
*/
class OC_FileCache_Cached {
public static $savedData = array ();
2012-08-29 10:38:33 +04:00
2012-11-02 22:53:02 +04:00
public static function get ( $path , $root = false ) {
2012-09-07 17:22:01 +04:00
if ( $root === false ) {
2012-06-15 21:56:15 +04:00
$root = OC_Filesystem :: getRoot ();
}
$path = $root . $path ;
2012-11-16 20:52:52 +04:00
$stmt = OC_DB :: prepare ( 'SELECT `id`, `path`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `path_hash`=?' );
2012-09-13 00:56:16 +04:00
if ( ! OC_DB :: isError ( $stmt ) ) {
$result = $stmt -> execute ( array ( md5 ( $path )));
if ( ! OC_DB :: isError ( $result ) ) {
$result = $result -> fetchRow ();
} else {
OC : Log :: write ( 'OC_FileCache_Cached' , 'could not execute get: ' . OC_DB :: getErrorMessage ( $result ), OC_Log :: ERROR );
$result = false ;
}
} else {
OC_Log :: write ( 'OC_FileCache_Cached' , 'could not prepare get: ' . OC_DB :: getErrorMessage ( $stmt ), OC_Log :: ERROR );
$result = false ;
}
2012-09-07 17:22:01 +04:00
if ( is_array ( $result )) {
if ( isset ( self :: $savedData [ $path ])) {
2012-09-10 13:32:49 +04:00
$result = array_merge ( $result , self :: $savedData [ $path ]);
2012-06-15 21:56:15 +04:00
}
return $result ;
} else {
2012-09-07 17:22:01 +04:00
if ( isset ( self :: $savedData [ $path ])) {
2012-06-15 21:56:15 +04:00
return self :: $savedData [ $path ];
} else {
return array ();
}
}
}
/**
* get all files and folders in a folder
* @ param string path
* @ param string root ( optional )
* @ return array
*
* returns an array of assiciative arrays with the following keys :
* - path
* - name
* - size
* - mtime
* - ctime
* - mimetype
* - encrypted
* - versioned
*/
2012-11-02 22:53:02 +04:00
public static function getFolderContent ( $path , $root = false , $mimetype_filter = '' ) {
2012-09-07 17:22:01 +04:00
if ( $root === false ) {
2012-06-15 21:56:15 +04:00
$root = OC_Filesystem :: getRoot ();
}
2012-09-10 13:32:49 +04:00
$parent = OC_FileCache :: getId ( $path , $root );
2012-09-07 17:22:01 +04:00
if ( $parent ==- 1 ) {
2012-06-20 13:34:17 +04:00
return array ();
}
2012-08-25 03:52:27 +04:00
$query = OC_DB :: prepare ( 'SELECT `id`,`path`,`name`,`ctime`,`mtime`,`mimetype`,`size`,`encrypted`,`versioned`,`writable` FROM `*PREFIX*fscache` WHERE `parent`=? AND (`mimetype` LIKE ? OR `mimetype` = ?)' );
2012-06-15 21:56:15 +04:00
$result = $query -> execute ( array ( $parent , $mimetype_filter . '%' , 'httpd/unix-directory' )) -> fetchAll ();
2012-09-07 17:22:01 +04:00
if ( is_array ( $result )) {
2012-06-15 21:56:15 +04:00
return $result ;
} else {
2012-09-10 13:32:49 +04:00
OC_Log :: write ( 'files' , 'getFolderContent(): file not found in cache (' . $path . ')' , OC_Log :: DEBUG );
2012-06-15 21:56:15 +04:00
return false ;
}
}
2012-11-16 20:52:52 +04:00
}