updated-packages

This commit is contained in:
RafficMohammed
2023-01-08 00:13:22 +05:30
parent 3ff7df7487
commit da241bacb6
12659 changed files with 563377 additions and 510538 deletions

View File

@@ -1,7 +1,7 @@
language: php
dist: precise
php:
- 5.3
- 5.4
- 5.5

View File

@@ -28,8 +28,11 @@ require_once './vendor/autoload.php';
$config = new \Flow\Config();
$config->setTempDir('./chunks_temp_folder');
$request = new \Flow\Request();
if (\Flow\Basic::save('./' . $request->getIdentifier(), $config, $request)) {
// file saved successfully and can be accessed at './final_file_destination'
$uploadFolder = './final_file_destination/'; // Folder where the file will be stored
$uploadFileName = uniqid()."_".$request->getFileName(); // The name the file will have on the server
$uploadPath = $uploadFolder.$uploadFileName;
if (\Flow\Basic::save($uploadPath, $config, $request)) {
// file saved successfully and can be accessed at $uploadPath
} else {
// This is not a final chunk or request is invalid, continue to upload.
}

View File

@@ -19,13 +19,18 @@
"chunks"
],
"require": {
"php": ">=5.3"
"php": ">=5.4"
},
"require-dev": {
"mikey179/vfsStream": "v1.2.0",
"mikey179/vfsstream": "v1.2.0",
"league/phpunit-coverage-listener": "~1.1",
"fabpot/php-cs-fixer": "dev-master",
"phpunit/phpunit": "4.*"
"fabpot/php-cs-fixer": "~2.2",
"phpunit/phpunit": "4.*",
"mongodb/mongodb": "^1.4.0",
"ext-mongodb": "*"
},
"suggest": {
"mongodb/mongodb":"Required to use this package with Mongo DB"
},
"autoload": {
"psr-0": {

0
vendor/flowjs/flow-php-server/phpunit vendored Normal file → Executable file
View File

View File

@@ -3,6 +3,7 @@
namespace Flow\Mongo;
use Flow\Config;
use MongoDB\GridFS\Bucket;
/**
* @codeCoverageIgnore
@@ -12,9 +13,9 @@ class MongoConfig extends Config implements MongoConfigInterface
private $gridFs;
/**
* @param \MongoGridFS $gridFS storage of the upload (and chunks)
* @param Bucket $gridFS storage of the upload (and chunks)
*/
function __construct(\MongoGridFS $gridFS)
function __construct(Bucket $gridFS)
{
parent::__construct();
$this->gridFs = $gridFS;
@@ -22,7 +23,7 @@ class MongoConfig extends Config implements MongoConfigInterface
/**
* @return \MongoGridFS
* @return Bucket
*/
public function getGridFs()
{

View File

@@ -3,6 +3,7 @@
namespace Flow\Mongo;
use Flow\ConfigInterface;
use MongoDB\GridFS\Bucket;
/**
* @codeCoverageIgnore
@@ -11,7 +12,7 @@ interface MongoConfigInterface extends ConfigInterface
{
/**
* @return \MongoGridFS
* @return Bucket
*/
public function getGridFs();

View File

@@ -2,9 +2,14 @@
namespace Flow\Mongo;
use Exception;
use Flow\File;
use Flow\Request;
use Flow\RequestInterface;
use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Operation\FindOneAndReplace;
/**
@@ -42,9 +47,9 @@ class MongoFile extends File
if (!$this->uploadGridFsFile) {
$gridFsFileQuery = $this->getGridFsFileQuery();
$changed = $gridFsFileQuery;
$changed['flowUpdated'] = new \MongoDate();
$this->uploadGridFsFile = $this->config->getGridFs()->findAndModify($gridFsFileQuery, $changed, null,
['upsert' => true, 'new' => true]);
$changed['flowUpdated'] = new UTCDateTime();
$this->uploadGridFsFile = $this->config->getGridFs()->getFilesCollection()->findOneAndReplace($gridFsFileQuery, $changed,
['upsert' => true, 'returnDocument' => FindOneAndReplace::RETURN_DOCUMENT_AFTER]);
}
return $this->uploadGridFsFile;
@@ -56,10 +61,10 @@ class MongoFile extends File
*/
public function chunkExists($index)
{
return $this->config->getGridFs()->chunks->find([
return $this->config->getGridFs()->getChunksCollection()->findOne([
'files_id' => $this->getGridFsFile()['_id'],
'n' => (intval($index) - 1)
])->limit(1)->hasNext();
]) !== null;
}
public function checkChunk()
@@ -69,10 +74,11 @@ class MongoFile extends File
/**
* Save chunk
* @param $additionalUpdateOptions array additional options for the mongo update/upsert operation.
* @return bool
* @throws \Exception if upload size is invalid or some other unexpected error occurred.
* @throws Exception if upload size is invalid or some other unexpected error occurred.
*/
public function saveChunk()
public function saveChunk($additionalUpdateOptions = [])
{
try {
$file = $this->request->getFile();
@@ -88,19 +94,19 @@ class MongoFile extends File
($actualChunkSize < $this->request->getDefaultChunkSize() &&
$this->request->getCurrentChunkNumber() != $this->request->getTotalChunks())
) {
throw new \Exception("Invalid upload! (size: {$actualChunkSize})");
throw new Exception("Invalid upload! (size: $actualChunkSize)");
}
$chunk['data'] = new \MongoBinData($data, 0); // \MongoBinData::GENERIC is not defined for older mongo drivers
$this->config->getGridFs()->chunks->findAndModify($chunkQuery, $chunk, [], ['upsert' => true]);
$chunk['data'] = new Binary($data, Binary::TYPE_GENERIC);
$this->config->getGridFs()->getChunksCollection()->replaceOne($chunkQuery, $chunk, array_merge(['upsert' => true], $additionalUpdateOptions));
unlink($file['tmp_name']);
$this->ensureIndices();
return true;
} catch (\Exception $e) {
} catch (Exception $e) {
// try to remove a possibly (partly) stored chunk:
if (isset($chunkQuery)) {
$this->config->getGridFs()->chunks->remove($chunkQuery);
$this->config->getGridFs()->getChunksCollection()->deleteMany($chunkQuery);
}
throw $e;
}
@@ -111,30 +117,25 @@ class MongoFile extends File
*/
public function validateFile()
{
$totalChunks = $this->request->getTotalChunks();
for ($i = 1; $i <= $totalChunks; $i++) {
if (!$this->chunkExists($i)) {
return false;
}
}
return true;
$totalChunks = intval($this->request->getTotalChunks());
$storedChunks = $this->config->getGridFs()->getChunksCollection()
->countDocuments(['files_id' => $this->getGridFsFile()['_id']]);
return $totalChunks === $storedChunks;
}
/**
* Merge all chunks to single file
* @param $metadata array additional metadata for final file
* @return \MongoId|bool of saved file or false if file was already saved
* @throws \Exception
* @return ObjectId|bool of saved file or false if file was already saved
* @throws Exception
*/
public function saveToGridFs($metadata = null)
{
$file = $this->getGridFsFile();
$file['flowStatus'] = 'finished';
$file['metadata'] = $metadata;
$result = $this->config->getGridFs()->findAndModify($this->getGridFsFileQuery(), $file);
$result = $this->config->getGridFs()->getFilesCollection()->findOneAndReplace($this->getGridFsFileQuery(), $file);
// on second invocation no more file can be found, as the flowStatus changed:
if (is_null($result)) {
return false;
@@ -145,7 +146,7 @@ class MongoFile extends File
public function save($destination)
{
throw new \Exception("Must not use 'save' on MongoFile - use 'saveToGridFs'!");
throw new Exception("Must not use 'save' on MongoFile - use 'saveToGridFs'!");
}
public function deleteChunks()
@@ -155,14 +156,10 @@ class MongoFile extends File
public function ensureIndices()
{
$chunksCollection = $this->config->getGridFs()->chunks;
$chunksCollection = $this->config->getGridFs()->getChunksCollection();
$indexKeys = ['files_id' => 1, 'n' => 1];
$indexOptions = ['unique' => true, 'background' => true];
if(method_exists($chunksCollection, 'createIndex')) { // only available for PECL mongo >= 1.5.0
$chunksCollection->createIndex($indexKeys, $indexOptions);
} else {
$chunksCollection->ensureIndex($indexKeys, $indexOptions);
}
$chunksCollection->createIndex($indexKeys, $indexOptions);
}
/**

View File

@@ -2,7 +2,7 @@
namespace Flow\Mongo;
use Flow\FileOpenException;
use MongoDB\GridFS\Bucket;
/**
* @codeCoverageIgnore
@@ -12,20 +12,17 @@ class MongoUploader
/**
* Delete chunks older than expiration time.
*
* @param \MongoGridFS $gridFs
* @param Bucket $gridFs
* @param int $expirationTime seconds
*
* @throws FileOpenException
*/
public static function pruneChunks($gridFs, $expirationTime = 172800)
{
$result = $gridFs->remove([
'flowUpdated' => ['$lt' => new \MongoDate(time() - $expirationTime)],
$result = $gridFs->find([
'flowUpdated' => ['$lt' => new \MongoDB\BSON\UTCDateTime(time() - $expirationTime)],
'flowStatus' => 'uploading'
]);
if (!$result) {
throw new FileOpenException("Could not remove chunks!");
foreach ($result as $file) {
$gridFs->delete($file['_id']);
}
}
}

View File

@@ -3,7 +3,7 @@ Usage
* Must use 'forceChunkSize=true' on client side.
* Chunk preprocessor not supported.
* One should ensure indices on the gridfs collection on the property 'flowIdentifier'.
* One should ensure indices on the gridfs files collection on the property 'flowIdentifier'.
Besides the points above, the usage is analogous to the 'normal' flow-php:
@@ -41,7 +41,7 @@ if ($file->validateFile()) {
Delete unfinished files
-----------------------
For this you should setup cron, which would check each chunk upload time.
For this you should set up cron, which would check each chunk upload time.
If chunk is uploaded long time ago, then chunk should be deleted.
Helper method for checking this: