Browse Source

Merge pull request #4790 from nextcloud/fix-comparisons-in-apps

Fix comparisons in apps
pull/5798/merge
Morris Jobke 8 years ago
committed by GitHub
parent
commit
6290ba8299
  1. 2
      apps/dav/lib/CalDAV/CalDavBackend.php
  2. 4
      apps/dav/lib/CalDAV/Search/SearchPlugin.php
  3. 2
      apps/dav/lib/CardDAV/CardDavBackend.php
  4. 2
      apps/dav/lib/Connector/Sabre/Directory.php
  5. 8
      apps/dav/lib/Connector/Sabre/File.php
  6. 2
      apps/dav/lib/Connector/Sabre/ObjectTree.php
  7. 2
      apps/dav/lib/DAV/Sharing/Backend.php
  8. 2
      apps/encryption/lib/Crypto/Crypt.php
  9. 6
      apps/encryption/lib/Crypto/Encryption.php
  10. 2
      apps/files/ajax/download.php
  11. 2
      apps/files/lib/Helper.php
  12. 2
      apps/files/lib/Settings/Admin.php
  13. 6
      apps/files_external/ajax/oauth2.php
  14. 4
      apps/files_external/lib/Command/Import.php
  15. 8
      apps/files_external/lib/Lib/Storage/Dropbox.php
  16. 2
      apps/files_external/lib/Lib/Storage/FTP.php
  17. 4
      apps/files_external/lib/Lib/Storage/OwnCloud.php
  18. 14
      apps/files_external/lib/Lib/Storage/SFTP.php
  19. 4
      apps/files_external/lib/Lib/Storage/SMB.php
  20. 4
      apps/files_external/lib/Lib/Storage/Swift.php
  21. 6
      apps/files_external/templates/settings.php
  22. 2
      apps/files_sharing/lib/Controller/ShareController.php
  23. 4
      apps/files_sharing/lib/Helper.php
  24. 8
      apps/files_sharing/lib/ShareBackend/File.php
  25. 4
      apps/files_sharing/lib/ShareBackend/Folder.php
  26. 2
      apps/files_sharing/templates/public.php
  27. 2
      apps/files_trashbin/lib/Storage.php
  28. 2
      apps/files_trashbin/lib/Trashbin.php
  29. 10
      apps/files_versions/lib/Hooks.php
  30. 158
      apps/files_versions/lib/Storage.php
  31. 2
      apps/user_ldap/lib/Wizard.php

2
apps/dav/lib/CalDAV/CalDavBackend.php

@ -1158,7 +1158,7 @@ class CalDavBackend extends AbstractBackend implements SyncSupport, Subscription
$requirePostFilter = false;
}
// There was a time-range filter
if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) {
if ($componentType === 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) {
$timeRange = $filters['comp-filters'][0]['time-range'];
// If start time OR the end time is not specified, we can do a

4
apps/dav/lib/CalDAV/Search/SearchPlugin.php

@ -134,7 +134,7 @@ class SearchPlugin extends ServerPlugin {
// If we're dealing with the calendar home, the calendar home itself is
// responsible for the calendar-query
if ($node instanceof CalendarHome && $depth == 2) {
if ($node instanceof CalendarHome && $depth === 2) {
$nodePaths = $node->calendarSearch($report->filters, $report->limit, $report->offset);
@ -156,4 +156,4 @@ class SearchPlugin extends ServerPlugin {
$this->server->generateMultiStatus($result,
$prefer['return'] === 'minimal'));
}
}
}

2
apps/dav/lib/CardDAV/CardDavBackend.php

@ -1019,7 +1019,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
}
$preferred = 0;
foreach($property->parameters as $parameter) {
if ($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') {
if ($parameter->name === 'TYPE' && strtoupper($parameter->getValue()) === 'PREF') {
$preferred = 1;
break;
}

2
apps/dav/lib/Connector/Sabre/Directory.php

@ -225,7 +225,7 @@ class Directory extends \OCA\DAV\Connector\Sabre\Node
throw new \Sabre\DAV\Exception\NotFound('File with name ' . $path . ' could not be located');
}
if ($info['mimetype'] == 'httpd/unix-directory') {
if ($info['mimetype'] === 'httpd/unix-directory') {
$node = new \OCA\DAV\Connector\Sabre\Directory($this->fileView, $info, $this->tree, $this->shareManager);
} else {
$node = new \OCA\DAV\Connector\Sabre\File($this->fileView, $info, $this->shareManager);

8
apps/dav/lib/Connector/Sabre/File.php

@ -146,8 +146,8 @@ class File extends Node implements IFile {
// double check if the file was fully received
// compare expected and actual size
if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
$expected = $_SERVER['CONTENT_LENGTH'];
if ($count != $expected) {
$expected = (int) $_SERVER['CONTENT_LENGTH'];
if ($count !== $expected) {
throw new BadRequest('expected filesize ' . $expected . ' got ' . $count);
}
}
@ -409,8 +409,8 @@ class File extends Node implements IFile {
//detect aborted upload
if (isset ($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'PUT') {
if (isset($_SERVER['CONTENT_LENGTH'])) {
$expected = $_SERVER['CONTENT_LENGTH'];
if ($bytesWritten != $expected) {
$expected = (int) $_SERVER['CONTENT_LENGTH'];
if ($bytesWritten !== $expected) {
$chunk_handler->remove($info['index']);
throw new BadRequest(
'expected filesize ' . $expected . ' got ' . $bytesWritten);

2
apps/dav/lib/Connector/Sabre/ObjectTree.php

@ -81,7 +81,7 @@ class ObjectTree extends \Sabre\DAV\Tree {
if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
// resolve to real file name to find the proper node
list($dir, $name) = \Sabre\Uri\split($path);
if ($dir == '/' || $dir == '.') {
if ($dir === '/' || $dir === '.') {
$dir = '';
}

2
apps/dav/lib/DAV/Sharing/Backend.php

@ -170,7 +170,7 @@ class Backend {
'href' => "principal:${row['principaluri']}",
'commonName' => isset($p['{DAV:}displayname']) ? $p['{DAV:}displayname'] : '',
'status' => 1,
'readOnly' => ($row['access'] == self::ACCESS_READ),
'readOnly' => ((int) $row['access'] === self::ACCESS_READ),
'{http://owncloud.org/ns}principal' => $row['principaluri'],
'{http://owncloud.org/ns}group-share' => is_null($p)
];

2
apps/encryption/lib/Crypto/Crypt.php

@ -605,7 +605,7 @@ class Crypt {
$element = array_shift($exploded);
while ($element != self::HEADER_END) {
while ($element !== self::HEADER_END) {
$result[$element] = array_shift($exploded);
$element = array_shift($exploded);
}

6
apps/encryption/lib/Crypto/Encryption.php

@ -449,13 +449,13 @@ class Encryption implements IEncryptionModule {
return false;
}
if ($parts[2] == 'files') {
if ($parts[2] === 'files') {
return true;
}
if ($parts[2] == 'files_versions') {
if ($parts[2] === 'files_versions') {
return true;
}
if ($parts[2] == 'files_trashbin') {
if ($parts[2] === 'files_trashbin') {
return true;
}

2
apps/files/ajax/download.php

@ -51,7 +51,7 @@ if(isset($_GET['downloadStartSecret'])
setcookie('ocDownloadStarted', $_GET['downloadStartSecret'], time() + 20, '/');
}
$server_params = array( 'head' => \OC::$server->getRequest()->getMethod() == 'HEAD' );
$server_params = array( 'head' => \OC::$server->getRequest()->getMethod() === 'HEAD' );
/**
* Http range requests support

2
apps/files/lib/Helper.php

@ -227,7 +227,7 @@ class Helper {
foreach ($filesById as $key => $fileWithTags) {
foreach($fileList as $key2 => $file){
if( $file[$fileIdentifier] == $key){
if( $file[$fileIdentifier] === $key){
$fileList[$key2] = $fileWithTags;
}
}

2
apps/files/lib/Settings/Admin.php

@ -46,7 +46,7 @@ class Admin implements ISettings {
* @return TemplateResponse
*/
public function getForm() {
$htaccessWorking = (getenv('htaccessWorking') == 'true');
$htaccessWorking = (getenv('htaccessWorking') === 'true');
$htaccessWritable = is_writable(\OC::$SERVERROOT.'/.htaccess');
$userIniWritable = is_writable(\OC::$SERVERROOT.'/.user.ini');

6
apps/files_external/ajax/oauth2.php

@ -46,8 +46,8 @@ if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST
$client->setApprovalPrompt('force');
$client->setAccessType('offline');
if (isset($_POST['step'])) {
$step = $_POST['step'];
if ($step == 1) {
$step = (int) $_POST['step'];
if ($step === 1) {
try {
$authUrl = $client->createAuthUrl();
OCP\JSON::success(array('data' => array(
@ -58,7 +58,7 @@ if (isset($_POST['client_id']) && isset($_POST['client_secret']) && isset($_POST
'message' => $l->t('Step 1 failed. Exception: %s', array($exception->getMessage()))
)));
}
} else if ($step == 2 && isset($_POST['code'])) {
} else if ($step === 2 && isset($_POST['code'])) {
try {
$token = $client->authenticate((string)$_POST['code']);
OCP\JSON::success(array('data' => array(

4
apps/files_external/lib/Command/Import.php

@ -161,8 +161,8 @@ class Import extends Base {
if (
$existingMount->getMountPoint() === $mount->getMountPoint() &&
$existingMount->getApplicableGroups() === $mount->getApplicableGroups() &&
$existingMount->getApplicableUsers() == $mount->getApplicableUsers() &&
$existingMount->getBackendOptions() == $mount->getBackendOptions()
$existingMount->getApplicableUsers() === $mount->getApplicableUsers() &&
$existingMount->getBackendOptions() === $mount->getBackendOptions()
) {
$output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>");
return 1;

8
apps/files_external/lib/Lib/Storage/Dropbox.php

@ -47,7 +47,7 @@ class Dropbox extends \OC\Files\Storage\Common {
private $oauth;
public function __construct($params) {
if (isset($params['configured']) && $params['configured'] == 'true'
if (isset($params['configured']) && $params['configured'] === 'true'
&& isset($params['app_key'])
&& isset($params['app_secret'])
&& isset($params['token'])
@ -187,12 +187,12 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function filetype($path) {
if ($path == '' || $path == '/') {
if ($path === '' || $path === '/') {
return 'dir';
} else {
$metaData = $this->getDropBoxMetaData($path);
if ($metaData) {
if ($metaData['is_dir'] == 'true') {
if ($metaData['is_dir'] === 'true') {
return 'dir';
} else {
return 'file';
@ -203,7 +203,7 @@ class Dropbox extends \OC\Files\Storage\Common {
}
public function file_exists($path) {
if ($path == '' || $path == '/') {
if ($path === '' || $path === '/') {
return true;
}
if ($this->getDropBoxMetaData($path)) {

2
apps/files_external/lib/Lib/Storage/FTP.php

@ -56,7 +56,7 @@ class FTP extends StreamWrapper{
$this->secure = false;
}
$this->root=isset($params['root'])?$params['root']:'/';
if ( ! $this->root || $this->root[0]!='/') {
if ( ! $this->root || $this->root[0]!=='/') {
$this->root='/'.$this->root;
}
if (substr($this->root, -1) !== '/') {

4
apps/files_external/lib/Lib/Storage/OwnCloud.php

@ -40,10 +40,10 @@ class OwnCloud extends \OC\Files\Storage\DAV{
// (owncloud install path on host)
$host = $params['host'];
// strip protocol
if (substr($host, 0, 8) == "https://") {
if (substr($host, 0, 8) === "https://") {
$host = substr($host, 8);
$params['secure'] = true;
} else if (substr($host, 0, 7) == "http://") {
} else if (substr($host, 0, 7) === "http://") {
$host = substr($host, 7);
$params['secure'] = false;
}

14
apps/files_external/lib/Lib/Storage/SFTP.php

@ -102,11 +102,11 @@ class SFTP extends \OC\Files\Storage\Common {
$this->root
= isset($params['root']) ? $this->cleanPath($params['root']) : '/';
if ($this->root[0] != '/') {
if ($this->root[0] !== '/') {
$this->root = '/' . $this->root;
}
if (substr($this->root, -1, 1) != '/') {
if (substr($this->root, -1, 1) !== '/') {
$this->root .= '/';
}
}
@ -128,7 +128,7 @@ class SFTP extends \OC\Files\Storage\Common {
// The SSH Host Key MUST be verified before login().
$currentHostKey = $this->client->getServerPublicHostKey();
if (array_key_exists($this->host, $hostKeys)) {
if ($hostKeys[$this->host] != $currentHostKey) {
if ($hostKeys[$this->host] !== $currentHostKey) {
throw new \Exception('Host public key does not match known key');
}
} else {
@ -248,7 +248,7 @@ class SFTP extends \OC\Files\Storage\Common {
if ($lines) {
foreach ($lines as $line) {
$hostKeyArray = explode("::", $line, 2);
if (count($hostKeyArray) == 2) {
if (count($hostKeyArray) === 2) {
$hosts[] = $hostKeyArray[0];
$keys[] = $hostKeyArray[1];
}
@ -300,7 +300,7 @@ class SFTP extends \OC\Files\Storage\Common {
$id = md5('sftp:' . $path);
$dirStream = array();
foreach($list as $file) {
if ($file != '.' && $file != '..') {
if ($file !== '.' && $file !== '..') {
$dirStream[] = $file;
}
}
@ -316,11 +316,11 @@ class SFTP extends \OC\Files\Storage\Common {
public function filetype($path) {
try {
$stat = $this->getConnection()->stat($this->absPath($path));
if ($stat['type'] == NET_SFTP_TYPE_REGULAR) {
if ((int) $stat['type'] === NET_SFTP_TYPE_REGULAR) {
return 'file';
}
if ($stat['type'] == NET_SFTP_TYPE_DIRECTORY) {
if ((int) $stat['type'] === NET_SFTP_TYPE_DIRECTORY) {
return 'dir';
}
} catch (\Exception $e) {

4
apps/files_external/lib/Lib/Storage/SMB.php

@ -81,10 +81,10 @@ class SMB extends Common implements INotifyStorage {
$this->share = $this->server->getShare(trim($params['share'], '/'));
$this->root = isset($params['root']) ? $params['root'] : '/';
if (!$this->root || $this->root[0] != '/') {
if (!$this->root || $this->root[0] !== '/') {
$this->root = '/' . $this->root;
}
if (substr($this->root, -1, 1) != '/') {
if (substr($this->root, -1, 1) !== '/') {
$this->root .= '/';
}
} else {

4
apps/files_external/lib/Lib/Storage/Swift.php

@ -435,7 +435,7 @@ class Swift extends \OC\Files\Storage\Common {
}
$metadata = array('timestamp' => $mtime);
if ($this->file_exists($path)) {
if ($this->is_dir($path) && $path != '.') {
if ($this->is_dir($path) && $path !== '.') {
$path .= '/';
}
@ -640,7 +640,7 @@ class Swift extends \OC\Files\Storage\Common {
}, $cachedContent);
sort($cachedNames);
sort($content);
return $cachedNames != $content;
return $cachedNames !== $content;
}
/**

6
apps/files_external/templates/settings.php

@ -89,7 +89,7 @@
<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
<h2 data-anchor-name="external-storage"><?php p($l->t('External storages')); ?></h2>
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?>
<?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?>
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
<thead>
<tr>
@ -169,10 +169,10 @@
<?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
value="1" <?php if ($_['allowUserMounting'] === 'yes') print_unescaped(' checked="checked"'); ?> />
<label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
<p id="userMountingBackends"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>>
<p id="userMountingBackends"<?php if ($_['allowUserMounting'] !== 'yes'): ?> class="hidden"<?php endif; ?>>
<?php p($l->t('Allow users to mount the following external storage')); ?><br />
<?php
$userBackends = array_filter($_['backends'], function($backend) {

2
apps/files_sharing/lib/Controller/ShareController.php

@ -514,7 +514,7 @@ class ShareController extends Controller {
$this->emitAccessShareHook($share);
$server_params = array( 'head' => $this->request->getMethod() == 'HEAD' );
$server_params = array( 'head' => $this->request->getMethod() === 'HEAD' );
/**
* Http range requests support

4
apps/files_sharing/lib/Helper.php

@ -132,7 +132,7 @@ class Helper {
Filesystem::initMountPoints($owner);
$info = Filesystem::getFileInfo($target);
$ownerView = new View('/'.$owner.'/files');
if ( $owner != User::getUser() ) {
if ( $owner !== User::getUser() ) {
$path = $ownerView->getPath($info['fileid']);
} else {
$path = $target;
@ -183,7 +183,7 @@ class Helper {
$uid = User::getUser();
}
Filesystem::initMountPoints($uid);
if ( $uid != User::getUser() ) {
if ( $uid !== User::getUser() ) {
$info = Filesystem::getFileInfo($filename);
$ownerView = new View('/'.$uid.'/files');
try {

8
apps/files_sharing/lib/ShareBackend/File.php

@ -123,7 +123,7 @@ class File implements \OCP\Share_Backend_File_Dependent {
}
public function formatItems($items, $format, $parameters = null) {
if ($format == self::FORMAT_SHARED_STORAGE) {
if ($format === self::FORMAT_SHARED_STORAGE) {
// Only 1 item should come through for this format call
$item = array_shift($items);
return array(
@ -133,7 +133,7 @@ class File implements \OCP\Share_Backend_File_Dependent {
'permissions' => $item['permissions'],
'uid_owner' => $item['uid_owner'],
);
} else if ($format == self::FORMAT_GET_FOLDER_CONTENTS) {
} else if ($format === self::FORMAT_GET_FOLDER_CONTENTS) {
$files = array();
foreach ($items as $item) {
$file = array();
@ -156,13 +156,13 @@ class File implements \OCP\Share_Backend_File_Dependent {
$files[] = $file;
}
return $files;
} else if ($format == self::FORMAT_OPENDIR) {
} else if ($format === self::FORMAT_OPENDIR) {
$files = array();
foreach ($items as $item) {
$files[] = basename($item['file_target']);
}
return $files;
} else if ($format == self::FORMAT_GET_ALL) {
} else if ($format === self::FORMAT_GET_ALL) {
$ids = array();
foreach ($items as $item) {
$ids[] = $item['file_source'];

4
apps/files_sharing/lib/ShareBackend/Folder.php

@ -83,7 +83,7 @@ class Folder extends File implements \OCP\Share_Backend_Collection {
$query = \OCP\DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
$result = $query->execute(array('httpd/unix-directory'));
if ($row = $result->fetchRow()) {
$mimetype = $row['id'];
$mimetype = (int) $row['id'];
} else {
$mimetype = -1;
}
@ -96,7 +96,7 @@ class Folder extends File implements \OCP\Share_Backend_Collection {
while ($file = $result->fetchRow()) {
$children[] = array('source' => $file['fileid'], 'file_path' => $file['name']);
// If a child folder is found look inside it
if ($file['mimetype'] == $mimetype) {
if ((int) $file['mimetype'] === $mimetype) {
$parents[] = $file['fileid'];
}
}

2
apps/files_sharing/templates/public.php

@ -75,7 +75,7 @@ $maxUploadFilesize = min($upload_max_filesize, $post_max_size);
<?php if (isset($_['folder'])): ?>
<?php print_unescaped($_['folder']); ?>
<?php else: ?>
<?php if ($_['previewEnabled'] && substr($_['mimetype'], 0, strpos($_['mimetype'], '/')) == 'video'): ?>
<?php if ($_['previewEnabled'] && substr($_['mimetype'], 0, strpos($_['mimetype'], '/')) === 'video'): ?>
<div id="imgframe">
<video tabindex="0" controls="" preload="none" style="max-width: <?php p($_['previewMaxX']); ?>px; max-height: <?php p($_['previewMaxY']); ?>px">
<source src="<?php p($_['downloadURL']); ?>" type="<?php p($_['mimetype']); ?>" />

2
apps/files_trashbin/lib/Storage.php

@ -206,7 +206,7 @@ class Storage extends Wrapper {
return false;
}
if ($this->userManager->userExists($parts[1]) && $parts[2] == 'files') {
if ($this->userManager->userExists($parts[1]) && $parts[2] === 'files') {
return true;
}

2
apps/files_trashbin/lib/Trashbin.php

@ -95,7 +95,7 @@ class Trashbin {
return [null, null];
}
Filesystem::initMountPoints($uid);
if ($uid != User::getUser()) {
if ($uid !== User::getUser()) {
$info = Filesystem::getFileInfo($filename);
$ownerView = new View('/' . $uid . '/files');
try {

10
apps/files_versions/lib/Hooks.php

@ -57,7 +57,7 @@ class Hooks {
if (\OCP\App::isEnabled('files_versions')) {
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
if($path !== '') {
Storage::store($path);
}
}
@ -75,7 +75,7 @@ class Hooks {
if (\OCP\App::isEnabled('files_versions')) {
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
if($path !== '') {
Storage::delete($path);
}
}
@ -87,7 +87,7 @@ class Hooks {
*/
public static function pre_remove_hook($params) {
$path = $params[\OC\Files\Filesystem::signal_param_path];
if($path<>'') {
if($path !== '') {
Storage::markDeletedFile($path);
}
}
@ -104,7 +104,7 @@ class Hooks {
if (\OCP\App::isEnabled('files_versions')) {
$oldpath = $params['oldpath'];
$newpath = $params['newpath'];
if($oldpath<>'' && $newpath<>'') {
if($oldpath !== '' && $newpath !== '') {
Storage::renameOrCopy($oldpath, $newpath, 'rename');
}
}
@ -122,7 +122,7 @@ class Hooks {
if (\OCP\App::isEnabled('files_versions')) {
$oldpath = $params['oldpath'];
$newpath = $params['newpath'];
if($oldpath<>'' && $newpath<>'') {
if($oldpath !== '' && $newpath !== '') {
Storage::renameOrCopy($oldpath, $newpath, 'copy');
}
}

158
apps/files_versions/lib/Storage.php

@ -102,7 +102,7 @@ class Storage {
$uid = User::getUser();
}
Filesystem::initMountPoints($uid);
if ( $uid != User::getUser() ) {
if ( $uid !== User::getUser() ) {
$info = Filesystem::getFileInfo($filename);
$ownerView = new View('/'.$uid.'/files');
try {
@ -161,41 +161,39 @@ class Storage {
* store a new version of a file.
*/
public static function store($filename) {
if(\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
// if the file gets streamed we need to remove the .part extension
// to get the right target
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if ($ext === 'part') {
$filename = substr($filename, 0, strlen($filename) - 5);
}
// if the file gets streamed we need to remove the .part extension
// to get the right target
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if ($ext === 'part') {
$filename = substr($filename, 0, strlen($filename) - 5);
}
// we only handle existing files
if (! Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) {
return false;
}
// we only handle existing files
if (! Filesystem::file_exists($filename) || Filesystem::is_dir($filename)) {
return false;
}
list($uid, $filename) = self::getUidAndFilename($filename);
list($uid, $filename) = self::getUidAndFilename($filename);
$files_view = new View('/'.$uid .'/files');
$users_view = new View('/'.$uid);
$files_view = new View('/'.$uid .'/files');
$users_view = new View('/'.$uid);
// no use making versions for empty files
if ($files_view->filesize($filename) === 0) {
return false;
}
// no use making versions for empty files
if ($files_view->filesize($filename) === 0) {
return false;
}
// create all parent folders
self::createMissingDirectories($filename, $users_view);
// create all parent folders
self::createMissingDirectories($filename, $users_view);
self::scheduleExpire($uid, $filename);
self::scheduleExpire($uid, $filename);
// store a new version of a file
$mtime = $users_view->filemtime('files/' . $filename);
$users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
// call getFileInfo to enforce a file cache entry for the new version
$users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
}
// store a new version of a file
$mtime = $users_view->filemtime('files/' . $filename);
$users_view->copy('files/' . $filename, 'files_versions/' . $filename . '.v' . $mtime);
// call getFileInfo to enforce a file cache entry for the new version
$users_view->getFileInfo('files_versions/' . $filename . '.v' . $mtime);
}
@ -320,61 +318,60 @@ class Storage {
*/
public static function rollback($file, $revision) {
if(\OC::$server->getConfig()->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true') {
// add expected leading slash
$file = '/' . ltrim($file, '/');
list($uid, $filename) = self::getUidAndFilename($file);
if ($uid === null || trim($filename, '/') === '') {
return false;
}
// add expected leading slash
$file = '/' . ltrim($file, '/');
list($uid, $filename) = self::getUidAndFilename($file);
if ($uid === null || trim($filename, '/') === '') {
return false;
}
$users_view = new View('/'.$uid);
$files_view = new View('/'. User::getUser().'/files');
$users_view = new View('/'.$uid);
$files_view = new View('/'. User::getUser().'/files');
$versionCreated = false;
$versionCreated = false;
$fileInfo = $files_view->getFileInfo($file);
$fileInfo = $files_view->getFileInfo($file);
// check if user has the permissions to revert a version
if (!$fileInfo->isUpdateable()) {
return false;
}
// check if user has the permissions to revert a version
if (!$fileInfo->isUpdateable()) {
return false;
}
//first create a new version
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
if (!$users_view->file_exists($version)) {
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
$versionCreated = true;
}
//first create a new version
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
if (!$users_view->file_exists($version)) {
$users_view->copy('files'.$filename, 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename));
$versionCreated = true;
}
$fileToRestore = 'files_versions' . $filename . '.v' . $revision;
// Restore encrypted version of the old file for the newly restored file
// This has to happen manually here since the file is manually copied below
$oldVersion = $users_view->getFileInfo($fileToRestore)->getEncryptedVersion();
$oldFileInfo = $users_view->getFileInfo($fileToRestore);
$cache = $fileInfo->getStorage()->getCache();
$cache->update(
$fileInfo->getId(), [
'encrypted' => $oldVersion,
'encryptedVersion' => $oldVersion,
'size' => $oldFileInfo->getSize()
]
);
// rollback
if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file);
\OC_Hook::emit('\OCP\Versions', 'rollback', array(
'path' => $filename,
'revision' => $revision,
));
return true;
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
}
$fileToRestore = 'files_versions' . $filename . '.v' . $revision;
// Restore encrypted version of the old file for the newly restored file
// This has to happen manually here since the file is manually copied below
$oldVersion = $users_view->getFileInfo($fileToRestore)->getEncryptedVersion();
$oldFileInfo = $users_view->getFileInfo($fileToRestore);
$cache = $fileInfo->getStorage()->getCache();
$cache->update(
$fileInfo->getId(), [
'encrypted' => $oldVersion,
'encryptedVersion' => $oldVersion,
'size' => $oldFileInfo->getSize()
]
);
// rollback
if (self::copyFileContents($users_view, $fileToRestore, 'files' . $filename)) {
$files_view->touch($file, $revision);
Storage::scheduleExpire($uid, $file);
\OC_Hook::emit('\OCP\Versions', 'rollback', array(
'path' => $filename,
'revision' => $revision,
));
return true;
} else if ($versionCreated) {
self::deleteVersion($users_view, $version);
}
return false;
}
@ -629,7 +626,7 @@ class Storage {
$interval = 1;
$step = Storage::$max_versions_per_interval[$interval]['step'];
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1) {
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) {
$nextInterval = -1;
} else {
$nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'];
@ -644,7 +641,7 @@ class Storage {
foreach ($versions as $key => $version) {
$newInterval = true;
while ($newInterval) {
if ($nextInterval == -1 || $prevTimestamp > $nextInterval) {
if ($nextInterval === -1 || $prevTimestamp > $nextInterval) {
if ($version['version'] > $nextVersion) {
//distance between two version too small, mark to delete
$toDelete[$key] = $version['path'] . '.v' . $version['version'];
@ -659,7 +656,7 @@ class Storage {
$interval++;
$step = Storage::$max_versions_per_interval[$interval]['step'];
$nextVersion = $prevTimestamp - $step;
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] == -1) {
if (Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'] === -1) {
$nextInterval = -1;
} else {
$nextInterval = $time - Storage::$max_versions_per_interval[$interval]['intervalEndsAfter'];
@ -698,10 +695,9 @@ class Storage {
* @return bool|int|null
*/
public static function expire($filename, $uid) {
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();
if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {
if ($expiration->isEnabled()) {
// get available disk space for user
$user = \OC::$server->getUserManager()->get($uid);
if (is_null($user)) {

2
apps/user_ldap/lib/Wizard.php

@ -905,7 +905,7 @@ class Wizard extends LDAPUtility {
$er = $this->ldap->firstEntry($cr, $rr);
$attrs = $this->ldap->getAttributes($cr, $er);
$dn = $this->ldap->getDN($cr, $er);
if ($dn == false || $dn === '') {
if ($dn === false || $dn === '') {
continue;
}
$filterPart = '(memberof=' . $dn . ')';

Loading…
Cancel
Save