Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/unused.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}

- name: Detect unused packages
run: composer-unused -vvv --profile --ansi --no-interaction --no-progress --excludePackage=php --excludePackage=tatter/alerts --excludePackage=tatter/assets --excludePackage=tatter/audits
run: composer-unused -vvv --profile --ansi --no-interaction --no-progress --excludePackage=php --excludePackage=tatter/alerts --excludePackage=tatter/assets --excludePackage=tatter/audits --excludePackage=tatter/preferences --excludePackage=tatter/thumbnails
49 changes: 49 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Upgrade Guide

## Version 2 to 3
***

* Switches to `Tatter\Preferences` for managing persistent settings; read more below
* Drops `Tatter\Audits` as a dependency and adds it as a suggestion; read more below

### `Settings` Migration

`Preferences` relies on `CodeIgniter\Settings` instead of the abandoned `Tatter\Settings`, but
both packages had migrations for a `settings` database table and the schemas are not compatible.
You should archive any global and user-specific settings you would like to keep, then drop
or rename the old table. You may also need to update your `migrations` table in case your
project complains about a "gap in the migrations". Read more on the migration process at the
[Tatter\Settings](https://github.com/tattersoftware/codeigniter4-settings) repo.

### Audits

In order to simplify this library `Tatter\Audits` is no longer included by default. If you
want that level of user-specific logging to database changes then you may install the package
and provide a model extension with the events to reenable. You may also need to update your
`migrations` table in case your project complains about a "gap in the migrations".

Installation:
```bash
composer require tatter/audits
php spark migrate --all
```

Example model file in **app/Models/FileModel.php**:
```
<?php

namespace App\Models;

use Tatter\Audits\Traits\AuditsTrait;
use Tatter\Files\Models\FileModel as BaseModel;

class FileModel extends BaseModel
{
use AuditsTrait;

// Audits
protected $afterInsert = ['auditInsert'];
protected $afterUpdate = ['auditUpdate'];
protected $afterDelete = ['auditDelete'];
}
```
26 changes: 10 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,19 @@
],
"require": {
"php": "^7.3 || ^8.0",
"components/jquery": "^3.3",
"enyo/dropzone": "^5.7",
"fortawesome/font-awesome": "^5.8",
"codeigniter4/authentication-implementation": "^1.0",
"enyo/dropzone": "^6.0",
"tatter/alerts": "^2.0",
"tatter/assets": "^2.2",
"tatter/audits": "^1.0",
"tatter/exports": "^2.0",
"tatter/frontend": "^1.0",
"tatter/permits": "^2.0",
"tatter/settings": "^1.0 || ^2.0",
"tatter/thumbnails": "^1.2",
"twbs/bootstrap": "^4.5"
"tatter/preferences": "^1.0",
"tatter/thumbnails": "^1.2"
},
"require-dev": {
"antecedent/patchwork": "^2.1",
"codeigniter4/codeigniter4": "dev-develop",
"myth/auth": "dev-develop",
"tatter/imposter": "^1.0",
"tatter/tools": "^1.15"
},
"autoload": {
Expand All @@ -55,19 +52,16 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/codeigniter4/CodeIgniter4",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/lonnieezell/myth-auth",
"no-api": true
"url": "https://github.com/codeigniter4/CodeIgniter4.git"
},
{
"type": "composer",
"url": "https://asset-packagist.org"
}
],
"suggest": {
"tatter/audits": "Adds logging for user changes to Files database rows."
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
Expand Down
5 changes: 2 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ parameters:
- '#Cannot access property \$[a-z]+ on array\|object#'
- '#Cannot call method [A-Za-z]+\(\) on array\|object#'
- '#Unsafe usage of new static\(\)*#'
- '#Call to an undefined static method Config\\Services::authentication\(\)#'
- '#Function Patchwork\\redefine not found#'
universalObjectCratesClasses:
- CodeIgniter\Entity
- Faker\Generator
scanDirectories:
- vendor/codeigniter4/codeigniter4/system/Helpers
- vendor/myth/auth/src/Helpers
- vendor/tatter/alerts/src/Helpers
- vendor/tatter/handlers/src/Helpers
- vendor/tatter/imposter/src/Helpers
- vendor/tatter/preferences/src/Helpers
dynamicConstantNames:
- APP_NAMESPACE
- CI_DEBUG
Expand Down
18 changes: 18 additions & 0 deletions src/Bundles/DropzoneBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Tatter\Files\Bundles;

use Tatter\Frontend\FrontendBundle;

class DropzoneBundle extends FrontendBundle
{
/**
* Applies any initial inputs after the constructor.
*/
protected function define(): void
{
$this
->addPath('dropzone/dropzone.css')
->addPath('dropzone/dropzone-min.js');
}
}
21 changes: 21 additions & 0 deletions src/Bundles/FilesBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tatter\Files\Bundles;

use Tatter\Assets\Bundle;
use Tatter\Frontend\Bundles\BootstrapBundle;
use Tatter\Frontend\Bundles\FontAwesomeBundle;

class FilesBundle extends Bundle
{
/**
* Applies any initial inputs after the constructor.
*/
protected function define(): void
{
$this
->merge(new BootstrapBundle())
->merge(new DropzoneBundle())
->merge(new FontAwesomeBundle());
}
}
94 changes: 73 additions & 21 deletions src/Config/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,17 @@
namespace Tatter\Files\Config;

use CodeIgniter\Config\BaseConfig;
use Tatter\Files\Exceptions\FilesException;

class Files extends BaseConfig
{
/**
* Directory to store files (with trailing slash)
*
* @var string
*/
public $storagePath = WRITEPATH . 'files/';

/**
* Whether to include routes to the Files Controller.
*
* @var bool
*/
public $routeFiles = true;

/**
* Layouts to use for general access and for administration
*
* @var array<string, string>
*/
public $layouts = [
'public' => 'Tatter\Files\Views\layout',
'manage' => 'Tatter\Files\Views\layout',
];

/**
* View file aliases
*
Expand All @@ -40,16 +24,84 @@ class Files extends BaseConfig
];

/**
* Default display format; built in are 'cards', 'list', 'select'
* Path to the default thumbnail file
*
* @var string
*/
public $defaultFormat = 'cards';
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';

//--------------------------------------------------------------------
// Display Preferences
//--------------------------------------------------------------------

/**
* Path to the default thumbnail file
* Display format for listing files.
* Included options are 'cards', 'list', 'select'
*
* @var string
*/
public $defaultThumbnail = 'Tatter\Files\Assets\Unavailable.jpg';
public $format = 'cards';

/**
* Default sort column.
* See FileModel::$allowedFields for options.
*
* @var string
*/
public $sort = 'filename';

/**
* Default sort ordering. "asc" or "desc"
*
* @var string
*/
public $order = 'asc';

//--------------------------------------------------------------------
// Storage Options
//--------------------------------------------------------------------

/**
* Directory to store files (with trailing slash).
* Usually best to use getPath()
*
* @var string
*/
protected $path = WRITEPATH . 'files' . DIRECTORY_SEPARATOR;

/**
* Normalizes and creates (if necessary) the storage and thumbnail paths,
* returning the normalized storage path.
*
* @throws FilesException
*/
public function getPath(): string
{
$storage = $this->path;

// Verify the storage directory
if (! is_dir($storage) && ! @mkdir($storage, 0775, true)) {
throw FilesException::forDirFail($storage);
}

// Normalize the storage path
$this->path = realpath($storage) ?: $storage;
$this->path = rtrim($storage, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

// Check or create the thumbnails subdirectory
$thumbnails = $storage . 'thumbnails';
if (! is_dir($thumbnails) && ! @mkdir($thumbnails, 0775, true)) {
throw FilesException::forDirFail($thumbnails); // @codeCoverageIgnore
}

return $storage;
}

/**
* Changes the storage path value. Mostly just for testing.
*/
public function setPath(string $path)
{
$this->path = $path;
}
}
9 changes: 2 additions & 7 deletions src/Config/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

namespace Tatter\Files\Config;

/**
* Class Registrar
*
* Provides a basic registrar class for testing BaseConfig registration functions.
*/
class Registrar
{
/**
* Override database config
* Adds the Files option to available Pager templates.
*
* @return array
* @return array<string,mixed>
*/
public static function Pager()
{
Expand Down
7 changes: 6 additions & 1 deletion src/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
return;
}

$options = [
'filter' => 'assets:\Tatter\Files\Bundles\FilesBundle',
'namespace' => '\Tatter\Files\Controllers',
];

// Routes to Files controller
$routes->group('files', ['namespace' => '\Tatter\Files\Controllers'], static function ($routes) {
$routes->group('files', $options, static function ($routes) {
$routes->get('/', 'Files::index');
$routes->get('user', 'Files::user');
$routes->get('user/(:any)', 'Files::user/$1');
Expand Down
Loading