Skip to content

Use database for upload session instead of Yii::$app->session #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2966b34
Use database for upload session instead of Yii::$app->session
Webkadabra Nov 4, 2018
288113b
Bump version
Webkadabra Nov 4, 2018
e87ff05
Fix Error with message "Class rkit\filemanager\models\Expression not …
Webkadabra Nov 19, 2018
122d1cb
Fix error Class rkit\filemanager\models\TimestampBehavior does not exist
Webkadabra Nov 19, 2018
4b59efd
Fix error: 'Setting unknown property: rkit\filemanager\models\FileUpl…
Webkadabra Nov 19, 2018
ce9833d
Update documentation
Webkadabra Jan 5, 2019
07415ab
Improve support for cases of uploads when original model was a new re…
Webkadabra Jan 6, 2019
109d765
Fix use of `clearState`
Webkadabra Jan 7, 2019
df9c672
Add remote upload support
Webkadabra Apr 8, 2019
1b997a5
Add compatibility with console contorllers
Webkadabra Apr 20, 2019
0cea45b
Add `onSuccess` option
Webkadabra May 7, 2019
1cc5419
Bump version
Webkadabra May 7, 2019
86fe36b
Add `userComponent` property
Webkadabra May 7, 2019
ffb5965
Bump version
Webkadabra May 7, 2019
67d9855
Add `FileBehavior::addClassAlias` to be able to upload files for diff…
Webkadabra Jun 17, 2019
be261ec
Bump version
Webkadabra Jun 17, 2019
162f491
Revert "Bump version"
Webkadabra Jun 17, 2019
7fdf793
Ability to mark current upload session as already linked (e.g. file i…
Webkadabra Aug 2, 2019
d8019d9
Bump version
Webkadabra Sep 19, 2019
8dacc69
Add file option `disableAutobind`
Webkadabra Sep 19, 2019
3bee64e
Set correct mime type when uploading
Webkadabra Sep 19, 2019
28eec20
Fix error: `path` is not available in every adapter
Webkadabra Oct 4, 2019
c2dfbdf
Update FileBehavior.php
Webkadabra Sep 5, 2020
cb778df
Update composer.json
Webkadabra Sep 5, 2020
02f33d9
Update composer.json
Webkadabra Mar 15, 2021
91f83e5
Update FileBind.php
Webkadabra Mar 19, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 51 additions & 45 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,45 +1,51 @@
{
"name": "rkit/filemanager-yii2",
"description": "FileManager for Yii2",
"keywords": ["yii2", "extension", "file manager", "manager", "upload", "resize", "files"],
"homepage": "https://github.com/rkit/filemanager-yii2",
"type": "yii2-extension",
"license": "MIT",
"authors": [
{
"name": "Igor Romanov",
"email": "rkit.ru@gmail.com"
}
],
"support": {
"issues": "https://github.com/rkit/filemanager-yii2/issues?state=open",
"source": "https://github.com/rkit/filemanager-yii2"
},
"require": {
"yiisoft/yii2": "^2.0"
},
"scripts": {
"phpdoc": "phpdoc",
"test-prepare": [
"php tests/yii migrate --migrationPath=@tests/migrations/ --interactive=0"
],
"test": "phpunit --colors=always",
"test-coverage": "phpunit --coverage-html=tests/tmp/coverage.html --colors=always",
"test-coverage-open": "open tests/tmp/coverage.html/index.html"
},
"autoload": {
"psr-4": {
"rkit\\filemanager\\": "src"
}
},
"require-dev": {
"intervention/image": "^2.3.2",
"phpunit/phpunit": "^4.8",
"phpunit/dbunit": "^1.4",
"phpdocumentor/phpdocumentor": "^2.8.0",
"cvuorinen/phpdoc-markdown-public": "^0.1.2",
"league/flysystem": "^1.0",
"creocoder/yii2-flysystem": "^0.8.1",
"squizlabs/php_codesniffer": "3.0.0RC1"
}
}
{
"name": "rkit/filemanager-yii2",
"description": "FileManager for Yii2",
"keywords": ["yii2", "extension", "file manager", "manager", "upload", "resize", "files"],
"homepage": "https://github.com/rkit/filemanager-yii2",
"type": "yii2-extension",
"version": "5.8.1",
"license": "MIT",
"authors": [
{
"name": "Igor Romanov",
"email": "rkit.ru@gmail.com"
},
{
"name": "Sergii Gamaiunov",
"email": "devkadabra@gmail.com"
}
],
"support": {
"issues": "https://github.com/rkit/filemanager-yii2/issues?state=open",
"source": "https://github.com/rkit/filemanager-yii2"
},
"require": {
"yiisoft/yii2": "^2.0",
"igogo5yo/yii2-upload-from-url": "^1.4"
},
"scripts": {
"phpdoc": "phpdoc",
"test-prepare": [
"php tests/yii migrate --migrationPath=@tests/migrations/ --interactive=0"
],
"test": "phpunit --colors=always",
"test-coverage": "phpunit --coverage-html=tests/tmp/coverage.html --colors=always",
"test-coverage-open": "open tests/tmp/coverage.html/index.html"
},
"autoload": {
"psr-4": {
"rkit\\filemanager\\": "src"
}
},
"require-dev": {
"intervention/image": "^2.3.2",
"phpunit/phpunit": "^4.8",
"phpunit/dbunit": "^1.4",
"phpdocumentor/phpdocumentor": "^2.8.0",
"cvuorinen/phpdoc-markdown-public": "^0.1.2",
"league/flysystem": "*",
"creocoder/yii2-flysystem": "*",
"squizlabs/php_codesniffer": "3.0.0RC1"
}
}
18 changes: 18 additions & 0 deletions guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Let's do it.
```
> You can add any extra fields, such as `type` to divide files by type or `position` to set sort order

Migration for upload session (since 5.0)

```php
php yii migrate/create create_file_upload_session_table --fields="file_id:integer:notNull:defaultValue(0),created_user_id:integer:notNull:defaultValue(0),target_model_id:integer:defaultValue(0),target_model_class:string:notNull:defaultValue(''),target_model_attribute:string:notNull:defaultValue(''),created_on:datetime"
```
> You can add any extra fields, such as `type` to divide files by type or `position` to set sort order

3. **Applying Migrations**

```php
Expand Down Expand Up @@ -119,6 +126,17 @@ Let's do it.
$file->save();
return $file;
},
// a callback for creating `File` model for remote uploads
'createRemoteFile' => function ($info, $name) {
$file = new File();
$file->title = $name;
$file->created_on = new yii\db\Expression('NOW()');
$file->created_user_id = Yii::$app->user->id;
$file->size_bytes = $info->size;
$file->generateName($info->url, $name, $this);
$file->save();
return $file;
},
// core validators
'rules' => [
'imageSize' => ['minWidth' => 300, 'minHeight' => 300],
Expand Down
5 changes: 0 additions & 5 deletions src/FileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
*/
class FileManager extends Component
{
/**
* @var string Session variable name
*/
public $sessionName = 'filemanager.uploads';

/**
* @internal
*/
Expand Down
15 changes: 15 additions & 0 deletions src/actions/UploadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class UploadAction extends Action
* @var bool $saveAfterUpload Save after upload
*/
public $saveAfterUpload = false;
/**
* @var callable $onSuccess Function to be returned after successful upload instead of responce. Function signature
* is ```function (File $file, ActiveRecord $model){}```, where `File` is the model that's configured in `createFile`
* option of model's file behavior configuration
* @since 5.3.0
*/
public $onSuccess;
/**
* @var ActiveRecord $model
*/
Expand Down Expand Up @@ -111,6 +118,14 @@ private function upload($file)
if (count($presetAfterUpload)) {
$this->applyPreset($presetAfterUpload, $file);
}
if ($this->onSuccess) {
$responce = call_user_func($this->onSuccess, $file, $this->model);
if (is_array($responce)) {
return $this->controller->asJson($responce);
} else {
return $responce;
}
}
$template = $this->model->fileOption($this->attribute, 'template');
if ($template) {
return $this->response(
Expand Down
Loading