Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/nextcloud/server into lda…
Browse files Browse the repository at this point in the history
…p_password_renew_pr
  • Loading branch information
GitHubUser4234 committed Jan 10, 2017
2 parents 6b43dd9 + 97a63ad commit 59ee4eb
Show file tree
Hide file tree
Showing 30 changed files with 461 additions and 455 deletions.
15 changes: 2 additions & 13 deletions apps/comments/lib/Notification/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

use OCP\Comments\CommentsEvent;
use OCP\Comments\IComment;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Notification\IManager;

Expand All @@ -34,25 +33,19 @@ class Listener {
/** @var IUserManager */
protected $userManager;

/** @var IURLGenerator */
protected $urlGenerator;

/**
* Listener constructor.
*
* @param IManager $notificationManager
* @param IUserManager $userManager
* @param IURLGenerator $urlGenerator
*/
public function __construct(
IManager $notificationManager,
IUserManager $userManager,
IURLGenerator $urlGenerator
IUserManager $userManager
) {

$this->notificationManager = $notificationManager;
$this->userManager = $userManager;
$this->urlGenerator = $urlGenerator;
}

/**
Expand Down Expand Up @@ -100,11 +93,7 @@ public function instantiateNotification(IComment $comment) {
->setApp('comments')
->setObject('comment', $comment->getId())
->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
->setDateTime($comment->getCreationDateTime())
->setLink($this->urlGenerator->linkToRouteAbsolute(
'comments.Notifications.view',
['id' => $comment->getId()])
);
->setDateTime($comment->getCreationDateTime());

return $notification;
}
Expand Down
6 changes: 5 additions & 1 deletion apps/comments/lib/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ public function prepare(INotification $notification, $languageCode) {
]
);
}
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')));
$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/comment.svg')))
->setLink($this->url->linkToRouteAbsolute(
'comments.Notifications.view',
['id' => $comment->getId()])
);

return $notification;
break;
Expand Down
8 changes: 3 additions & 5 deletions apps/comments/tests/Unit/Notification/ListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ class ListenerTest extends TestCase {
protected function setUp() {
parent::setUp();

$this->notificationManager = $this->getMockBuilder('\OCP\Notification\IManager')->getMock();
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')->getMock();
$this->urlGenerator = $this->getMockBuilder('OCP\IURLGenerator')->getMock();
$this->notificationManager = $this->createMock(\OCP\Notification\IManager::class);
$this->userManager = $this->createMock(\OCP\IUserManager::class);

$this->listener = new Listener(
$this->notificationManager,
$this->userManager,
$this->urlGenerator
$this->userManager
);
}

Expand Down
16 changes: 7 additions & 9 deletions apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

use Aws\S3\S3Client;
use Aws\S3\Exception\S3Exception;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use OC\Files\ObjectStore\S3ConnectionTrait;

Expand Down Expand Up @@ -366,14 +367,15 @@ public function fopen($path, $mode) {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tmpFiles[$tmpFile] = $path;

return fopen('close://' . $tmpFile, $mode);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function() use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
}
return false;
}
Expand Down Expand Up @@ -514,15 +516,11 @@ public function getId() {
return $this->id;
}

public function writeBack($tmpFile) {
if (!isset(self::$tmpFiles[$tmpFile])) {
return false;
}

public function writeBack($tmpFile, $path) {
try {
$this->getConnection()->putObject(array(
'Bucket' => $this->bucket,
'Key' => $this->cleanKey(self::$tmpFiles[$tmpFile]),
'Key' => $this->cleanKey($path),
'SourceFile' => $tmpFile,
'ContentType' => \OC::$server->getMimeTypeDetector()->detect($tmpFile),
'ContentLength' => filesize($tmpFile)
Expand Down
28 changes: 13 additions & 15 deletions apps/files_external/lib/Lib/Storage/Dropbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
namespace OCA\Files_External\Lib\Storage;

use GuzzleHttp\Exception\RequestException;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use Icewind\Streams\RetryWrapper;
use OCP\Files\StorageNotAvailableException;
Expand All @@ -45,8 +46,6 @@ class Dropbox extends \OC\Files\Storage\Common {
private $metaData = array();
private $oauth;

private static $tempFiles = array();

public function __construct($params) {
if (isset($params['configured']) && $params['configured'] == 'true'
&& isset($params['app_key'])
Expand Down Expand Up @@ -305,27 +304,26 @@ public function fopen($path, $mode) {
$ext = '';
}
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r');
file_put_contents($tmpFile, $source);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://'.$tmpFile, $mode);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
}
return false;
}

public function writeBack($tmpFile) {
if (isset(self::$tempFiles[$tmpFile])) {
$handle = fopen($tmpFile, 'r');
try {
$this->dropbox->putFile(self::$tempFiles[$tmpFile], $handle);
unlink($tmpFile);
$this->deleteMetaData(self::$tempFiles[$tmpFile]);
} catch (\Exception $exception) {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
}
public function writeBack($tmpFile, $path) {
$handle = fopen($tmpFile, 'r');
try {
$this->dropbox->putFile($path, $handle);
unlink($tmpFile);
$this->deleteMetaData($path);
} catch (\Exception $exception) {
\OCP\Util::writeLog('files_external', $exception->getMessage(), \OCP\Util::ERROR);
}
}

Expand Down
16 changes: 8 additions & 8 deletions apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

namespace OCA\Files_External\Lib\Storage;

use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\RetryWrapper;

class FTP extends StreamWrapper{
Expand Down Expand Up @@ -127,21 +128,20 @@ public function fopen($path,$mode) {
$ext='';
}
$tmpFile=\OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$this->getFile($path, $tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
return fopen('close://'.$tmpFile, $mode);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
}
return false;
}

public function writeBack($tmpFile) {
if (isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
public function writeBack($tmpFile, $path) {
$this->uploadFile($tmpFile, $path);
unlink($tmpFile);
}

/**
Expand Down
144 changes: 70 additions & 74 deletions apps/files_external/lib/Lib/Storage/Google.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
namespace OCA\Files_External\Lib\Storage;

use GuzzleHttp\Exception\RequestException;
use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory;
use Icewind\Streams\RetryWrapper;

Expand All @@ -50,8 +51,6 @@ class Google extends \OC\Files\Storage\Common {
private $service;
private $driveFiles;

private static $tempFiles = array();

// Google Doc mimetypes
const FOLDER = 'application/vnd.google-apps.folder';
const DOCUMENT = 'application/vnd.google-apps.document';
Expand Down Expand Up @@ -495,94 +494,91 @@ public function fopen($path, $mode) {
case 'c':
case 'c+':
$tmpFile = \OCP\Files::tmpFile($ext);
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
if ($this->file_exists($path)) {
$source = $this->fopen($path, 'rb');
file_put_contents($tmpFile, $source);
}
self::$tempFiles[$tmpFile] = $path;
return fopen('close://'.$tmpFile, $mode);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
}
}

public function writeBack($tmpFile) {
if (isset(self::$tempFiles[$tmpFile])) {
$path = self::$tempFiles[$tmpFile];
$parentFolder = $this->getDriveFile(dirname($path));
if ($parentFolder) {
$mimetype = \OC::$server->getMimeTypeDetector()->detect($tmpFile);
$params = array(
'mimeType' => $mimetype,
'uploadType' => 'media'
);
$result = false;
public function writeBack($tmpFile, $path) {
$parentFolder = $this->getDriveFile(dirname($path));
if ($parentFolder) {
$mimetype = \OC::$server->getMimeTypeDetector()->detect($tmpFile);
$params = array(
'mimeType' => $mimetype,
'uploadType' => 'media'
);
$result = false;

$chunkSizeBytes = 10 * 1024 * 1024;

$useChunking = false;
$size = filesize($tmpFile);
if ($size > $chunkSizeBytes) {
$useChunking = true;
} else {
$params['data'] = file_get_contents($tmpFile);
}

$chunkSizeBytes = 10 * 1024 * 1024;
if ($this->file_exists($path)) {
$file = $this->getDriveFile($path);
$this->client->setDefer($useChunking);
$request = $this->service->files->update($file->getId(), $file, $params);
} else {
$file = new \Google_Service_Drive_DriveFile();
$file->setTitle(basename($path));
$file->setMimeType($mimetype);
$parent = new \Google_Service_Drive_ParentReference();
$parent->setId($parentFolder->getId());
$file->setParents(array($parent));
$this->client->setDefer($useChunking);
$request = $this->service->files->insert($file, $params);
}

$useChunking = false;
$size = filesize($tmpFile);
if ($size > $chunkSizeBytes) {
$useChunking = true;
} else {
$params['data'] = file_get_contents($tmpFile);
if ($useChunking) {
// Create a media file upload to represent our upload process.
$media = new \Google_Http_MediaFileUpload(
$this->client,
$request,
'text/plain',
null,
true,
$chunkSizeBytes
);
$media->setFileSize($size);

// Upload the various chunks. $status will be false until the process is
// complete.
$status = false;
$handle = fopen($tmpFile, 'rb');
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}

if ($this->file_exists($path)) {
$file = $this->getDriveFile($path);
$this->client->setDefer($useChunking);
$request = $this->service->files->update($file->getId(), $file, $params);
} else {
$file = new \Google_Service_Drive_DriveFile();
$file->setTitle(basename($path));
$file->setMimeType($mimetype);
$parent = new \Google_Service_Drive_ParentReference();
$parent->setId($parentFolder->getId());
$file->setParents(array($parent));
$this->client->setDefer($useChunking);
$request = $this->service->files->insert($file, $params);
// The final value of $status will be the data from the API for the object
// that has been uploaded.
$result = false;
if ($status !== false) {
$result = $status;
}

if ($useChunking) {
// Create a media file upload to represent our upload process.
$media = new \Google_Http_MediaFileUpload(
$this->client,
$request,
'text/plain',
null,
true,
$chunkSizeBytes
);
$media->setFileSize($size);

// Upload the various chunks. $status will be false until the process is
// complete.
$status = false;
$handle = fopen($tmpFile, 'rb');
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}

// The final value of $status will be the data from the API for the object
// that has been uploaded.
$result = false;
if ($status !== false) {
$result = $status;
}

fclose($handle);
} else {
$result = $request;
}
fclose($handle);
} else {
$result = $request;
}

// Reset to the client to execute requests immediately in the future.
$this->client->setDefer(false);
// Reset to the client to execute requests immediately in the future.
$this->client->setDefer(false);

if ($result) {
$this->setDriveFile($path, $result);
}
if ($result) {
$this->setDriveFile($path, $result);
}
unlink($tmpFile);
}
}

Expand Down
Loading

0 comments on commit 59ee4eb

Please sign in to comment.