Skip to content

Commit 6226cb1

Browse files
authored
Merge pull request #18 from tattersoftware/session-fix
Session fix
2 parents c734287 + 7c4b2c2 commit 6226cb1

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

composer.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@
7272
"minimum-stability": "dev",
7373
"prefer-stable": true,
7474
"scripts": {
75-
"post-update-cmd": [
76-
"composer dump-autoload"
77-
],
7875
"analyze": "phpstan analyze",
7976
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 src/ tests/",
8077
"test": "phpunit"

src/Controllers/Files.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ public function upload()
417417
// Check for more chunks
418418
if ($chunkIndex < $totalChunks - 1)
419419
{
420+
session_write_close();
420421
return '';
421422
}
422423

@@ -432,9 +433,13 @@ public function upload()
432433
// Accept the file
433434
$file = $this->model->createFromPath($path ?? $upload->getRealPath(), $data);
434435

435-
return $this->request->isAJAX()
436-
? ''
437-
: redirect()->back()->with('message', lang('File.uploadSucces', [$file->clientname]));;
436+
if ($this->request->isAJAX())
437+
{
438+
session_write_close();
439+
return '';
440+
}
441+
442+
return redirect()->back()->with('message', lang('File.uploadSucces', [$file->clientname]));
438443
}
439444

440445
/**

src/Views/Dropzone/config.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// Limit files to the MB equivalent of 500 chunks
1212
$maxFileSize = round($chunkSize * 500 / 1024 / 1024, 1);
13-
?>
13+
?>
1414
Dropzone.options.filesDropzone = {
1515

1616
// Reload file list after uploads
@@ -22,10 +22,7 @@
2222

2323
// Maximum file size in MB
2424
maxFilesize: <?= $maxFileSize ?>,
25-
26-
// Disable parallel uploads
27-
// (CodeIgniter4 Sessions chokes on interspersed AJAX calls)
28-
parallelUploads: 1,
25+
timeout: 0,
2926

3027
// Enable chunking
3128
chunking: true,

src/Views/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
</div>
6969
</div>
7070

71+
<?= $this->endSection() ?>
72+
<?= $this->section('footerAssets') ?>
73+
7174
<?= view(config('Files')->views['dropzone']) ?>
7275

7376
<?= $this->endSection() ?>

tests/_support/FeatureTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use CodeIgniter\Config\Factories;
44
use Config\Services;
55
use Tatter\Files\Models\FileModel;
6+
use Tests\Support\Models\UserModel;
67

78
class FeatureTestCase extends FilesTestCase
89
{
@@ -37,6 +38,9 @@ protected function setUp(): void
3738
parent::setUp();
3839

3940
$this->resetAuthServices();
41+
42+
// Make sure we use the correct UserModel for permissions
43+
Factories::injectMock('models', UserModel::class, new UserModel());
4044
}
4145

4246
/**

0 commit comments

Comments
 (0)