diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-06-16 09:35:57 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-06-16 09:35:57 +0200 |
commit | 14f6d4dcba0e4c0728bb9dc27f8d30787378cf40 (patch) | |
tree | eeb04897c077904e78c67edae08da730638bf0a1 /lib | |
parent | 2c8a61ae9c1437ded36ecba6eba5e1bc9d7e7948 (diff) | |
parent | bf2062b09d6c3a3d1c8b94b3612b6bb940aa5b79 (diff) | |
download | nextcloud-server-14f6d4dcba0e4c0728bb9dc27f8d30787378cf40.tar.gz nextcloud-server-14f6d4dcba0e4c0728bb9dc27f8d30787378cf40.zip |
Merge branch 'master' into oc_error
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 6 | ||||
-rw-r--r-- | lib/connector/sabre/directory.php | 32 | ||||
-rw-r--r-- | lib/connector/sabre/node.php | 44 | ||||
-rw-r--r-- | lib/filecache.php | 2 | ||||
-rw-r--r-- | lib/migrate.php | 40 |
5 files changed, 69 insertions, 55 deletions
diff --git a/lib/base.php b/lib/base.php index f85710ddfcf..fedc1238851 100644 --- a/lib/base.php +++ b/lib/base.php @@ -121,8 +121,7 @@ class OC{ } public static function initPaths(){ - // calculate the documentroot - $DOCUMENTROOT=realpath($_SERVER['DOCUMENT_ROOT']); + // calculate the root directories OC::$SERVERROOT=str_replace("\\",'/',substr(__FILE__,0,-13)); OC::$SUBURI= str_replace("\\","/",substr(realpath($_SERVER["SCRIPT_FILENAME"]),strlen(OC::$SERVERROOT))); $scriptName=$_SERVER["SCRIPT_NAME"]; @@ -137,9 +136,6 @@ class OC{ } } OC::$WEBROOT=substr($scriptName,0,strlen($scriptName)-strlen(OC::$SUBURI)); - // try a new way to detect the WEBROOT which is simpler and also works with the app directory outside the owncloud folder. let´s see if this works for everybody -// OC::$WEBROOT=substr(OC::$SERVERROOT,strlen($DOCUMENTROOT)); - if(OC::$WEBROOT!='' and OC::$WEBROOT[0]!=='/'){ OC::$WEBROOT='/'.OC::$WEBROOT; diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 5aa70392d76..9832449af3a 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -69,15 +69,13 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); if ($info['mimetype'] == 'httpd/unix-directory') { - - return new OC_Connector_Sabre_Directory($path, $info); - + $node = new OC_Connector_Sabre_Directory($path); } else { - - return new OC_Connector_Sabre_File($path, $info); - + $node = new OC_Connector_Sabre_File($path); } + $node->setFileinfoCache($info); + return $node; } /** @@ -87,10 +85,28 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getChildren() { - $nodes = array(); $folder_content = OC_FileCache::getFolderContent($this->path); + $paths = array(); + foreach($folder_content as $info) { + $paths[] = $this->path.'/'.$info['name']; + } + $placeholders = join(',', array_fill(0, count($paths), '?')); + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ?' . ' AND propertypath IN ('.$placeholders.')' ); + array_unshift($paths, OC_User::getUser()); // prepend userid + $result = $query->execute( $paths ); + $properties = array_fill_keys($paths, array()); + while($row = $result->fetchRow()) { + $propertypath = $row['propertypath']; + $propertyname = $row['propertyname']; + $propertyvalue = $row['propertyvalue']; + $properties[$propertypath][$propertyname] = $propertyvalue; + } + + $nodes = array(); foreach($folder_content as $info) { - $nodes[] = $this->getChild($info['name'], $info); + $node = $this->getChild($info['name'], $info); + $node->setPropertyCache($properties[$this->path.'/'.$info['name']]); + $nodes[] = $node; } return $nodes; } diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index e5c059f0c8a..be315a0ffd9 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -30,10 +30,15 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr */ protected $path; /** - * file stat cache + * node fileinfo cache * @var array */ protected $fileinfo_cache; + /** + * node properties cache + * @var array + */ + protected $property_cache = null; /** * Sets up the node, expects a full path name @@ -41,11 +46,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @param string $path * @return void */ - public function __construct($path, $fileinfo_cache = null) { + public function __construct($path) { $this->path = $path; - if ($fileinfo_cache) { - $this->fileinfo_cache = $fileinfo_cache; - } } @@ -85,8 +87,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } + public function setFileinfoCache($fileinfo_cache) + { + $this->fileinfo_cache = $fileinfo_cache; + } + /** - * Set the stat cache + * Make sure the fileinfo cache is filled. Uses OC_FileCache or a direct stat */ protected function getFileinfoCache() { if (!isset($this->fileinfo_cache)) { @@ -99,6 +106,11 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + public function setPropertyCache($property_cache) + { + $this->property_cache = $property_cache; + } + /** * Returns the last modification time, as a unix timestamp * @@ -137,7 +149,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } else { - if( strcmp( $propertyName, "lastmodified")) { + if( strcmp( $propertyName, "lastmodified") === 0) { $this->touch($propertyValue); } else { if(!array_key_exists( $propertyName, $existing )){ @@ -151,6 +163,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } + $this->setPropertyCache(null); return true; } @@ -166,23 +179,24 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * @return void */ function getProperties($properties) { - // At least some magic in here :-) - $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); - $result = $query->execute( array( OC_User::getUser(), $this->path )); + if (is_null($this->property_cache)) { + $query = OC_DB::prepare( 'SELECT * FROM *PREFIX*properties WHERE userid = ? AND propertypath = ?' ); + $result = $query->execute( array( OC_User::getUser(), $this->path )); - $existing = array(); - while( $row = $result->fetchRow()){ - $existing[$row['propertyname']] = $row['propertyvalue']; + $this->property_cache = array(); + while( $row = $result->fetchRow()){ + $this->property_cache[$row['propertyname']] = $row['propertyvalue']; + } } // if the array was empty, we need to return everything if(count($properties) == 0){ - return $existing; + return $this->property_cache; } $props = array(); foreach($properties as $property) { - if (isset($existing[$property])) $props[$property] = $existing[$property]; + if (isset($this->property_cache[$property])) $props[$property] = $this->property_cache[$property]; } return $props; } diff --git a/lib/filecache.php b/lib/filecache.php index 7c9c4dc41ff..32c6929ff60 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -34,7 +34,7 @@ class OC_FileCache{ * @param string root (optional) * @return array * - * returns an assiciative array with the following keys: + * returns an associative array with the following keys: * - size * - mtime * - ctime diff --git a/lib/migrate.php b/lib/migrate.php index f9cab915d04..5939ba32e50 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -196,7 +196,7 @@ class OC_Migrate{ * @param optional $uid userid of new user */ public static function import( $path, $type='user', $uid=null ){ - OC_Util::checkAdminUser(); + $datadir = OC_Config::getValue( 'datadirectory' ); // Extract the zip if( !$extractpath = self::extractZip( $path ) ){ @@ -216,12 +216,19 @@ class OC_Migrate{ } self::$exporttype = $type; + $currentuser = OC_User::getUser(); + // Have we got a user if type is user if( self::$exporttype == 'user' ){ - if( !$uid ){ - self::$uid = $json->exporteduser; - } else { - self::$uid = $uid; + self::$uid = !is_null($uid) ? $uid : $currentuser; + } + + // We need to be an admin if we are not importing our own data + if(($type == 'user' && self::$uid != $currentuser) || $type != 'user' ){ + if( !OC_Group::inGroup( OC_User::getUser(), 'admin' )){ + // Naughty. + OC_Log::write( 'migration', 'Import not permitted.', OC_Log::ERROR ); + return json_encode( array( 'success' => false ) ); } } @@ -229,27 +236,8 @@ class OC_Migrate{ switch( self::$exporttype ){ case 'user': // Check user availability - if( OC_User::userExists( self::$uid ) ){ - OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - $run = true; - OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => self::$uid, "password" => $json->hash )); - if( !$run ){ - // Something stopped the user creation - OC_Log::write( 'migration', 'User creation failed', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - // Create the user - if( !self::createUser( self::$uid, $json->hash ) ){ - return json_encode( array( 'success' => false ) ); - } - // Emit the post_createUser hook (password is already hashed, will cause problems - OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => self::$uid, "password" => $json->hash )); - // Make the new users data dir - $path = $datadir . '/' . self::$uid; - if( !mkdir( $path, 0755, true ) ){ - OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR ); + if( !OC_User::userExists( self::$uid ) ){ + OC_Log::write( 'migration', 'User doesn\'t exist', OC_Log::ERROR ); return json_encode( array( 'success' => false ) ); } // Copy data |