Skip to content

Commit ab47935

Browse files
authored
Merge pull request #19 from tattersoftware/exports
Export Records
2 parents 09d3bee + caa414d commit ab47935

File tree

8 files changed

+176
-41
lines changed

8 files changed

+176
-41
lines changed

.github/workflows/analyze.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,20 @@ on:
2222

2323
jobs:
2424
build:
25-
name: Analyze code
25+
name: PHP ${{ matrix.php-versions }} Static Analysis
2626
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
php-versions: ['7.3', '7.4']
2731
steps:
2832
- name: Checkout
2933
uses: actions/checkout@v2
3034

3135
- name: Setup PHP
3236
uses: shivammathur/setup-php@v2
3337
with:
34-
php-version: latest
38+
php-version: ${{ matrix.php-versions }}
3539
tools: composer, pecl, phpunit
3640
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
3741

@@ -60,7 +64,7 @@ jobs:
6064
restore-keys: ${{ runner.os }}-phpstan-
6165

6266
- name: Install dependencies
63-
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
67+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
6468
env:
6569
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
6670

.github/workflows/test.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ on:
44
pull_request:
55
branches:
66
- develop
7+
push:
8+
branches:
9+
- develop
710

811
jobs:
912
main:
10-
name: Build and test
13+
name: PHP ${{ matrix.php-versions }} Unit Tests
1114

1215
strategy:
1316
matrix:
14-
php-versions: ['7.2', '7.3', '7.4']
17+
php-versions: ['7.3', '7.4']
1518

1619
runs-on: ubuntu-latest
1720

@@ -41,9 +44,29 @@ jobs:
4144
restore-keys: ${{ runner.os }}-composer-
4245

4346
- name: Install dependencies
44-
run: composer install --no-progress --no-suggest --no-interaction --prefer-dist --optimize-autoloader
47+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
4548
env:
4649
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
4750

4851
- name: Test with PHPUnit
4952
run: vendor/bin/phpunit --verbose --coverage-text
53+
54+
- if: matrix.php-versions == '7.4'
55+
name: Run Coveralls
56+
run: |
57+
composer global require php-coveralls/php-coveralls:^2.4
58+
php-coveralls --coverage_clover=build/logs/clover.xml -v
59+
env:
60+
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
COVERALLS_PARALLEL: true
62+
COVERALLS_FLAG_NAME: PHP ${{ matrix.php-versions }} - ${{ matrix.db-platforms }}
63+
64+
coveralls:
65+
needs: [main]
66+
runs-on: ubuntu-latest
67+
steps:
68+
- name: Coveralls Finished
69+
uses: coverallsapp/github-action@master
70+
with:
71+
github-token: ${{ secrets.GITHUB_TOKEN }}
72+
parallel-finished: true

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Release Notes
2+
3+
## [Unreleased](https://github.com/tattersoftware/codeigniter4-files/compare/v2.2.1...develop)
4+
5+
## [v2.2.1 (2021-01-19)](https://github.com/tattersoftware/codeigniter4-files/compare/v2.2.0...v2.2.1)
6+
7+
- Removed unused `downloads` table and added in `exports` ([](https://github.com/tattersoftware/codeigniter4-files/commit/8ba3902879bb6f997d802901927867096b7fa7a5))

composer.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "tatter/files",
3+
"type": "library",
34
"description": "File uploads and management, for CodeIgniter 4",
45
"keywords": [
56
"codeigniter",
@@ -19,7 +20,7 @@
1920
}
2021
],
2122
"require": {
22-
"php": ">=7.2",
23+
"php": "^7.3",
2324
"components/jquery": "^3.3",
2425
"enyo/dropzone": "^5.7",
2526
"fortawesome/font-awesome": "^5.8",
@@ -36,17 +37,16 @@
3637
"antecedent/patchwork": "^2.1",
3738
"codeigniter4/codeigniter4": "dev-develop",
3839
"codeigniter4/codeigniter4-standard": "^1.0",
39-
"fzaninotto/faker": "^1.9@dev",
40-
"mikey179/vfsstream": "^1.6",
4140
"myth/auth": "dev-develop",
42-
"phpstan/phpstan": "^0.12",
43-
"phpunit/phpunit": "^8.5",
44-
"squizlabs/php_codesniffer": "^3.5"
41+
"tatter/tools": "^1.3"
4542
},
4643
"autoload": {
4744
"psr-4": {
4845
"Tatter\\Files\\": "src"
49-
}
46+
},
47+
"exclude-from-classmap": [
48+
"**/Database/Migrations/**"
49+
]
5050
},
5151
"autoload-dev": {
5252
"psr-4": {
@@ -73,7 +73,7 @@
7373
"prefer-stable": true,
7474
"scripts": {
7575
"analyze": "phpstan analyze",
76-
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 src/ tests/",
76+
"style": "phpcbf --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
7777
"test": "phpunit"
7878
}
7979
}

phpunit.xml.dist

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
bootstrap="vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php"
34
backupGlobals="false"
45
colors="true"
56
convertErrorsToExceptions="true"
@@ -8,34 +9,39 @@
89
stopOnError="false"
910
stopOnFailure="false"
1011
stopOnIncomplete="false"
11-
stopOnSkipped="false">
12+
stopOnSkipped="false"
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
14+
15+
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
16+
<include>
17+
<directory suffix=".php">./src</directory>
18+
</include>
19+
<exclude>
20+
<directory suffix=".php">./src/Views</directory>
21+
<file>./src/Config/Routes.php</file>
22+
</exclude>
23+
<report>
24+
<clover outputFile="build/logs/clover.xml"/>
25+
<html outputDirectory="build/logs/html"/>
26+
<php outputFile="build/logs/coverage.serialized"/>
27+
<text outputFile="php://stdout" showUncoveredFiles="false"/>
28+
</report>
29+
</coverage>
30+
1231
<testsuites>
1332
<testsuite name="app">
1433
<directory>./tests</directory>
1534
</testsuite>
1635
</testsuites>
1736

18-
<filter>
19-
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
20-
<directory suffix=".php">./src</directory>
21-
<exclude>
22-
<directory suffix=".php">./src/Views</directory>
23-
<file>./src/Config/Routes.php</file>
24-
</exclude>
25-
</whitelist>
26-
</filter>
27-
2837
<logging>
29-
<log type="coverage-html" target="build/logs/html"/>
30-
<log type="coverage-clover" target="build/logs/clover.xml"/>
31-
<log type="coverage-php" target="build/logs/coverage.serialized"/>
32-
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>
33-
<log type="testdox-html" target="build/logs/testdox.html"/>
34-
<log type="testdox-text" target="build/logs/testdox.txt"/>
35-
<log type="junit" target="build/logs/logfile.xml"/>
38+
<testdoxHtml outputFile="build/logs/testdox.html"/>
39+
<testdoxText outputFile="build/logs/testdox.txt"/>
40+
<junit outputFile="build/logs/logfile.xml"/>
3641
</logging>
3742

3843
<php>
44+
<env name="XDEBUG_MODE" value="coverage"/>
3945
<server name="app.baseURL" value="http://example.com"/>
4046

4147
<!-- Directory containing phpunit.xml -->
@@ -47,13 +53,17 @@
4753
<!-- Directory containing the front controller (index.php) -->
4854
<const name="PUBLICPATH" value="./vendor/codeigniter4/codeigniter4/public/"/>
4955

50-
<!-- <env name="database.tests.hostname" value="localhost"/> -->
51-
<!-- <env name="database.tests.database" value="tests"/> -->
52-
<!-- <env name="database.tests.username" value="tests_user"/> -->
53-
<!-- <env name="database.tests.password" value=""/> -->
54-
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
55-
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
56-
<env name="database.tests.database" value=":memory:"/>
57-
<env name="database.tests.DBDriver" value="SQLite3"/>
56+
<!-- https://getcomposer.org/xdebug -->
57+
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
58+
59+
<!-- Database configuration -->
60+
<!-- Uncomment to use alternate testing database configuration
61+
<env name="database.tests.hostname" value="localhost"/>
62+
<env name="database.tests.database" value="tests"/>
63+
<env name="database.tests.username" value="tests_user"/>
64+
<env name="database.tests.password" value=""/>
65+
<env name="database.tests.DBDriver" value="MySQLi"/>
66+
<env name="database.tests.DBPrefix" value="tests_"/>
67+
-->
5868
</php>
5969
</phpunit>

src/Controllers/Files.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Tatter\Files\Config\Files as FilesConfig;
1010
use Tatter\Files\Exceptions\FilesException;
1111
use Tatter\Files\Entities\File;
12+
use Tatter\Files\Models\ExportModel;
1213
use Tatter\Files\Models\FileModel;
1314

1415
class Files extends Controller
@@ -522,6 +523,13 @@ public function export(string $slug, $fileId): ResponseInterface
522523
return redirect()->back();
523524
}
524525

526+
// Create the record
527+
model(ExportModel::class)->insert([
528+
'handler' => $slug,
529+
'file_id' => $file->id,
530+
'user_id' => user_id() ?: null
531+
]);
532+
525533
// Pass to the handler
526534
$export = new $handler($file->object);
527535
$response = $export->setFilename($file->filename)->process();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace Tatter\Files\Database\Migrations;
2+
3+
use CodeIgniter\Database\Migration;
4+
5+
class CreateExports extends Migration
6+
{
7+
public function up()
8+
{
9+
// Remove the unused downloads table
10+
$this->forge->dropTable('downloads');
11+
12+
// Create the exports table
13+
$fields = [
14+
'handler' => ['type' => 'varchar', 'constraint' => 63],
15+
'file_id' => ['type' => 'int', 'unsigned' => true],
16+
'user_id' => ['type' => 'int', 'unsigned' => true, 'null' => true],
17+
'created_at' => ['type' => 'datetime', 'null' => true],
18+
];
19+
20+
$this->forge->addField('id');
21+
$this->forge->addField($fields);
22+
23+
$this->forge->addKey('handler');
24+
$this->forge->addKey('file_id');
25+
$this->forge->addKey('user_id');
26+
27+
$this->forge->createTable('exports');
28+
}
29+
30+
public function down()
31+
{
32+
// Restore downloads table
33+
$fields = [
34+
'file_id' => ['type' => 'int', 'unsigned' => true],
35+
'user_id' => ['type' => 'int', 'unsigned' => true],
36+
'created_at' => ['type' => 'datetime', 'null' => true],
37+
];
38+
39+
$this->forge->addField('id');
40+
$this->forge->addField($fields);
41+
42+
$this->forge->addKey(['file_id', 'user_id']);
43+
$this->forge->addKey(['user_id', 'file_id']);
44+
45+
$this->forge->createTable('downloads');
46+
47+
// Drop exports
48+
$this->forge->dropTable('exports');
49+
}
50+
}

src/Models/ExportModel.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php namespace Tatter\Files\Models;
2+
3+
use CodeIgniter\Files\File as CIFile;
4+
use CodeIgniter\Model;
5+
use Tatter\Files\Entities\File;
6+
use Tatter\Files\Exceptions\FilesException;
7+
use Tatter\Thumbnails\Exceptions\ThumbnailsException;
8+
9+
/**
10+
* Export Model
11+
*
12+
* Used to track records for file
13+
* exports.
14+
*/
15+
class ExportModel extends Model
16+
{
17+
protected $table = 'exports';
18+
protected $primaryKey = 'id';
19+
protected $returnType = 'object';
20+
21+
protected $useTimestamps = true;
22+
protected $updatedField = '';
23+
protected $useSoftDeletes = false;
24+
protected $skipValidation = false;
25+
26+
protected $allowedFields = ['handler', 'file_id', 'user_id'];
27+
28+
protected $validationRules = [
29+
'handler' => 'required|max_length[63]',
30+
'file_id' => 'required|integer',
31+
'user_id' => 'permit_empty|integer',
32+
];
33+
}

0 commit comments

Comments
 (0)