Skip to content

Commit

Permalink
fix: continue with patching old tests and wrong configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed May 22, 2024
1 parent 48fe2c6 commit a2541b4
Show file tree
Hide file tree
Showing 22 changed files with 135 additions and 1,125 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ npm-debug.log
/public
/resources
.phpunit.result.cache
/app
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require": {
"silverstripe/cms": "^4.0 || ^5.0",
"symbiote/silverstripe-gridfieldextensions": "*",
"silverstripe/asset-admin": "*",
"silverstripe/taxonomy": "*"
},
"suggest": {
Expand Down
53 changes: 28 additions & 25 deletions docs/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@ project root directory:

```yaml
DMS:
folder_name: my-custom-folder
folder_name: my-custom-folder
```
## Enable/disable documents/sets for a specific page type
If you don't need documents/document sets for a specific page type you can disable this with YAML configuration:
```yaml
MyPageType:
documents_enabled: false
documents_enabled: false
```
Likewise, you could override a previously set configuration value by setting this back to `true` in a configuration
Expand All @@ -38,12 +37,13 @@ To add extra allowed file extensions purely for DMS documents, you can update th

```yaml
DMSDocumentAddController:
allowed_extensions:
- php
- php5
allowed_extensions:
- php
- php5
```

## Adding fields to the Query Builder

Query builder fields are read from the DMSDocument::searchable_fields property set in [querybuilder.yml](../../_config/querybuilder.yml). Some default fields are provided and can be customised
by modifying the field and/or filter properties of a field or adding a new field entirely.

Expand All @@ -54,21 +54,21 @@ The default searchable filters available to query builder is as follows:

```yaml
DMSDocument:
searchable_fields:
Title:
title: "Document title matches ..."
Description:
title: "Document summary matches ..."
CreatedByID:
title: 'Document created by ...'
field: 'ListboxField'
filter: 'ExactMatchFilter'
LastEditedByID:
title: 'Document last changed by ...'
field: 'ListboxField'
filter: 'ExactMatchFilter'
Filename:
title: 'File name'
searchable_fields:
Title:
title: "Document title matches ..."
Description:
title: "Document summary matches ..."
CreatedByID:
title: "Document created by ..."
field: "ListboxField"
filter: "ExactMatchFilter"
LastEditedByID:
title: "Document last changed by ..."
field: "ListboxField"
filter: "ExactMatchFilter"
Filename:
title: "File name"
```

## Change the shortcode handler
Expand All @@ -77,15 +77,18 @@ If you need to change the `dms_document_link` shortcode handler for some reason,
and some PHP:

```yaml
DMS:
shortcode_handler_key: your_shortcode
Sunnysideup\DMS\DMS:
shortcode_handler_key: your_shortcode
```

And for example in `_config.php`:

```php
use Sunnysideup\DMS\DMS;
use Sunnysideup\DMS\DMSShortcodeHandler;
ShortcodeParser::get('default')->register(
Config::inst()->get('DMS', 'shortcode_handler_key'),
array('DMSShortcodeHandler', 'handle')
Config::inst()->get(DMS::class, 'shortcode_handler_key'),
[DMSShortcodeHandler::class, 'handle']
);
```
28 changes: 14 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/.</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">src/.</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 2 additions & 0 deletions src/DMS.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ class DMS
use Configurable;

private static $folder_name = 'dms';

private static $shortcode_handler_key = 'dms';
}
35 changes: 35 additions & 0 deletions src/DMSShortcodeHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Sunnysideup\DMS;

use SilverStripe\View\Parsers\ShortcodeParser;
use Sunnysideup\DMS\Model\DMSDocument;

class DMSShortcodeHandler
{
public static function handle($arguments, $content, ShortcodeParser $parser, $tag, array $extra = [])
{
if (!empty($arguments['id'])) {
$document = DMSDocument::get()->byID($arguments['id']);

if ($document && !$document->isHidden()) {
if ($content) {
return sprintf(
'<a href="%s">%s</a>',
$document->Link(),
$parser->parse($content)
);
}

if (isset($extra['element'])) {
$extra['element']->setAttribute('data-ext', $document->getExtension());
$extra['element']->setAttribute('data-size', $document->getFileSizeFormatted());
}

return $document->Link();
}
}

return '';
}
}
9 changes: 5 additions & 4 deletions src/Model/DMSDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use Sunnysideup\DMS\Admin\DMSDocumentAdmin;;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Security\Security;

/**
* @package dms
Expand Down Expand Up @@ -373,12 +374,12 @@ public function getPermissionsActionPanel()

public function onBeforeWrite()
{
// Set user fields
if ($currentUserID = Member::currentUserID()) {
if ($currentUser = Security::getCurrentUser()) {
if (!$this->CreatedByID) {
$this->CreatedByID = $currentUserID;
$this->CreatedByID = $currentUser->ID;
}
$this->LastEditedByID = $currentUserID;

$this->LastEditedByID = $currentUser->ID;
}

if ($this->TempFileID) {
Expand Down
64 changes: 0 additions & 64 deletions src/Tasks/MakeDMSTablesObsolete.php

This file was deleted.

Loading

0 comments on commit a2541b4

Please sign in to comment.