diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 00000000..f998e4cb
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,17 @@
+name: CI
+
+on:
+ push:
+ pull_request:
+ workflow_dispatch:
+
+jobs:
+ ci:
+ name: CI
+ uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1
+ with:
+ dynamic_matrix: false
+ extra_jobs: |
+ - php: '8.1'
+ db: mysql80
+ phpunit: true
diff --git a/.gitignore b/.gitignore
index 1ca95717..436f77a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,7 @@
node_modules/
npm-debug.log
+/composer.lock
+/vendor
+/public
+/resources
+.phpunit.result.cache
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 651eec7e..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,40 +0,0 @@
-# See https://github.com/silverstripe/silverstripe-travis-support for setup details
-
-language: php
-
-php:
- - 5.3
- - 5.4
- - 5.5
- - 5.6
-
-dist: precise
-
-env:
- - DB=MYSQL CORE_RELEASE=3.5
-
-matrix:
- include:
- - php: 7.1
- env: DB=MYSQL CORE_RELEASE=3.6
- - php: 7.1
- env: DB=MYSQL CORE_RELEASE=3 COVERAGE="--coverage-clover=coverage.xml"
-
-before_script:
- - echo -e "[server]\nmax_allowed_packet=64M" | sudo tee -a /etc/mysql/conf.d/dms.cnf
- - sudo service mysql restart
- - composer self-update || true
- - git clone git://github.com/silverstripe/silverstripe-travis-support.git ~/travis-support
- - php ~/travis-support/travis_setup.php --source `pwd` --target ~/build/ss --require undefinedoffset/sortablegridfield:~0.6.9
- - cd ~/build/ss
- - composer install
-
-script:
- - vendor/bin/phpunit "$COVERAGE" dms/tests
-
-after_success:
- - >
- test "$COVERAGE" != ""
- && mv coverage.xml ~/build/$TRAVIS_REPO_SLUG
- && cd ~/build/$TRAVIS_REPO_SLUG
- && bash <(curl -s https://codecov.io/bash)
diff --git a/.upgrade.yml b/.upgrade.yml
deleted file mode 100644
index 44455629..00000000
--- a/.upgrade.yml
+++ /dev/null
@@ -1,25 +0,0 @@
-mappings:
- DMS: Sunnysideup\DMS\DMS
- DMSShortcodeHandler: Sunnysideup\DMS\DMSShortcodeHandler
- MigrateToDocumentSetsTask: Sunnysideup\DMS\Tasks\MigrateToDocumentSetsTask
- DMSJsonField: Sunnysideup\DMS\Forms\DMSJsonField
- DMSGridFieldAddNewButton: Sunnysideup\DMS\Cms\DMSGridFieldAddNewButton
- DMSUploadField_ItemHandler: Sunnysideup\DMS\Cms\DMSUploadField_ItemHandler
- DMSGridFieldEditButton: Sunnysideup\DMS\Cms\DMSGridFieldEditButton
- DMSDocumentAddExistingField: Sunnysideup\DMS\Cms\DMSDocumentAddExistingField
- DocumentHTMLEditorFieldToolbar: Sunnysideup\DMS\Cms\DocumentHTMLEditorFieldToolbar
- DMSDocumentAddController: Sunnysideup\DMS\Cms\DMSDocumentAddController
- DMSUploadField: Sunnysideup\DMS\Cms\DMSUploadField
- DMSDocumentAdmin: Sunnysideup\DMS\Cms\DMSDocumentAdmin
- DMSGridFieldDetailForm_ItemRequest: Sunnysideup\DMS\Cms\DMSGridFieldDetailForm_ItemRequest
- DMSInterface: Sunnysideup\DMS\Interface\DMSInterface
- DMSDocumentInterface: Sunnysideup\DMS\Interface\DMSDocumentInterface
- DMSDocumentTaxonomyExtension: Sunnysideup\DMS\Extensions\DMSDocumentTaxonomyExtension
- DMSTaxonomyTypeExtension: Sunnysideup\DMS\Extensions\DMSTaxonomyTypeExtension
- DMSSiteTreeExtension: Sunnysideup\DMS\Extensions\DMSSiteTreeExtension
- FileNotFoundException: Sunnysideup\DMS\Exceptions\FileNotFoundException
- DMSDocument_versions: Sunnysideup\DMS\Model\DMSDocument_versions
- DMSDocument: Sunnysideup\DMS\Model\DMSDocument
- DMSDocumentController: Sunnysideup\DMS\Control\DMSDocumentController
- DMSDocumentSet: Sunnysideup\DMS\Model\DMSDocumentSet
- ShortCodeRelationFinder: Sunnysideup\DMS\Tools\ShortCodeRelationFinder
diff --git a/_config.php b/_config.php
deleted file mode 100644
index 8543412d..00000000
--- a/_config.php
+++ /dev/null
@@ -1,40 +0,0 @@
-register(
-// $config->get(DMS::class, 'shortcode_handler_key'),
-// array(DMSShortcodeHandler::class, 'handle')
-// );
-
-if ($config->get(DMSDocument_versions::class, 'enable_versions')) {
- //using the same db relations for the versioned documents, as for the actual documents
- // Config::modify()->update(DMSDocument_versions::class, 'db', $config->get(DMSDocument::class, 'db'));
-}
-
-// add dmsassets folder to file system sync exclusion
-if (strpos($config->get(DMS::class, 'folder_name'), 'assets/') === 0) {
- $folderName = substr($config->get(DMS::class, 'folder_name'), 7);
- // Config::modify()->update(Filesystem::class, 'sync_blacklisted_patterns', array("/^" . $folderName . "$/i",));
-}
diff --git a/_dev/Cms/DMSDocumentAdmin.php b/_dev/Cms/DMSDocumentAdmin.php
deleted file mode 100644
index 9b6d332e..00000000
--- a/_dev/Cms/DMSDocumentAdmin.php
+++ /dev/null
@@ -1,96 +0,0 @@
-Fields()->fieldByName($this->sanitiseClassName($this->modelClass));
- return $this->modifyGridField($form, $gridField);
- }
-
- /**
- * If the GridField is for DMSDocument then add a custom "add" button. If it's for DMSDocumentSet then
- * update the display fields to include some extra columns that are only for this ModelAdmin, so cannot
- * be added directly to the model's display fields.
- *
- * @param CMSForm $form
- * @param GridField $gridField
- * @return CMSForm
- */
- protected function modifyGridField(CMSForm $form, GridField $gridField)
- {
- $gridFieldConfig = $gridField->getConfig();
-
- $gridFieldConfig->removeComponentsByType(GridFieldEditButton::class);
- $gridFieldConfig->addComponent(new DMSGridFieldEditButton(), GridFieldDeleteAction::class);
-
- if ($this->modelClass === DMSDocument::class) {
- $gridFieldConfig->removeComponentsByType(GridFieldAddNewButton::class);
- $gridFieldConfig->addComponent(
- new DMSGridFieldAddNewButton('buttons-before-left'),
- GridFieldExportButton::class
- );
- } elseif ($this->modelClass === DMSDocumentSet::class) {
- $dataColumns = $gridFieldConfig->getComponentByType(GridFieldDataColumns::class);
- $fields = $dataColumns->getDisplayFields($gridField);
- $fields = array('Title' => 'Title', 'Page.Title' => 'Page') + $fields;
- $dataColumns->setDisplayFields($fields)
- ->setFieldFormatting(
- array(
- 'Page.Title' => function ($value, $item) {
- // Link a page click directly to the Document Set on the actual page
- if ($page = SiteTree::get()->byID($item->PageID)) {
- return sprintf(
- "$value",
- $page->CMSEditLink(),
- $page->DocumentSets()->count()
- );
- }
- }
- )
- );
- }
-
- return $form;
- }
-}
diff --git a/_dev/Cms/DMSGridFieldDetailForm.php b/_dev/Cms/DMSGridFieldDetailForm.php
deleted file mode 100644
index 23e9a7aa..00000000
--- a/_dev/Cms/DMSGridFieldDetailForm.php
+++ /dev/null
@@ -1,31 +0,0 @@
-record) {
- $numberOfPageRelations = $record->getRelatedPages()->count();
- $relations = new ShortCodeRelationFinder();
- $numberOfInlineRelations = $relations->findPageCount($record->ID);
-
- //add the number of pages attached to this field as a data-attribute
- $form->setAttribute('data-pages-count', $numberOfPageRelations);
- $form->setAttribute('data-relation-count', $numberOfInlineRelations);
- }
- return $form;
- }
-}
diff --git a/_dev/Cms/DMSGridFieldEditButton.php b/_dev/Cms/DMSGridFieldEditButton.php
deleted file mode 100755
index 64d24aab..00000000
--- a/_dev/Cms/DMSGridFieldEditButton.php
+++ /dev/null
@@ -1,34 +0,0 @@
- Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
- ));
-
- $template = $record->canEdit() ? GridFieldEditButton::class : GridFieldViewButton::class;
-
- return $data->renderWith($template);
- }
-}
diff --git a/_dev/_manifest_exclude b/_dev/_manifest_exclude
deleted file mode 100644
index e69de29b..00000000
diff --git a/_dev/javascript/DMSDocumentAddExistingField.js b/_dev/javascript/DMSDocumentAddExistingField.js
deleted file mode 100644
index 0f08682c..00000000
--- a/_dev/javascript/DMSDocumentAddExistingField.js
+++ /dev/null
@@ -1,135 +0,0 @@
-(function ($) {
- "use strict";
-
- $.entwine('ss', function ($) {
- $('.document-add-existing').entwine({
- adddocument: function (document_id) {
- var documentSetId = $(this).closest('form').find('input[name="DSID"]').val();
-
- jQuery.ajax(
- 'admin/pages/adddocument/linkdocument?dsid=' + documentSetId + '&documentID=' + document_id,
- {
- dataType: 'json',
- success: function (data, textstatus) {
- var fn = window.tmpl.cache['ss-uploadfield-addtemplate'];
- var fnout = fn({
- files: [data],
- formatFileSize: function (bytes) {
- if (typeof bytes !== 'number') {
- return '';
- }
- if (bytes >= 1000000000) {
- return (bytes / 1000000000).toFixed(2) + ' GB'
- }
- if (bytes >= 1000000) {
- return (bytes / 1000000).toFixed(2) + ' MB';
- }
- return (bytes / 1000).toFixed(2) + ' KB';
- }
- });
-
- $('.ss-add-files').append(fnout);
- }
- }
- );
- },
- selectdocument: function (documentID, documentName) {
- if (typeof(documentID) !== "undefined") {
- // Substitute the ID for the full document name, if no name is present
- if (typeof(documentName) === "undefined") {
- documentName = documentID;
- }
- $('.ss-add-files').html('
'+documentName+'
');
- } else {
- $('.ss-add-files').html('');
- }
- }
- });
-
- $('.document-add-existing .document-autocomplete').entwine({
- onmatch: function () {
- var self = this;
- this.autocomplete({
- source: 'admin/pages/adddocument/documentautocomplete',
- select: function (event, ui) {
- if (ui.item) {
- if (self.closest('.document-add-existing').hasClass('link-editor-context')) {
- $(this).closest('.document-add-existing').selectdocument(ui.item.value, ui.item.label);
- } else {
- $(this).closest('.document-add-existing').adddocument(ui.item.value);
- }
-
- $(this).val('');
-
- return false;
- }
- }
- });
- }
- });
-
- // Add label to tree drop down button
- $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
- onmatch: function () {
- this.prepend('Browse by page');
- }
- });
-
- $('.document-add-existing .TreeDropdownField').entwine({
- onpanelshow: function () {
- $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', true);
- },
- onpanelhide: function () {
- $(this)
- .closest('.document-add-existing')
- .find('input.document-autocomplete')
- .prop('disabled', $(this).closest('.document-add-existing').find('.document-list:visible').length > 0);
- }
- });
-
- $('.document-add-existing input[name=PageSelector]').entwine({
- onchange: function (event) {
- var doclist = $(this).closest('.document-add-existing').find('.document-list');
- doclist.html('Loading...
');
- doclist.show();
- doclist.load(
- 'admin/pages/adddocument/documentlist?pageID=' + $(this).val()
- );
- }
- });
-
- $('.document-add-existing a.add-document').entwine({
- onclick: function (event) {
- var document_id = this.data('document-id');
- var dae = this.closest('.document-add-existing');
-
- if (dae.hasClass('link-editor-context')) {
- dae.selectdocument(document_id, this.text());
- } else {
- dae.adddocument(document_id);
- }
-
- $(this).closest('.document-list').hide();
- $(this).closest('.document-add-existing').find('input.document-autocomplete').prop('disabled', false);
-
- return false;
- }
- });
-
- $('body').entwine({
- onclick: function (event) {
- $('.document-list:visible')
- .hide()
- .closest('.document-add-existing')
- .find('input.document-autocomplete')
- .prop('disabled', false);
- }
- });
-
- $('.document-add-existing .treedropdownfield-toggle-panel-link').entwine({
- onclick: function (event) {
- $('.document-list:visible').hide();
- }
- });
- });
-}(jQuery));
diff --git a/_dev/javascript/DMSGridField.js b/_dev/javascript/DMSGridField.js
deleted file mode 100644
index 53789fdc..00000000
--- a/_dev/javascript/DMSGridField.js
+++ /dev/null
@@ -1,24 +0,0 @@
-(function ($) {
- "use strict";
-
- $.entwine('ss', function ($) {
- $('.ss-gridfield-item a.file-url').entwine({
- onclick: function (e) {
- // Make sure the download link doesn't trigger a gridfield edit dialog
- window.open(this.attr('href'), '_blank');
-
- e.preventDefault();
- return false;
- }
- });
-
- $('.ss-gridfield-item a.dms-doc-sets-link').entwine({
- onclick: function (e) {
- // Prevent the initial flash of the gridfield's edit form
- e.preventDefault();
- document.location.href=this.attr('href');
- return false;
- }
- });
- });
-}(jQuery));
diff --git a/_dev/javascript/DMSUploadField_addtemplate.js b/_dev/javascript/DMSUploadField_addtemplate.js
deleted file mode 100644
index d1a70902..00000000
--- a/_dev/javascript/DMSUploadField_addtemplate.js
+++ /dev/null
@@ -1,30 +0,0 @@
-window.tmpl.cache['ss-uploadfield-addtemplate'] = tmpl(
- '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i' +
- '' +
- '' +
- ' ' +
- '' +
- '
' +
- '{% if (file.error) { %}' +
- '
' +
- '
' +
- '
' +
- '{% } else { %}' +
- '
{% print(file.buttons, true); %}
' +
- '{% } %}' +
- '
' +
- '{% if (!file.error) { %}' +
- '' +
- '{% } %}' +
- '' +
- '{% } %}'
-);
diff --git a/_dev/javascript/DMSUploadField_downloadtemplate.js b/_dev/javascript/DMSUploadField_downloadtemplate.js
deleted file mode 100644
index e0a93b4f..00000000
--- a/_dev/javascript/DMSUploadField_downloadtemplate.js
+++ /dev/null
@@ -1,27 +0,0 @@
-window.tmpl.cache['ss-dmsuploadfield-downloadtemplate'] = tmpl(
- '{% for (var i=0, files=o.files, l=files.length, file=files[0]; i' +
- '' +
- '' +
- ' ' +
- '' +
- '
' +
- '{% if (file.error) { %}' +
- '
' +
- '
' +
- '
' +
- '{% } else { %}' +
- '
(please click save and the page will update)
' +
- '{% } %}' +
- '
' +
- '' +
- '{% } %}'
-);
diff --git a/_dev/javascript/DocumentHtmlEditorFieldToolbar.js b/_dev/javascript/DocumentHtmlEditorFieldToolbar.js
deleted file mode 100755
index 0f34b9a6..00000000
--- a/_dev/javascript/DocumentHtmlEditorFieldToolbar.js
+++ /dev/null
@@ -1,118 +0,0 @@
-(function ($) {
- "use strict";
-
- $.entwine('ss', function ($) {
- $('form.htmleditorfield-linkform input[name=LinkType]').entwine({
- onchange: function (e) {
- this._super(e);
-
- var form = $('form.htmleditorfield-linkform');
- var show = false;
-
- if (this.attr('value') === 'document') {
- if (this.is(':checked')) {
- show = true;
- }
- }
-
- // Hide or show the additional document link addition tool
- if (show) {
- form.find('.ss-add').show();
- } else {
- form.find('.ss-add').hide();
- }
- },
- onadd: function (e) {
- this.change();
- }
- });
-
- $('form.htmleditorfield-linkform').entwine({
- getShortcodeKey: function () {
- return this.find(':input[name=DMSShortcodeHandlerKey]').val();
- },
- insertLink: function () {
- var href, target = null;
- var checkedValue = this.find(':input[name=LinkType]:checked').val();
- if (checkedValue === 'document') {
- href = '[' + this.getShortcodeKey() + ',id=' + this.find('.selected-document').data('document-id') + ']';
-
- // Determine target
- if (this.find(':input[name=TargetBlank]').is(':checked')) {
- target = '_blank';
- }
-
- var attributes = {
- href: href,
- target: target,
- class: 'documentLink',
- // Title is the text of the selected document
- title: this.find('.selected-document').text()
- };
-
- this.modifySelection(function (ed) {
- ed.insertLink(attributes);
- });
-
- this.updateFromEditor();
- return false;
- } else {
- this._super();
- }
- },
- getCurrentLink: function () {
- var selectedEl = this.getSelection(), href = "", target = "", title = "", action = "insert", style_class = "";
- var linkDataSource = null;
- if (selectedEl.length) {
- if (selectedEl.is('a')) {
- linkDataSource = selectedEl;
- } else {
- linkDataSource = selectedEl = selectedEl.parents('a:first');
- }
- }
-
- if (linkDataSource && linkDataSource.length) {
- this.modifySelection(function (ed) {
- ed.selectNode(linkDataSource[0]);
- });
- }
-
- // Is anchor not a link
- if (!linkDataSource.attr('href')) {
- linkDataSource = null;
- }
-
- if (linkDataSource) {
- href = linkDataSource.attr('href');
- target = linkDataSource.attr('target');
- title = linkDataSource.attr('title');
- style_class = linkDataSource.attr('class');
- href = this.getEditor().cleanLink(href, linkDataSource);
- action = "update";
- }
-
- // Match a document or call the regular link handling
- if (href.match(new RegExp('^\\[' + this.getShortcodeKey() + '(\s*|%20|,)?id=([0-9]+)\\]?$', 'i'))) {
- var returnArray = {
- LinkType: 'document',
- DocumentID: RegExp.$2,
- Description: title
- };
-
- // Show the selected document
- $('.document-add-existing').selectdocument(returnArray.DocumentID,returnArray.Description);
-
- // Select the correct radio button
- $('form.htmleditorfield-linkform input[name=LinkType][value=document]').click();
-
- return returnArray;
- } else {
- // Clear the selected document
- $('.document-add-existing').selectdocument();
- $('form.htmleditorfield-linkform .ss-add.ss-upload').hide();
- return this._super();
- }
- }
- });
- });
-}(jQuery));
diff --git a/_dev/scss/_mixins.scss b/_dev/scss/_mixins.scss
deleted file mode 100644
index 195b8e70..00000000
--- a/_dev/scss/_mixins.scss
+++ /dev/null
@@ -1,7 +0,0 @@
-//** Generate a state for an active list item link
-//
-// @param {string} $color - the colour to use for the border
-// @param {string} $size - the size the border should be, e.g. "8px"
-@mixin dmsdocument-actions-active($color, $size: "4px") {
- border-bottom: #{$size} solid #{$color};
-}
diff --git a/_dev/scss/_variables.scss b/_dev/scss/_variables.scss
deleted file mode 100644
index 8bad479f..00000000
--- a/_dev/scss/_variables.scss
+++ /dev/null
@@ -1,12 +0,0 @@
-//** Default values for colours, sizes etc
-
-// Colours
-$color-button-generic: #e6e6e6 !default;
-$color-zebra: #F0F4F7 !default;
-
-$color-grey-lighter: #f8f8f8 !default;
-$color-grey-light: #d0d3d5 !default;
-$color-grey-dark: #66727d !default;
-$color-white: #ffffff !default;
-
-$color-cms-input-border: #b3b3b3 !default;
diff --git a/_dev/scss/cmsfields.scss b/_dev/scss/cmsfields.scss
deleted file mode 100644
index cdd52ad9..00000000
--- a/_dev/scss/cmsfields.scss
+++ /dev/null
@@ -1,203 +0,0 @@
-//** The DMS document details/information on an edit page
-.dmsdocument-documentdetails {
- .fieldgroup-field {
- .cms-file-info-preview {
- box-shadow: none;
- }
-
- .cms-file-info-data {
- width: 400px;
- }
-
- .fieldholder-small {
- margin-top: 5px;
-
- .fieldholder-small-label {
- font-weight: bold;
- float: left;
- }
-
- .readonly {
- font-style: italic;
- }
- }
- }
-}
-
-//** The actions panel buttons when editing a DMS document
-.dmsdocment-actions {
- border: none;
- box-shadow: none;
- margin-bottom: 0;
- padding: 0;
-
- label.left {
- padding: 6px 0 0 0;
- }
-
- .ss-ui-button {
- border: none;
- background: none;
- border-radius: 0;
- font-weight: normal;
-
- .ui-button-text {
- padding-bottom: 1em;
- }
-
- &.dms-active,
- &.dms-active:hover {
- @include dmsdocument-actions-active($color-grey-dark);
- }
-
- &:hover,
- &:active {
- background: none;
- border: none;
- box-shadow: none;
- }
- }
-}
-
-//** The actions panel, containing mini forms for each DMS document action
-.dmsdocument-actionspanel {
- margin-top: 0;
-
- .fieldgroup {
- border: 1px solid $color-grey-light;
- display: none;
- margin-left: 0;
- padding: 5px 15px;
-
- .fieldholder-small {
- label {
- padding: 0;
- }
- }
-
- .embargo,
- .expiry {
- li {
- margin-left: 8px;
- width: 100%;
-
- label {
- padding-left: 10px;
- }
- }
-
- .embargoDatetime,
- .expiryDatetime {
- float: left;
- margin-top: 0;
- margin-left: 34px;
- overflow: hidden;
-
- .field {
- &.date,
- &.time {
- display: inline-block;
- margin: 0;
- padding: 0;
- width: auto;
-
- .middleColumn {
- overflow: hidden;
- }
- }
-
- &.date {
- .middleColumn {
- background: url('../images/calendar-month.png') 90px 7px no-repeat;
- }
- }
-
- &.time {
- .middleColumn {
- background: url('../images/clock-frame.png') 90px 7px no-repeat;
- }
- }
- }
-
- .middleColumn {
- border: none;
- margin-left: 0;
- width: auto;
-
- input.date,
- input.time {
- margin-right: 40px;
- width: 80px;
- }
- }
- }
- }
-
- .fieldgroup-field label {
- margin: 0;
- }
- }
-
- .ss-uploadfield-files {
- .ss-uploadfield-item-preview {
- background: url('../images/app_icons/generic_32.png') -10px -6px no-repeat;
- }
-
- .ss-uploadfield-item-name {
- span.name {
- width: 260px;
- }
- }
-
- .ss-uploadfield-item-actions {
- .ss-uploadfield-item-cancel {
- text-indent: 0;
- width: auto;
-
- .btn-icon-deleteLight {
- background-position: 0 -128px;
- display: inline-block;
- }
-
- .ui-button-text {
- color: $color-grey-dark;
- display: block;
- float: right;
- padding: 0 0 0 2em;
- position: relative;
- }
- }
- }
- }
-
- & > .fieldgroup.middleColumn {
- display: block;
- overflow: hidden;
-
- .fieldgroup-field {
- width: 100%;
- }
- }
-
- .permissions {
- .fieldholder-small {
- clear: both;
- }
- }
-}
-
-#ui-datepicker-div {
- border: 1px solid $color-grey-light;
-}
-
-//** Overrides for the inline edit screen
-form.small .field input.text,
-form.small .field textarea,
-form.small .field select,
-form.small .field .TreeDropdownField,
-.field.small input.text,
-.field.small textarea,
-.field.small select,
-.field.small .TreeDropdownField {
- width: 100%;
-}
diff --git a/_dev/scss/main.scss b/_dev/scss/main.scss
deleted file mode 100644
index b5d9a4e5..00000000
--- a/_dev/scss/main.scss
+++ /dev/null
@@ -1,4 +0,0 @@
-@import "_variables";
-@import "_mixins";
-@import "cmsfields";
-@import "upload";
diff --git a/_dev/scss/upload.scss b/_dev/scss/upload.scss
deleted file mode 100644
index 6004eac9..00000000
--- a/_dev/scss/upload.scss
+++ /dev/null
@@ -1,273 +0,0 @@
-.dmsdocument-addexisting {
- .ui-autocomplete {
- border: 1px solid $color-grey-light;
- max-height: 300px;
- overflow: scroll;
- }
-}
-
-.ss-add {
- .document-add-existing {
- input.document-autocomplete {
- position: absolute;
- z-index: 9999;
- width: 390px;
- padding: 9px 7px;
- border-bottom-right-radius: 0;
- border-top-right-radius: 0;
- outline: none;
- box-sizing: border-box;
- -moz-box-sizing: border-box;
-
- &[disabled] {
- color: $color-grey-light;
- text-shadow: 0 -1px 0 $color-white;
- background: $color-grey-lighter;
- background-image:none;
- box-shadow: inset 0 1px 8px 0 $color-grey-light;
- border-bottom-left-radius: 0;
- border-bottom-right-radius: 0;
- }
- }
-
- .treedropdown {
- border: none;
- }
-
- .treedropdownfield-toggle-panel-link {
- padding: 5px 9px 9px;
- background: #fff;
- border: 1px solid $color-cms-input-border;
- float: right;
- z-index: 99999;
- position: relative;
-
- &.treedropdownfield-open-tree {
- background: #fff;
- border: 1px solid $color-cms-input-border;
- border-bottom:none;
- border-bottom-right-radius:0;
- }
- }
-
- .treedropdownfield-title {
- width: auto;
- }
-
- .treedropdownfield-toggle-panel-link a {
- display: inline-block;
- top: 4px;
- position: relative;
- }
-
- .document-list {
- width: 510px;
- border: 1px solid $color-grey-light;
- border-top: none;
- background: $color-white;
- display: none;
- max-height: 300px;
- background-clip: padding-box;
- overflow: scroll;
-
- p {
- padding: 10px 10px 0;
- }
-
- ul {
- padding: 4px 0;
-
- li {
- line-height: 18px;
-
- a {
- display: block;
- padding: 4px 8px;
- border: 1px solid $color-white;
- color: black;
-
- &:hover {
- border: 1px solid $color-grey-light;
- border-radius: 4px;
- background: rgba(203, 203, 203, 0.4);
- cursor: pointer;
- text-decoration: none;
- outline: none;
- text-shadow: none;
- }
- }
- }
- }
- }
-
- // When inserting a link to a document via the TinyMCE editor
- &.link-editor-context {
- label {
- float: left;
- display: block;
- width: 176px;
- padding: 8px 8px 8px 0;
- line-height: 16px;
- font-weight: bold;
- text-shadow: 1px 1px 0 white;
- }
-
- .middleColumn {
- input {
- background: white;
- border: 1px solid $color-cms-input-border;
- line-height: 16px;
- border-radius: 4px;
- background-size: 100%;
- max-width: 468px;
-
- &.document-autocomplete {
- max-width: 365px;
- }
- }
- }
-
- .document-list {
- width: calc(100% - 2px);
- }
- }
- }
-
- .ss-assetuploadfield {
- &.link-editor-context {
- label {
- float: left;
- display: block;
- width: 176px;
- padding: 8px 8px 8px 0;
- line-height: 16px;
- font-weight: bold;
- text-shadow: 1px 1px 0 white;
- }
-
- .middleColumn {
- margin-left: 184px;
- display: block;
- padding: 8px 8px 8px 0;
- font-style: italic;
- min-height: 20px;
- }
- }
-
- .step4 {
- margin-bottom: 10px;
- }
- }
-}
-
-// Styling for tree dropdown field
-.cms {
- .ss-add,
- .selectiongroup {
- .treedropdownfield-panel {
- margin: -1px 0 0 0;
- box-sizing: border-box;
-
- ul {
- padding: 4px 0;
-
- li {
- border: 1px solid $color-white;
-
- a {
- display: block;
- padding: 4px 2px;
-
- &.jstree-hovered {
- background: rgba(203, 203, 203, 0.4);
- border: 1px solid $color-grey-light;
- }
- }
- }
- }
- }
- }
-}
-
-#Form_ItemEditForm {
- h3:first-child {
- display: inline-block;
- float: left;
- width: 184px;
- }
-
- ul.SelectionGroup {
- display: inline-block;
- position: relative;
- padding: 0;
- margin-top: 9px;
- margin-left: 0;
- height: 110px;
- background: none;
- border: none;
-
- li {
- width: auto;
- clear: none;
- display: inline;
- margin-right: 4px;
-
- input {
- &.selector {
- display: none;
- }
- }
-
- label {
- &.ui-button {
- font-weight: bold;
- border: 1px solid #C0C0C2;
- border-radius: 3px;
- padding: 0.8em 1.5em;
-
- &:hover {
- box-shadow: 0 0 5px rgba(0,0,0,0.3);
- }
- }
- }
-
- div.field {
- margin-left: 0px;
- margin-bottom: 1em;
- width: 600px;
- position: absolute;
- left: 0;
- margin-top: 13px;
- padding: 10px;
- background: white;
- border: 1px solid $color-cms-input-border;
- }
-
- &.selected {
- label.ui-button {
- &:after {
- top: 43px;
- }
- }
- }
- }
-
- .treedropdownfield-panel {
- margin: 1px 0 0 -1px;
- box-sizing: content-box;
-
- ul {
- li {
- display: block;
- clear: both;
- width: 100%;
- margin: 0;
-
- li {
- padding-left: 20px;
- }
- }
- }
- }
- }
-}
diff --git a/composer.json b/composer.json
index 6b2d861b..f3c84973 100644
--- a/composer.json
+++ b/composer.json
@@ -16,13 +16,10 @@
}
],
"require": {
- "silverstripe/framework": "^4.0 || ^5.0",
+ "silverstripe/cms": "^4.0 || ^5.0",
"symbiote/silverstripe-gridfieldextensions": "*",
"silverstripe/taxonomy": "*"
},
- "require-dev": {
- "sunnysideup/migration-task": "*"
- },
"suggest": {
"undefinedoffset/sortablegridfield": "Allow documents to be reordered via drag-and-drop"
},
@@ -38,5 +35,14 @@
"psr-4": {
"Sunnysideup\\DMS\\": "src/"
}
+ },
+ "config": {
+ "allow-plugins": {
+ "composer/installers": true,
+ "silverstripe/vendor-plugin": true
+ }
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^9.6"
}
-}
\ No newline at end of file
+}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
new file mode 100644
index 00000000..6788a080
--- /dev/null
+++ b/phpunit.xml.dist
@@ -0,0 +1,16 @@
+
+
+
+
+ src/.
+
+
+ tests/
+
+
+
+
+ tests
+
+
+
diff --git a/src/Admin/DMSDocumentAdmin.php b/src/Admin/DMSDocumentAdmin.php
index b2e0bf7e..86299a14 100644
--- a/src/Admin/DMSDocumentAdmin.php
+++ b/src/Admin/DMSDocumentAdmin.php
@@ -9,7 +9,9 @@
class DMSDocumentAdmin extends ModelAdmin
{
private static $url_segment = "dms-documents";
+
private static $menu_title = 'DMS Documents';
+
private static $managed_models = [
DMSDocument::class,
DMSDocumentSet::class
diff --git a/_dev/Cms/DMSDocumentAddController.php b/src/Cms/DMSDocumentAddController.php
similarity index 93%
rename from _dev/Cms/DMSDocumentAddController.php
rename to src/Cms/DMSDocumentAddController.php
index 3a3df3ab..e89ce7fc 100644
--- a/_dev/Cms/DMSDocumentAddController.php
+++ b/src/Cms/DMSDocumentAddController.php
@@ -95,24 +95,15 @@ public function getCurrentDocumentSet()
public function getEditForm($id = null, $fields = null)
{
-/**
- * ### @@@@ START REPLACEMENT @@@@ ###
- * WHY: upgrade to SS4
- * OLD: FRAMEWORK_DIR (ignore case)
- * NEW: SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() (COMPLEX)
- * EXP: Please review update and fix as required
- * ### @@@@ STOP REPLACEMENT @@@@ ###
- */
- Requirements::javascript(SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() . '/javascript/AssetUploadField.js');
-
/**
- * ### @@@@ START REPLACEMENT @@@@ ###
- * WHY: upgrade to SS4
- * OLD: FRAMEWORK_DIR (ignore case)
- * NEW: SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() (COMPLEX)
- * EXP: Please review update and fix as required
- * ### @@@@ STOP REPLACEMENT @@@@ ###
- */
+ * ### @@@@ START REPLACEMENT @@@@ ###
+ * WHY: upgrade to SS4
+ * OLD: FRAMEWORK_DIR (ignore case)
+ * NEW: SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() (COMPLEX)
+ * EXP: Please review update and fix as required
+ * ### @@@@ STOP REPLACEMENT @@@@ ###
+ */
+ Requirements::javascript(SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() . '/javascript/AssetUploadField.js');
Requirements::css(SilverStripe\Core\Manifest\ModuleLoader::getModule('silverstripe/framework')->getResource('UPGRADE-FIX-REQUIRED.php')->getRelativePath() . '/css/AssetUploadField.css');
Requirements::css(DMS_DIR . '/dist/css/cmsbundle.css');
@@ -264,7 +255,7 @@ public function documentautocomplete()
$data = DMSDocument::get()
->where(
'("ID" LIKE \'%' . $termSql . '%\' OR "Filename" LIKE \'%' . $termSql . '%\''
- . ' OR "Title" LIKE \'%' . $termSql . '%\')'
+ . ' OR "Title" LIKE \'%' . $termSql . '%\')'
)
->sort('ID ASC')
->limit(20);
@@ -334,7 +325,7 @@ public function documentlist()
$list .= sprintf(
'%s',
$document->ID,
- $document->ID . ' - '. Convert::raw2xml($document->Title)
+ $document->ID . ' - ' . Convert::raw2xml($document->Title)
);
}
@@ -377,7 +368,8 @@ public function canView($member = null, $context = [])
$member = Member::currentUser();
}
- if ($member &&
+ if (
+ $member &&
Permission::checkMember(
$member,
array(
diff --git a/_dev/Cms/DMSDocumentAddExistingField.php b/src/Cms/DMSDocumentAddExistingField.php
similarity index 74%
rename from _dev/Cms/DMSDocumentAddExistingField.php
rename to src/Cms/DMSDocumentAddExistingField.php
index 69a2f760..2403ea15 100644
--- a/_dev/Cms/DMSDocumentAddExistingField.php
+++ b/src/Cms/DMSDocumentAddExistingField.php
@@ -6,7 +6,6 @@
use SilverStripe\Forms\TreeDropdownField;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\Requirements;
-use Sunnysideup\DMS\Cms\DMSDocumentAddExistingField;
use SilverStripe\Forms\CompositeField;
class DMSDocumentAddExistingField extends CompositeField
@@ -48,26 +47,28 @@ public function getRecord()
if (!$this->record && $this->form) {
if ($this->form->getRecord() && is_a($this->form->getRecord(), DataObject::class)) {
$this->record = $this->form->getRecord();
- } elseif ($this->form->Controller() && $this->form->Controller()->hasMethod('data')
- && $this->form->Controller()->data() && is_a($this->form->Controller()->data(), DataObject::class)) {
+ } elseif (
+ $this->form->Controller() && $this->form->Controller()->hasMethod('data')
+ && $this->form->Controller()->data() && is_a($this->form->Controller()->data(), DataObject::class)
+ ) {
$this->record = $this->form->Controller()->data();
}
}
return $this->record;
}
- public function FieldHolder($properties = array())
+ public function FieldHolder($properties = [])
{
return $this->Field($properties);
}
- public function Field($properties = array())
+ public function Field($properties = [])
{
- Requirements::javascript(DMS_DIR . '/javascript/DMSDocumentAddExistingField.js');
- Requirements::javascript(DMS_DIR . '/javascript/DocumentHTMLEditorFieldToolbar.js');
- Requirements::css(DMS_DIR . '/dist/css/cmsbundle.css');
+ Requirements::javascript('heyday/silverstripe-dms:javascript/DMSDocumentAddExistingField.js');
+ Requirements::javascript('heyday/silverstripe-dms:javascript/DocumentHTMLEditorFieldToolbar.js');
+ Requirements::css('heyday/silverstripe-dms:dist/css/cmsbundle.css');
- return $this->renderWith(DMSDocumentAddExistingField::class);
+ return $this->renderWith(self::class);
}
/**
diff --git a/_dev/Cms/DMSGridFieldAddNewButton.php b/src/Cms/DMSGridFieldAddNewButton.php
similarity index 100%
rename from _dev/Cms/DMSGridFieldAddNewButton.php
rename to src/Cms/DMSGridFieldAddNewButton.php
diff --git a/_dev/Cms/DMSUploadField.php b/src/Cms/DMSUploadField.php
similarity index 99%
rename from _dev/Cms/DMSUploadField.php
rename to src/Cms/DMSUploadField.php
index c1d8183c..bf5861c6 100644
--- a/_dev/Cms/DMSUploadField.php
+++ b/src/Cms/DMSUploadField.php
@@ -3,13 +3,7 @@
namespace Sunnysideup\DMS\Cms;
use Exception;
-
-
-
use SilverStripe\Core\Injector\Injector;
-
-
-
use Sunnysideup\DMS\DMS;
use Sunnysideup\DMS\Model\DMSDocument;
use Sunnysideup\DMS\Model\DMSDocumentSet;
@@ -129,7 +123,7 @@ public function upload(HTTPRequest $request)
$record->write();
}
$tooManyFiles = $record->{$name}()->count() >= $this->getConfig('allowedMaxFileNumber');
- // has_one only allows one file at any given time.
+ // has_one only allows one file at any given time.
} elseif ($record->hasOne($name)) {
$tooManyFiles = $record->{$name}() && $record->{$name}()->exists();
}
diff --git a/_dev/Cms/DMSUploadField_ItemHandler.php b/src/Cms/DMSUploadField_ItemHandler.php
similarity index 100%
rename from _dev/Cms/DMSUploadField_ItemHandler.php
rename to src/Cms/DMSUploadField_ItemHandler.php
diff --git a/_dev/Cms/DocumentHtmlEditorFieldToolbar.php b/src/Cms/DocumentHtmlEditorFieldToolbar.php
similarity index 100%
rename from _dev/Cms/DocumentHtmlEditorFieldToolbar.php
rename to src/Cms/DocumentHtmlEditorFieldToolbar.php
diff --git a/src/Control/DMSDocumentController.php b/src/Control/DMSDocumentController.php
index 9f923080..8b78be33 100644
--- a/src/Control/DMSDocumentController.php
+++ b/src/Control/DMSDocumentController.php
@@ -3,13 +3,9 @@
namespace Sunnysideup\DMS\Control;
use SilverStripe\Security\Permission;
-use InvalidArgumentException;
-
use SilverStripe\Versioned\Versioned;
use SilverStripe\Core\Convert;
use SilverStripe\Control\Director;
-use Sunnysideup\DMS\Model\DMSDocument_versions;
-use SilverStripe\ORM\DataObject;
use Sunnysideup\DMS\Model\DMSDocument;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Controller;
@@ -23,9 +19,9 @@ class DMSDocumentController extends Controller
*/
protected static $testMode = false;
- private static $allowed_actions = array(
+ private static $allowed_actions = [
'index' => true
- );
+ ];
public function init()
{
@@ -48,7 +44,7 @@ public function index(HTTPRequest $request)
}
$doc = $this->getDocumentFromID($request);
- if (! empty($doc)) {
+ if (!empty($doc)) {
$canView = $doc->canView();
if ($canView) {
@@ -72,7 +68,7 @@ public function index(HTTPRequest $request)
$ext = $doc->getExtension();
if ($ext == 'pdf') {
$mime = 'application/pdf';
- } elseif ($ext == 'html' || $ext =='htm') {
+ } elseif ($ext == 'html' || $ext == 'htm') {
$mime = 'text/html';
} else {
$mime = 'application/octet-stream';
@@ -83,14 +79,7 @@ public function index(HTTPRequest $request)
return $path;
}
- // set fallback if no config nor file-specific value
$disposition = 'attachment';
-
- // file-specific setting
-
-
- //if a DMSDocument can be downloaded and all the permissions/privileges has passed,
-
return $this->sendFile($path, $mime, $doc->Name, $disposition);
}
}
@@ -117,6 +106,7 @@ protected function getDocumentFromID($request)
$id = Convert::raw2sql($request->param('ID'));
$versionID = Convert::raw2sql($request->param('VersionID'));
$isLegacyLink = true;
+
//new scenario with version and id
if ($versionID === 'latest') {
$versionID = 0;
@@ -138,23 +128,15 @@ protected function getDocumentFromID($request)
$id = $this->getDocumentIdFromSlug($id);
if ($versionID || $oldCaseVersioning) {
- //todo: UPGRADE: getting versionID
- if ($oldCaseVersioning) {
- //use $id to find version
- } else {
- //new school approach
- //use $id and $versionID to find version.
- }
$this->extend('updateVersionFromID', $doc, $request);
} elseif ($id && $isLegacyLink) {
- //backwards compatibility - fall back to OriginalDMSDocumentIDFile
$doc = DMSDocument::get()
->filter(['OriginalDMSDocumentIDFile' => intval($id)])
->first();
+
$this->extend('updateDocumentFromIDLegacyLink', $doc, $request);
$this->extend('updateDocumentFromID', $doc, $request);
} elseif ($id) {
- //new school approach
$doc = DMSDocument::get()->byID(intval($id));
$this->extend('updateDocumentFromID', $doc, $request);
} else {
@@ -188,9 +170,10 @@ protected function getDocumentIdFromSlug($slug)
protected function sendFile($path, $mime, $name, $disposition)
{
header('Content-Type: ' . $mime);
- header('Content-Length: ' . filesize($path), null);
+ header('Content-Length: ' . filesize($path));
+
if (!empty($mime) && $mime != "text/html") {
- header('Content-Disposition: '.$disposition.'; filename="'.addslashes($name).'"');
+ header('Content-Disposition: ' . $disposition . '; filename="' . addslashes($name) . '"');
}
header('Content-transfer-encoding: 8bit');
header('Expires: 0');
diff --git a/src/DMS.php b/src/DMS.php
new file mode 100644
index 00000000..ab68d075
--- /dev/null
+++ b/src/DMS.php
@@ -0,0 +1,12 @@
+ TaxonomyTerm::class
- );
+ ];
private static $many_many_extraFields = [
'Tags' => [
@@ -36,7 +36,7 @@ public function getAllTagsMap()
$map = [];
foreach ($tags as $tag) {
- $nameParts = array($tag->Name);
+ $nameParts = [$tag->Name];
$currentTag = $tag;
while ($currentTag->Parent() && $currentTag->Parent()->exists()) {
diff --git a/src/Admin/DMSSettings.php b/src/Extensions/DMSSettings.php
similarity index 77%
rename from src/Admin/DMSSettings.php
rename to src/Extensions/DMSSettings.php
index 3003f766..0f952de1 100644
--- a/src/Admin/DMSSettings.php
+++ b/src/Extensions/DMSSettings.php
@@ -13,9 +13,9 @@
class DMSSettings extends DataExtension
{
- private static $has_one = array(
+ private static $has_one = [
'DMSFolder' => Folder::class
- );
+ ];
/**
* Returns the fields that should be rendered in the admin module.
@@ -31,8 +31,8 @@ public function updateCMSFields(FieldList $fields)
'DMS Documents Folder',
Folder::get()->filter(['ParentID' => 0])
)
- ->setEmptyString('--- Please select a folder --- ')
- ->setRightTitle('All DMS documents will be stored in either this folder or a child folder of this folder')
+ ->setEmptyString('--- Please select a folder --- ')
+ ->setRightTitle('All DMS documents will be stored in either this folder or a child folder of this folder')
);
return $fields;
}
diff --git a/src/Extensions/DMSSiteTreeExtension.php b/src/Extensions/DMSSiteTreeExtension.php
index 76c79403..ac8b129b 100644
--- a/src/Extensions/DMSSiteTreeExtension.php
+++ b/src/Extensions/DMSSiteTreeExtension.php
@@ -4,25 +4,27 @@
use Sunnysideup\DMS\Model\DMSDocumentSet;
use SilverStripe\Forms\FieldList;
-use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
-use SilverStripe\Dev\Deprecation;
use SilverStripe\ORM\ArrayList;
-use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\DataExtension;
-
-/**
- * @package dms
- */
+use SilverStripe\Security\Security;
class DMSSiteTreeExtension extends DataExtension
{
- private static $has_many = array(
+ private static $has_many = [
'DocumentSets' => DMSDocumentSet::class
- );
+ ];
+
+ private static $cascade_deletes = [
+ 'DocumentSets'
+ ];
+
+ private static $cascade_duplicates = [
+ 'DocumentSets'
+ ];
public function updateCMSFields(FieldList $fields)
{
@@ -31,12 +33,10 @@ public function updateCMSFields(FieldList $fields)
return;
}
- // Hides the DocumentSets tab if the user has no permisions
if (!Permission::checkMember(
- Member::currentUser(),
- array('ADMIN', 'CMS_ACCESS_DMSDocumentAdmin')
- )
- ) {
+ Security::getCurrentUser(),
+ ['ADMIN', 'CMS_ACCESS_DMSDocumentAdmin']
+ )) {
return;
}
@@ -50,7 +50,7 @@ public function updateCMSFields(FieldList $fields)
// Only show document sets in the autocompleter that have not been assigned to a page already
$config->getComponentByType(GridFieldAddExistingAutocompleter::class)->setSearchList(
- DMSDocumentSet::get()->filter(array('PageID' => 0))
+ DMSDocumentSet::get()->filter(['PageID' => 0])
);
$fields->addFieldToTab(
@@ -63,7 +63,7 @@ public function updateCMSFields(FieldList $fields)
->setTitle(_t(
__CLASS__ . '.DocumentSetsTabTitle',
'Document Sets ({count})',
- array('count' => $this->owner->DocumentSets()->count())
+ ['count' => $this->owner->DocumentSets()->count()]
));
}
@@ -87,16 +87,14 @@ public function getAllDocuments()
public function onBeforeDelete()
{
- //@todo: UPGRADE: should we really delete the documents, even from the sets?
- // Only remove if record doesn't still exist on live stage.
if ($this->owner->isOnDraft() || $this->owner->isPublished()) {
//do nothing...
} else {
$dmsDocuments = $this->owner->getAllDocuments();
+
foreach ($dmsDocuments as $document) {
// If the document is only associated with one page, i.e. only associated with this page
if ($document->getRelatedPages()->count() <= 1) {
- // Delete the document before deleting this page
$document->delete();
}
}
diff --git a/src/Extensions/DMSTaxonomyTypeExtension.php b/src/Extensions/DMSTaxonomyTypeExtension.php
index 220cf543..d4da5420 100644
--- a/src/Extensions/DMSTaxonomyTypeExtension.php
+++ b/src/Extensions/DMSTaxonomyTypeExtension.php
@@ -2,9 +2,9 @@
namespace Sunnysideup\DMS\Extensions;
-use TaxonomyType;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;
+use SilverStripe\Taxonomy\TaxonomyType;
/**
* Creates default taxonomy type records if they don't exist already
@@ -12,23 +12,14 @@
class DMSTaxonomyTypeExtension extends DataExtension
{
- /**
- * Create default taxonomy type records. Add records via YAML configuration (see taxonomy.yml):
- *
- *
- * DMSTaxonomyTypeExtension:
- * default_records:
- * - Document
- * - PrivateDocument
- *
- */
public function requireDefaultRecords()
{
$records = (array) Config::inst()->get(get_class($this), 'default_records');
foreach ($records as $name) {
$type = TaxonomyType::get()->filter('Name', $name)->first();
+
if (!$type) {
- $type = TaxonomyType::create(array('Name' => $name));
+ $type = TaxonomyType::create(['Name' => $name]);
$type->write();
}
}
diff --git a/src/Extensions/FileExtension.php b/src/Extensions/FileExtension.php
index 7d74b41e..b99dbc46 100644
--- a/src/Extensions/FileExtension.php
+++ b/src/Extensions/FileExtension.php
@@ -2,11 +2,8 @@
namespace Sunnysideup\DMS\Extensions;
-use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataExtension;
-use Sunnysideup\DMS\Model\DMSDocument;
-
/**
* Creates default taxonomy type records if they don't exist already
*/
diff --git a/src/Forms/DMSJsonField.php b/src/Forms/DMSJsonField.php
deleted file mode 100644
index 38283b5c..00000000
--- a/src/Forms/DMSJsonField.php
+++ /dev/null
@@ -1,124 +0,0 @@
-setName($name);
-
- if ($children instanceof FieldList || is_array($children)) {
- foreach ($children as $child) {
- $this->setChildName($child);
- }
- } else {
- $children = is_array(func_get_args()) ? func_get_args() : array();
- if (!empty($children)) {
- array_shift($children);
- }
- foreach ($children as $child) {
- $this->setChildName($child);
- }
- }
- parent::__construct($children);
- }
-
- /**
- * Sets the name of the child object
- *
- * @param FormField $child
- */
- private function setChildName($child)
- {
- $child->setName("{$this->getName()}[{$child->getName()}]");
- }
-
- public function hasData()
- {
- return true;
- }
-
- /**
- * Override parent's behaviour as it's no longer required
- *
- * @param array $list
- * @param bool $saveableOnly
- */
- public function collateDataFields(&$list, $saveableOnly = false)
- {
- }
-
- /**
- * Recursively removed empty key-value pairs from $haystack
- *
- * @param $haystack
- *
- * @return mixed
- */
- public function arrayFilterEmptyRecursive($haystack)
- {
- foreach ($haystack as $key => $value) {
- if (is_array($value)) {
- $haystack[$key] = $this->arrayFilterEmptyRecursive($haystack[$key]);
- }
- if (empty($haystack[$key])) {
- unset($haystack[$key]);
- }
- }
-
- return $haystack;
- }
-
- /**
- * Overrides parent behaviour to remove empty elements
- *
- * @return mixed|null|string
- */
- public function dataValue()
- {
- $result = null;
- if (is_array($this->value)) {
- $this->value = $this->arrayFilterEmptyRecursive($this->value);
- $result = (!empty($this->value)) ? Convert::array2json($this->value) : $result;
- } else {
- $result = parent::dataValue();
- }
-
- return $result;
- }
-
- /**
- * Sets the value
- * @param mixed $value
- *
- * @return $this
- */
- public function setValue($value, $data = null)
- {
- $this->value = $value;
- if (is_string($value) && !empty($value)) {
- $value = Convert::json2array($value);
- } elseif (!is_array($value)) {
- $value = array($value);
- }
-
- $pattern = "/^{$this->getName()}\[(.*)\]$/";
- foreach ($this->children as $c) {
- $title = $c->getName();
- preg_match($pattern, $title, $matches);
- if (!empty($matches[1]) && isset($value[$matches[1]])) {
- $c->setValue($value[$matches[1]]);
- }
- }
-
- return $this;
- }
-}
diff --git a/src/Model/DMSDocument.php b/src/Model/DMSDocument.php
index 517da61d..425b11cd 100644
--- a/src/Model/DMSDocument.php
+++ b/src/Model/DMSDocument.php
@@ -2,35 +2,21 @@
namespace Sunnysideup\DMS\Model;
-use Exception;
use Sunnysideup\DMS\Model\DMSDocumentSet;
use SilverStripe\Assets\File;
-use SilverStripe\Assets\Folder;
use SilverStripe\Assets\Image;
use SilverStripe\Security\Member;
-use Sunnysideup\DMS\Model\DMSDocument;
-use SilverStripe\Security\Group;
-use SilverStripe\Security\Permission;
use SilverStripe\ORM\DB;
-use SilverStripe\ORM\DataExtension;
use SilverStripe\View\Parsers\URLSegmentFilter;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\Versioned\Versioned;
-use SilverStripe\ORM\FieldType\DBDatetime;
-use SilverStripe\ORM\FieldType\DBField;
-use Sunnysideup\DMS\DMS;
-use SilverStripe\View\Requirements;
use SilverStripe\Forms\FieldList;
-use Sunnysideup\DMS\Tools\ShortCodeRelationFinder;
use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\AssetAdmin\Forms\UploadField;
-use SilverStripe\Core\Config\Config;
-use SilverStripe\Forms\HeaderField;
-use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
@@ -40,30 +26,21 @@
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\CMS\Controllers\CMSPageEditController;
use SilverStripe\Forms\GridField\GridField;
-use SilverStripe\ORM\FieldType\DBDate;
-use SilverStripe\Forms\DatetimeField;
-use SilverStripe\Forms\FieldGroup;
use SilverStripe\Forms\LiteralField;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CompositeField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\DateField_Disabled;
use SilverStripe\ORM\ArrayList;
-use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer;
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
-use SilverStripe\Forms\GridField\GridFieldEditButton;
-use Sunnysideup\DMS\Cms\DMSGridFieldEditButton;
-use SilverStripe\Forms\GridField\GridFieldDeleteAction;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\Tab;
-use SilverStripe\Core\Convert;
use SilverStripe\SiteConfig\SiteConfig;
-use SilverStripe\ORM\DataObject;
use Sunnysideup\DMS\Interfaces\DMSDocumentInterface;
-use Sunnysideup\DMS\Admin\DMSDocumentAdmin;
-use SilverStripe\Core\Manifest\ModuleLoader;
+use Sunnysideup\DMS\Admin\DMSDocumentAdmin;;
+
use SilverStripe\Core\Injector\Injector;
/**
@@ -164,7 +141,7 @@ class DMSDocument extends File implements DMSDocumentInterface
*/
public static function get_file_type($ext)
{
- $types = array(
+ $types = [
'gif' => 'GIF image - good for diagrams',
'jpg' => 'JPEG image - good for photos',
'jpeg' => 'JPEG image - good for photos',
@@ -186,7 +163,7 @@ public static function get_file_type($ext)
'css' => 'CSS file',
'html' => 'HTML file',
'htm' => 'HTML file'
- );
+ ];
return isset($types[$ext]) ? $types[$ext] : $ext;
}
@@ -226,9 +203,9 @@ public function getCMSFields()
}
if (!$siteConfig->DMSFolderID) {
$fieldsForMain[] = (LiteralField::create(
- 'DMSFolderMessage',
- 'You need to set the folder for the DMS documents before you can create a DMS document.'
- ));
+ 'DMSFolderMessage',
+ 'You need to set the folder for the DMS documents before you can create a DMS document.'
+ ));
} else {
if (!$this->ID) {
$uploadField = new UploadField('TempFile', 'File');
@@ -258,7 +235,7 @@ public function getCMSFields()
}
$coverImageField = UploadField::create('CoverImage', _t('DMSDocument.COVERIMAGE', 'Cover Image'));
- $coverImageField->getValidator()->setAllowedExtensions(array('jpg', 'jpeg', 'png', 'gif'));
+ $coverImageField->getValidator()->setAllowedExtensions(['jpg', 'jpeg', 'png', 'gif']);
$coverImageField->setAllowedMaxFileNumber(1);
$fieldsForDetails[] = $coverImageField;
@@ -272,17 +249,17 @@ public function getCMSFields()
);
$gridFieldConfig->getComponentByType(GridFieldDataColumns::class)
- ->setDisplayFields(array(
+ ->setDisplayFields([
'Title' => 'Title',
'ClassName' => 'Page Type',
'ID' => 'Page ID'
- ))
- ->setFieldFormatting(array(
+ ])
+ ->setFieldFormatting([
'Title' => sprintf(
'$Title',
singleton(CMSPageEditController::class)->Link('show')
)
- ));
+ ]);
$pagesGrid = GridField::create(
'Pages',
@@ -360,12 +337,12 @@ public function getCMSFields()
public function getPermissionsActionPanel()
{
$fields = FieldList::create();
- $showFields = array(
+ $showFields = [
'CanViewType' => '',
'ViewerGroups' => 'hide',
'CanEditType' => '',
'EditorGroups' => 'hide',
- );
+ ];
/** @var SiteTree $siteTree */
$siteTree = singleton(SiteTree::class);
$settingsFields = $siteTree->getSettingsFields();
@@ -634,7 +611,7 @@ protected function getRelatedDocumentsGridField()
$addExisting->setSearchList($this->getRelatedDocumentsForAutocompleter());
// Restrict search fields to specific fields only
- $addExisting->setSearchFields(array('Title:PartialMatch', 'Filename:PartialMatch'));
+ $addExisting->setSearchFields(['Title:PartialMatch', 'Filename:PartialMatch']);
$addExisting->setResultsFormat('$Filename');
$this->extend('updateRelatedDocumentsGridField', $gridField);
@@ -782,7 +759,7 @@ public function canCreate($member = null, $context = [])
*/
public function canEdit($member = null)
{
- if (Controller::curr() instanceof DMSDocumentAdmin || Controller::curr() instanceof CMSPageEditController){
+ if (Controller::curr() instanceof DMSDocumentAdmin || Controller::curr() instanceof CMSPageEditController) {
return parent::canEdit($member);
} else {
return false;
diff --git a/src/Model/DMSDocumentSet.php b/src/Model/DMSDocumentSet.php
index 4dd0d0ae..e37d7912 100644
--- a/src/Model/DMSDocumentSet.php
+++ b/src/Model/DMSDocumentSet.php
@@ -2,43 +2,12 @@
namespace Sunnysideup\DMS\Model;
-use UndefinedOffset\SortableGridField\Forms\GridFieldSortableRows;
-use Symbiote\GridFieldExtension\GridFieldOrderableRows;
-use SilverStripe\Assets\File;
use SilverStripe\CMS\Model\SiteTree;
use Sunnysideup\DMS\Model\DMSDocument;
-use SilverStripe\Forms\FieldList;
-use SilverStripe\Forms\LiteralField;
-use SilverStripe\Forms\GridField\GridFieldConfig;
-use SilverStripe\Forms\GridField\GridFieldButtonRow;
-use SilverStripe\Forms\GridField\GridFieldToolbarHeader;
-use SilverStripe\Forms\GridField\GridFieldFilterHeader;
-use SilverStripe\Forms\GridField\GridFieldSortableHeader;
-use SilverStripe\Forms\GridField\GridFieldDataColumns;
-use Sunnysideup\DMS\Cms\DMSGridFieldEditButton;
-use SilverStripe\Forms\GridField\GridFieldDeleteAction;
-use SilverStripe\Forms\GridField\GridFieldDetailForm;
-use SilverStripe\Forms\GridField\GridFieldPaginator;
-use SilverStripe\Control\Controller;
-use SilverStripe\CMS\Controllers\CMSPageEditController;
-use Sunnysideup\DMS\Cms\DMSGridFieldDetailForm_ItemRequest;
-use SilverStripe\Forms\GridField\GridField;
-use Sunnysideup\DMS\Cms\DMSGridFieldAddNewButton;
-use SilverStripe\Forms\GridField\GridFieldExportButton;
-use Sunnysideup\DMS\DMS;
-use SilverStripe\Forms\HiddenField;
-use SilverStripe\View\Requirements;
use SilverStripe\Security\Member;
-use SilverStripe\Forms\ListboxField;
-use Sunnysideup\DMS\Forms\DMSJsonField;
-use SilverStripe\Forms\DropdownField;
-use SilverStripe\Forms\FieldGroup;
-use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataList;
-use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Permission;
use SilverStripe\ORM\DataObject;
-use SilverStripe\Core\Manifest\ModuleLoader;
/**
* A document set is attached to Pages, and contains many DMSDocuments
@@ -57,34 +26,34 @@ class DMSDocumentSet extends DataObject
private static $plural_name = 'DMS Document Sets';
- private static $db = array(
+ private static $db = [
'Title' => 'Varchar(255)',
'KeyValuePairs' => 'Text',
'SortBy' => "Enum('LastEdited,Created,Title')')",
'SortByDirection' => "Enum('DESC,ASC')')",
- );
+ ];
- private static $has_one = array(
+ private static $has_one = [
'Page' => SiteTree::class,
- );
+ ];
- private static $many_many = array(
+ private static $many_many = [
'Documents' => DMSDocument::class,
- );
+ ];
- private static $many_many_extraFields = array(
- 'Documents' => array(
+ private static $many_many_extraFields = [
+ 'Documents' => [
// Flag indicating if a document was added directly to a set - in which case it is set - or added
// via the query-builder.
'ManuallyAdded' => 'Boolean(1)',
'DocumentSort' => 'Int'
- ),
- );
+ ],
+ ];
- private static $summary_fields = array(
+ private static $summary_fields = [
'Title' => 'Title',
'Documents.Count' => 'No. Documents'
- );
+ ];
/**
* Retrieve a list of the documents in this set. An extension hook is provided before the result is returned.
@@ -118,7 +87,7 @@ public function getDocumentDisplayFields()
{
return array_merge(
(array) DMSDocument::create()->config()->get('display_fields'),
- array('ManuallyAdded' => _t('DMSDocumentSet.ADDEDMETHOD', 'Added'))
+ ['ManuallyAdded' => _t('DMSDocumentSet.ADDEDMETHOD', 'Added')]
);
}
@@ -185,7 +154,7 @@ public function getGlobalPermission(Member $member = null)
$member &&
Permission::checkMember(
$member,
- array('ADMIN', 'SITETREE_EDIT_ALL', 'CMS_ACCESS_DMSDocumentAdmin')
+ ['ADMIN', 'SITETREE_EDIT_ALL', 'CMS_ACCESS_DMSDocumentAdmin']
)
);
diff --git a/src/Tasks/MakeDMSTablesObsolete.php b/src/Tasks/MakeDMSTablesObsolete.php
index 833ead93..f38f1a6c 100644
--- a/src/Tasks/MakeDMSTablesObsolete.php
+++ b/src/Tasks/MakeDMSTablesObsolete.php
@@ -12,13 +12,12 @@
namespace Sunnysideup\DMS\Tasks;
use SilverStripe\Core\Injector\Injector;
-use SilverStripe\SiteConfig\SiteConfig;
-use SilverStripe\Versioned\Versioned;
-
-
-use Sunnysideup\DMS\Model\DMSDocument;
use Sunnysideup\MigrateData\Tasks\MigrateDataTask;
+if (!class_exists(MigrateDataTask::class)) {
+ return;
+}
+
class MakeDMSTablesObsolete extends MigrateDataTask
{
@@ -36,16 +35,17 @@ protected function performMigration()
$oldFolder = ASSETS_PATH . '/_dmsassets';
$newFolder = ASSETS_PATH . '/dmsassets';
- if (file_exists($oldFolder) && ! file_exists($newFolder)) {
+ if (file_exists($oldFolder) && !file_exists($newFolder)) {
rename($oldFolder, $newFolder);
} elseif (file_exists($oldFolder) && file_exists($newFolder)) {
- user_error($oldFolder.' AND '.$newFolder.' exist! Please review ...', E_USER_NOTICE);
+ user_error($oldFolder . ' AND ' . $newFolder . ' exist! Please review ...', E_USER_NOTICE);
}
$obj = Injector::inst()->get('Sunnysideup\\MigrateData\\Tasks\\MigrateDataTask');
if ($obj->tableExists('DMSDocument_versions')) {
- if ($obj->fieldExists('DMSDocument_versions', 'Created') &&
+ if (
+ $obj->fieldExists('DMSDocument_versions', 'Created') &&
$obj->fieldExists('DMSDocument_versions', 'LastEdited')
) {
$obj->makeTableObsolete('DMSDocument_versions');
@@ -53,14 +53,12 @@ protected function performMigration()
}
if ($obj->tableExists('DMSDocument')) {
- if ($obj->fieldExists('DMSDocument', 'Created') &&
+ if (
+ $obj->fieldExists('DMSDocument', 'Created') &&
$obj->fieldExists('DMSDocument', 'LastEdited')
) {
$obj->makeTableObsolete('DMSDocument');
}
}
-
-
}
-
}
diff --git a/src/Tasks/MigrateDMSToSilverstripe4.php b/src/Tasks/MigrateDMSToSilverstripe4.php
index f1863fdb..e113f97b 100644
--- a/src/Tasks/MigrateDMSToSilverstripe4.php
+++ b/src/Tasks/MigrateDMSToSilverstripe4.php
@@ -1,34 +1,21 @@
get('Sunnysideup\\MigrateData\\Tasks\\MigrateDataTask');
if ($obj->tableExists('DMSDocument_versions')) {
- if ($obj->fieldExists('DMSDocument_versions', 'Created') &&
+ if (
+ $obj->fieldExists('DMSDocument_versions', 'Created') &&
$obj->fieldExists('DMSDocument_versions', 'LastEdited')
) {
$obj->makeTableObsolete('DMSDocument_versions');
@@ -62,7 +50,8 @@ public static function flush()
}
if ($obj->tableExists('DMSDocument')) {
- if ($obj->fieldExists('DMSDocument', 'Created') &&
+ if (
+ $obj->fieldExists('DMSDocument', 'Created') &&
$obj->fieldExists('DMSDocument', 'LastEdited')
) {
$obj->makeTableObsolete('DMSDocument');
@@ -93,12 +82,12 @@ protected function performMigration()
$baseURL = Director::absoluteBaseURL();
self::flush();
$rows = DB::query('SELECT * FROM "_obsolete_DMSDocument";');
- $this->flushNow('... selecting '.DB::affected_rows().' rows from _obsolete_DMSDocument');
+ $this->flushNow('... selecting ' . DB::affected_rows() . ' rows from _obsolete_DMSDocument');
foreach ($rows as $row) {
//new file system doesn't like using _ or 0 for folder names
- $oldFolderName = '/dmsassets/'. $row['Folder'] .'';
+ $oldFolderName = '/dmsassets/' . $row['Folder'] . '';
$folderNumber = $row['Folder'] ? $row['Folder'] : 'zero';
- $newFolderName = 'dmsassets/'.$folderNumber.'';
+ $newFolderName = 'dmsassets/' . $folderNumber . '';
if (!isset($this->_folderCache[$newFolderName])) {
$this->_folderCache[$newFolderName] = Folder::find_or_make($newFolderName);
}
@@ -106,11 +95,11 @@ protected function performMigration()
$myFolder = $this->_folderCache[$newFolderName];
$exists = File::get()->filter(['OriginalDMSDocumentIDFile' => $row['ID']])->count() ? true : false;
if ($exists) {
- $this->flushNow('Skipping File with ID '.$row['ID']);
+ $this->flushNow('Skipping File with ID ' . $row['ID']);
//do nothing
} else {
- $this->flushNow('Doing: '.print_r($row, 1));
- $fullLocationFromAssets = $oldFolderName.'/'.$row['Filename'];
+ $this->flushNow('Doing: ' . print_r($row, 1));
+ $fullLocationFromAssets = $oldFolderName . '/' . $row['Filename'];
$fullLocationFromBase = ASSETS_PATH . $fullLocationFromAssets;
@@ -143,38 +132,38 @@ protected function performMigration()
//in the obsolete one we already have a version 1. Above we write a file
//so we end up with version 1
- $sql = 'DELETE FROM "File_Versions" WHERE "RecordID" = '.$newFile->ID.' AND "Version" = 1;';
- $this->flushNow('... ... ... running - '.$sql);
+ $sql = 'DELETE FROM "File_Versions" WHERE "RecordID" = ' . $newFile->ID . ' AND "Version" = 1;';
+ $this->flushNow('... ... ... running - ' . $sql);
DB::query($sql);
- $sql = 'DELETE FROM "DMSDocument_Versions" WHERE "RecordID" = '.$newFile->ID.' AND "Version" = 1;';
- $this->flushNow('... ... ... running -'.$sql);
+ $sql = 'DELETE FROM "DMSDocument_Versions" WHERE "RecordID" = ' . $newFile->ID . ' AND "Version" = 1;';
+ $this->flushNow('... ... ... running -' . $sql);
DB::query($sql);
- if (! $this->tableExists('_obsolete_DMSDocument_versions')) {
+ if (!$this->tableExists('_obsolete_DMSDocument_versions')) {
user_error('Table _obsolete_DMSDocument_versions does not exist. Error', E_USER_ERROR);
}
- $versionRows = DB::query('SELECT "ID" FROM "_obsolete_DMSDocument_versions" WHERE "DocumentID" = '.$row['ID']);
+ $versionRows = DB::query('SELECT "ID" FROM "_obsolete_DMSDocument_versions" WHERE "DocumentID" = ' . $row['ID']);
foreach ($versionRows as $versionRow) {
- $this->flushNow('... adding row for DocumentID = '.$row['ID']);
+ $this->flushNow('... adding row for DocumentID = ' . $row['ID']);
$sql = '
INSERT
INTO "File_Versions" (
"RecordID", "Version", "Created", "LastEdited", "Name", "Title", "CanViewType", "CanEditType", "OriginalDMSDocumentIDFile", "ClassName"
)
SELECT
- '.$newFile->ID .', "VersionCounter", "Created", "LastEdited", "Filename", "Title", "CanViewType", "CanEditType", '.$row['ID'].' AS OriginalDMSDocumentIDFile, \'Sunnysideup\\\\DMS\\\\Model\\\\DMSDocument\' as ClassNameInsert
+ ' . $newFile->ID . ', "VersionCounter", "Created", "LastEdited", "Filename", "Title", "CanViewType", "CanEditType", ' . $row['ID'] . ' AS OriginalDMSDocumentIDFile, \'Sunnysideup\\\\DMS\\\\Model\\\\DMSDocument\' as ClassNameInsert
FROM "_obsolete_DMSDocument_versions"
- WHERE "ID" = '.$versionRow['ID'].';';
+ WHERE "ID" = ' . $versionRow['ID'] . ';';
echo $sql;
DB::query($sql);
$id = DB::query('SELECT LAST_INSERT_ID();')->value();
- if (! $id) {
+ if (!$id) {
user_error('Could not find an ID from the last insert.');
}
- $testVersionCountForDMSDocumentTable = DB::query('SELECT COUNT("ID") FROM "DMSDocument_Versions" WHERE "ID" = '.$id);
- if (! $testVersionCountForDMSDocumentTable) {
- user_error('ID already exists in DMSDocument_Versions: '.$testVersionCountForDMSDocumentTable);
+ $testVersionCountForDMSDocumentTable = DB::query('SELECT COUNT("ID") FROM "DMSDocument_Versions" WHERE "ID" = ' . $id);
+ if (!$testVersionCountForDMSDocumentTable) {
+ user_error('ID already exists in DMSDocument_Versions: ' . $testVersionCountForDMSDocumentTable);
}
$sql = '
INSERT
@@ -182,9 +171,9 @@ protected function performMigration()
"ID", "RecordID", "Version", "Description", "ISBN", "ISSN", "CoverImageID", "CreatedByID", "LastEditedByID"
)
SELECT
- '.$id.' AS ID, '.$newFile->ID .', "VersionCounter", "Description", "ISBN", "ISSN", '.$newFile->CoverImageID.', '.$newFile->CreatedByID.', "VersionAuthorID"
+ ' . $id . ' AS ID, ' . $newFile->ID . ', "VersionCounter", "Description", "ISBN", "ISSN", ' . $newFile->CoverImageID . ', ' . $newFile->CreatedByID . ', "VersionAuthorID"
FROM "_obsolete_DMSDocument_versions"
- WHERE "ID" = '.$versionRow['ID'].';';
+ WHERE "ID" = ' . $versionRow['ID'] . ';';
DB::query($sql);
}
@@ -204,7 +193,7 @@ protected function performMigration()
->filter(['ID' => $id])
->count();
if ($testCount1 !== 1) {
- $this->flushNow('error in migration for row TEST 1 - could not find File Record, number of files found: '.$testCount1, 'error');
+ $this->flushNow('error in migration for row TEST 1 - could not find File Record, number of files found: ' . $testCount1, 'error');
$this->flushNow('-----------------------------');
$this->flushNow('STOPPED');
$this->flushNow('-----------------------------');
@@ -216,8 +205,8 @@ protected function performMigration()
echo $link;
$testLocation = str_replace($baseURL, $baseDirWithPublic, $link);
- if (! file_exists($testLocation)) {
- $this->flushNow('error in migration for row - could not find Actual File ('.$testLocation.')', 'error');
+ if (!file_exists($testLocation)) {
+ $this->flushNow('error in migration for row - could not find Actual File (' . $testLocation . ')', 'error');
$this->flushNow('-----------------------------');
$this->flushNow('STOPPED');
$this->flushNow('-----------------------------');
@@ -228,15 +217,15 @@ protected function performMigration()
$newFile->OriginalDMSDocumentIDFile = $row['ID'];
$newFile->write();
} else {
- $this->flushNow('ERROR: could not link to document ... ID = '.$newFile->ID.' we looked at '.$fullLocationFromAssets);
+ $this->flushNow('ERROR: could not link to document ... ID = ' . $newFile->ID . ' we looked at ' . $fullLocationFromAssets);
die();
}
} else {
- $this->flushNow('Could not find: '.$fullLocationFromBase, 'error');
+ $this->flushNow('Could not find: ' . $fullLocationFromBase, 'error');
}
}
} else {
- die('Could not create folder: '.$newFolderName);
+ die('Could not create folder: ' . $newFolderName);
}
}
@@ -273,41 +262,41 @@ protected function getPostQueries()
protected function getPostQueriesBuilder($table, $relation)
{
- $field = $relation.'ID';
+ $field = $relation . 'ID';
if (!$this->tableExists($table)) {
- $this->flushNow('Error: could not find the following table: '.$table);
+ $this->flushNow('Error: could not find the following table: ' . $table);
die('');
}
//clean table
$baseTable = $table;
$baseTable = str_replace('_Live', '', $baseTable);
$baseTable = str_replace('_Versions', '', $baseTable);
- $originalDocumentIDField = 'OriginalDMSDocumentID'.$baseTable;
- if (! $this->fieldExists($table, $originalDocumentIDField)) {
- $this->flushNow('Error: could not find the following field: '.$originalDocumentIDField.' in '.$table);
+ $originalDocumentIDField = 'OriginalDMSDocumentID' . $baseTable;
+ if (!$this->fieldExists($table, $originalDocumentIDField)) {
+ $this->flushNow('Error: could not find the following field: ' . $originalDocumentIDField . ' in ' . $table);
die('');
}
- if (! $this->fieldExists($table, $field)) {
- $this->flushNow('Error: could not find the following field: '.$table.'.'.$field.'');
+ if (!$this->fieldExists($table, $field)) {
+ $this->flushNow('Error: could not find the following field: ' . $table . '.' . $field . '');
die('');
}
$queries = [];
foreach (['', '_Live', '_Versions'] as $tableExtensions) {
- $fullTable = $table.$tableExtensions;
+ $fullTable = $table . $tableExtensions;
if ($this->tableExists($fullTable)) {
$queries[] =
//set the OriginalDMSDocumentID if that has not been set yet ...
'
- UPDATE "'.$fullTable.'"
- SET "'.$fullTable.'"."'.$originalDocumentIDField.'" = "'.$fullTable.'"."'.$field.'"
+ UPDATE "' . $fullTable . '"
+ SET "' . $fullTable . '"."' . $originalDocumentIDField . '" = "' . $fullTable . '"."' . $field . '"
WHERE
(
- "'.$fullTable.'"."'.$originalDocumentIDField.'" = 0 OR
- "'.$fullTable.'"."'.$originalDocumentIDField.'" IS NULL
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" = 0 OR
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" IS NULL
) AND (
- "'.$fullTable.'"."'.$field.'" > 0 AND
- "'.$fullTable.'"."'.$field.'" IS NOT NULL
+ "' . $fullTable . '"."' . $field . '" > 0 AND
+ "' . $fullTable . '"."' . $field . '" IS NOT NULL
);
';
$queries[] =
@@ -315,13 +304,13 @@ protected function getPostQueriesBuilder($table, $relation)
//set the field to zero in case there is a DMS Link
//but the DMS link can not be made
'
- UPDATE "'.$fullTable.'"
+ UPDATE "' . $fullTable . '"
LEFT JOIN "File"
- ON "File"."OriginalDMSDocumentIDFile" = "'.$fullTable.'"."'.$originalDocumentIDField.'"
- SET "'.$fullTable.'"."'.$field.'" = 0
+ ON "File"."OriginalDMSDocumentIDFile" = "' . $fullTable . '"."' . $originalDocumentIDField . '"
+ SET "' . $fullTable . '"."' . $field . '" = 0
WHERE
- "'.$fullTable.'"."'.$originalDocumentIDField.'" > 0 AND
- "'.$fullTable.'"."'.$originalDocumentIDField.'" IS NOT NULL AND
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" > 0 AND
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" IS NOT NULL AND
"File"."ID" IS NULL;
';
@@ -329,16 +318,16 @@ protected function getPostQueriesBuilder($table, $relation)
//update to new value ... where there is a DMSDocument connection
'
- UPDATE "'.$fullTable.'"
+ UPDATE "' . $fullTable . '"
INNER JOIN "File"
- ON "File"."OriginalDMSDocumentIDFile" = "'.$fullTable.'"."'.$originalDocumentIDField.'"
- SET "'.$fullTable.'"."'.$field.'" = "File"."ID"
+ ON "File"."OriginalDMSDocumentIDFile" = "' . $fullTable . '"."' . $originalDocumentIDField . '"
+ SET "' . $fullTable . '"."' . $field . '" = "File"."ID"
WHERE
- "'.$fullTable.'"."'.$originalDocumentIDField.'" > 0 AND
- "'.$fullTable.'"."'.$originalDocumentIDField.'" IS NOT NULL;
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" > 0 AND
+ "' . $fullTable . '"."' . $originalDocumentIDField . '" IS NOT NULL;
';
} else {
- $this->flushNow('Skipping '.$fullTable.' as this table does not exist.');
+ $this->flushNow('Skipping ' . $fullTable . ' as this table does not exist.');
}
}
@@ -348,7 +337,7 @@ protected function getPostQueriesBuilder($table, $relation)
public function setMainDMSFolder()
{
$siteConfig = SiteConfig::current_site_config();
- if (! $siteConfig->DMSFolderID) {
+ if (!$siteConfig->DMSFolderID) {
$folder = Folder::find_or_make('dmsassets');
$siteConfig->DMSFolderID = $folder->ID;
$siteConfig->write();
diff --git a/src/Tasks/MigrateDMSToSilverstripe4HTMLShortCodeFix.php b/src/Tasks/MigrateDMSToSilverstripe4HTMLShortCodeFix.php
index 016cd77b..39c181f6 100644
--- a/src/Tasks/MigrateDMSToSilverstripe4HTMLShortCodeFix.php
+++ b/src/Tasks/MigrateDMSToSilverstripe4HTMLShortCodeFix.php
@@ -3,25 +3,16 @@
namespace Sunnysideup\DMS\Tasks;
-use SilverStripe\Assets\File;
-use SilverStripe\Assets\Folder;
-use SilverStripe\Control\Director;
use SilverStripe\CMS\Model\SiteTree;
-use SilverStripe\Core\Environment;
-use SilverStripe\Core\Flushable;
use SilverStripe\Core\ClassInfo;
-use SilverStripe\Core\Injector\Injector;
-use SilverStripe\Dev\BuildTask;
-use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB;
-use SilverStripe\SiteConfig\SiteConfig;
-use SilverStripe\Versioned\Versioned;
-
-
use Sunnysideup\DMS\Model\DMSDocument;
-use Sunnysideup\DMS\Model\DMSDocumentSet;
use Sunnysideup\MigrateData\Tasks\MigrateDataTask;
+if (!class_exists(MigrateDataTask::class)) {
+ return;
+}
+
class MigrateDMSToSilverstripe4HTMLShortCodeFix extends MigrateDataTask
{
@@ -34,17 +25,16 @@ class MigrateDMSToSilverstripe4HTMLShortCodeFix extends MigrateDataTask
protected function performMigration()
{
$count = DMSDocument::get()->count();
- $this->flushNow('DOING '.$count.' DMS DOCUMENTS');
+ $this->flushNow('DOING ' . $count . ' DMS DOCUMENTS');
$idList = DMSDocument::get()->map('ID', 'OriginalDMSDocumentIDFile');
- foreach($idList as $newID => $oldID) {
- if($oldID) {
+ foreach ($idList as $newID => $oldID) {
+ if ($oldID) {
$this->flushNow('');
$this->flushNow('');
- $this->flushNow('Searching for DMS Document with ID = '.$newID.' and OldID = '.$oldID);
+ $this->flushNow('Searching for DMS Document with ID = ' . $newID . ' and OldID = ' . $oldID);
$this->replaceShortCode($oldID, $newID);
}
}
-
}
/**
@@ -66,32 +56,32 @@ protected function replaceShortCode($oldID, $newID)
$fields = $this->getShortCodeFields(SiteTree::class);
foreach ($fields as $className => $fieldNames) {
$tableName = $this->getSchemaForDataObject()->tableName($className);
- $this->flushNow('... searching in '.$tableName);
- if($this->tableExists($tableName)) {
+ $this->flushNow('... searching in ' . $tableName);
+ if ($this->tableExists($tableName)) {
foreach ($fieldNames as $fieldName => $fieldSpecs) {
- if($this->fieldExists($tableName, $fieldName)) {
- $oldPhrase = '[dms_document_link,id='.$oldID.']';
- $newPhrase = '[file_link,id='.$newID.']';
- $this->flushNow('... ... replacing '.$oldPhrase.' to '.$newPhrase.' in '.$tableName.'.'.$fieldName);
+ if ($this->fieldExists($tableName, $fieldName)) {
+ $oldPhrase = '[dms_document_link,id=' . $oldID . ']';
+ $newPhrase = '[file_link,id=' . $newID . ']';
+ $this->flushNow('... ... replacing ' . $oldPhrase . ' to ' . $newPhrase . ' in ' . $tableName . '.' . $fieldName);
$sql = '
- UPDATE "'.$tableName.'"
+ UPDATE "' . $tableName . '"
SET
- "'.$tableName.'"."'.$fieldName.'" = REPLACE(
- "'.$tableName.'"."'.$fieldName.'",
- \''.$oldPhrase.'\',
- \''.$newPhrase.'\'
+ "' . $tableName . '"."' . $fieldName . '" = REPLACE(
+ "' . $tableName . '"."' . $fieldName . '",
+ \'' . $oldPhrase . '\',
+ \'' . $newPhrase . '\'
)
- WHERE "'.$tableName.'"."'.$fieldName.'" LIKE \'%'.$oldPhrase.'%\';
+ WHERE "' . $tableName . '"."' . $fieldName . '" LIKE \'%' . $oldPhrase . '%\';
';
// $this->flushNow($sql);
DB::query($sql);
- $this->flushNow('... ... ... DONE updated '.DB::affected_rows().' rows');
+ $this->flushNow('... ... ... DONE updated ' . DB::affected_rows() . ' rows');
} else {
- $this->flushNow('... ... skipping '.$tableName.'.'.$fieldName.' (does not exist)');
+ $this->flushNow('... ... skipping ' . $tableName . '.' . $fieldName . ' (does not exist)');
}
}
} else {
- $this->flushNow('... skipping: '.$tableName.' (does not exist)');
+ $this->flushNow('... skipping: ' . $tableName . ' (does not exist)');
}
}
}
@@ -106,7 +96,7 @@ protected function replaceShortCode($oldID, $newID)
*/
protected function getShortcodeFields($class)
{
- if(! isset($this->_classFieldCache[$class])) {
+ if (!isset($this->_classFieldCache[$class])) {
$fields = [];
$ancestry = array_values(ClassInfo::dataClassesFor($class));
@@ -133,5 +123,4 @@ protected function getShortcodeFields($class)
return $this->_classFieldCache[$class];
}
-
}
diff --git a/src/Tasks/MigrateToDocumentSetsTask.php b/src/Tasks/MigrateToDocumentSetsTask.php
index 3f855b24..ce7756cb 100644
--- a/src/Tasks/MigrateToDocumentSetsTask.php
+++ b/src/Tasks/MigrateToDocumentSetsTask.php
@@ -24,10 +24,10 @@ class MigrateToDocumentSetsTask extends BuildTask
* The valid actions that this task can perform (and the method that does them as the key)
* @var array
*/
- protected $validActions = array(
+ protected $validActions = [
'createDefaultSet' => 'create-default-document-set',
'reassignDocuments' => 'reassign-documents'
- );
+ ];
/**
* @var SS_HTTPRequest
@@ -118,7 +118,7 @@ protected function reassignDocuments()
return $this;
}
- $query = SQLSelect::create(array('DMSDocumentID', 'SiteTreeID'), 'DMSDocument_Pages');
+ $query = SQLSelect::create(['DMSDocumentID', 'SiteTreeID'], 'DMSDocument_Pages');
$result = $query->execute();
foreach ($result as $row) {
diff --git a/tests/DMSDocumentControllerTest.php b/tests/DMSDocumentControllerTest.php
index 676e604a..9c18a52b 100644
--- a/tests/DMSDocumentControllerTest.php
+++ b/tests/DMSDocumentControllerTest.php
@@ -18,7 +18,7 @@ class DMSDocumentControllerTest extends SapphireTest
*/
protected $controller;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -26,11 +26,11 @@ public function setUp()
$this->logInWithPermission('ADMIN');
$this->controller = $this->getMockBuilder(DMSDocumentController::class)
- ->setMethods(array('sendFile'))
+ ->setMethods(['sendFile'])
->getMock();
}
- public function tearDown()
+ public function tearDown(): void
{
DMSFilesystemTestHelper::delete('assets/_unit-test-123');
parent::tearDown();
@@ -69,9 +69,9 @@ public function tearDown()
*/
public function behaviourProvider()
{
- return array(
- array('open', 'inline'),
- array('download', 'attachment')
- );
+ return [
+ ['open', 'inline'],
+ ['download', 'attachment']
+ ];
}
}
diff --git a/tests/DMSDocumentSetTest.php b/tests/DMSDocumentSetTest.php
index fe559a15..9b8d3174 100644
--- a/tests/DMSDocumentSetTest.php
+++ b/tests/DMSDocumentSetTest.php
@@ -70,7 +70,7 @@ public function testRelations()
$this->assertCount(0, $s4->DocumentSets(), 'Page 4 has no document sets associated');
$this->assertCount(2, $s1->DocumentSets(), 'Page 1 has 2 document sets');
- $this->assertEquals(array($ds1->ID, $ds2->ID), $s1->DocumentSets()->column('ID'));
+ $this->assertEquals([$ds1->ID, $ds2->ID], $s1->DocumentSets()->column('ID'));
}
/**
@@ -109,7 +109,7 @@ public function testGetDocumentDisplayFields()
$document = $this->objFromFixture(DMSDocumentSet::class, 'ds1');
$this->assertInternalType('array', $document->getDocumentDisplayFields());
- Config::modify()->update(DMSDocument::class, 'display_fields', array('apple' => 'Apple', 'orange' => 'Orange'));
+ Config::modify()->update(DMSDocument::class, 'display_fields', ['apple' => 'Apple', 'orange' => 'Orange']);
$displayFields = $document->getDocumentDisplayFields();
$this->assertContains('Apple', $displayFields);
$this->assertContains('Orange', $displayFields);
@@ -191,7 +191,7 @@ public function testShortcodeHandlerKeyFieldExists()
{
Config::modify()->update(DMS::class, 'shortcode_handler_key', 'unit-test');
- $set = DMSDocumentSet::create(array('Title' => 'TestSet'));
+ $set = DMSDocumentSet::create(['Title' => 'TestSet']);
$set->write();
$fields = $set->getCMSFields();
@@ -242,7 +242,7 @@ public function testSaveLinkedDocuments()
*/
public function testExceptionOnNoTitleGiven()
{
- DMSDocumentSet::create(array('Title' => ''))->write();
+ DMSDocumentSet::create(['Title' => ''])->write();
}
/**
diff --git a/tests/DMSDocumentTest.php b/tests/DMSDocumentTest.php
index f4691bf3..a42f27b4 100644
--- a/tests/DMSDocumentTest.php
+++ b/tests/DMSDocumentTest.php
@@ -36,7 +36,7 @@ public function testRelatedDocuments()
$document = $this->objFromFixture(DMSDocument::class, 'document_with_relations');
$this->assertGreaterThan(0, $document->RelatedDocuments()->count());
$this->assertEquals(
- array('test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'),
+ ['test-file-file-doesnt-exist-1', 'test-file-file-doesnt-exist-2'],
$document->getRelatedDocuments()->column('Filename')
);
}
@@ -105,12 +105,12 @@ public function testGetRelatedDocumentsForAutocompleter()
$jsonResult = $autocompleter->doSearch(
$gridField,
- new HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'test'))
+ new HTTPRequest('GET', '/', ['gridfield_relationsearch' => 'test'])
);
$this->assertNotContains('test-file-file-doesnt-exist-1', $jsonResult);
$this->assertContains('test-file-file-doesnt-exist-2', $jsonResult);
- $this->assertEquals(array('Title:PartialMatch', 'Filename:PartialMatch'), $autocompleter->getSearchFields());
+ $this->assertEquals(['Title:PartialMatch', 'Filename:PartialMatch'], $autocompleter->getSearchFields());
}
/**
@@ -147,7 +147,7 @@ public function testGetActionTaskHtml()
$this->assertContains('permission', $result);
$this->assertContains('Example', $result);
- $actions = array('example', 'embargo','find-usage');
+ $actions = ['example', 'embargo','find-usage'];
foreach ($actions as $action) {
// Test remove with string
$document->removeActionPanelTask($action);
@@ -305,7 +305,7 @@ public function testGetRelatedPages()
$document = $this->objFromFixture(DMSDocument::class, 'd1');
$result = $document->getRelatedPages();
$this->assertCount(3, $result, 'Document 1 is related to 3 Pages');
- $this->assertSame(array('s1', 's2', 's3'), $result->column('URLSegment'));
+ $this->assertSame(['s1', 's2', 's3'], $result->column('URLSegment'));
}
/**
diff --git a/tests/DMSEmbargoTest.php b/tests/DMSEmbargoTest.php
index b40e2780..2ff86362 100644
--- a/tests/DMSEmbargoTest.php
+++ b/tests/DMSEmbargoTest.php
@@ -1,13 +1,6 @@
match('index/$ID');
return $r;
}
-//
-// public function testBasicEmbargo()
-// {
-// $oldTestMode = DMSDocumentController::$testMode;
-// Config::modify()->update(DMS::class, 'folder_name', 'assets/_unit-test-123');
-//
-// $doc = DMS::inst()->storeDocument('dms/tests/DMS-test-lorum-file.pdf');
-// $doc->CanViewType = 'LoggedInUsers';
-// $docID = $doc->write();
-//
-// //fake a request for a document
-// $controller = new DMSDocumentController();
-// DMSDocumentController::$testMode = true;
-// $result = $controller->index($this->createFakeHTTPRequest($docID));
-//
-// /**
-// * ### @@@@ START REPLACEMENT @@@@ ###
-// * WHY: upgrade to SS4
-// * OLD: ->getFullPath() (case sensitive)
-// * NEW: ->getFilename() (COMPLEX)
-// * EXP: You may need to add ASSETS_PATH."/" in front of this ...
-// * ### @@@@ STOP REPLACEMENT @@@@ ###
-// */
-// $this->assertEquals($doc->getFilename(), $result, 'Correct underlying file returned (in test mode)');
-//
-// $doc->embargoIndefinitely();
-//
-// $this->logInWithPermission('ADMIN');
-// $result = $controller->index($this->createFakeHTTPRequest($docID));
-//
-// /**
-// * ### @@@@ START REPLACEMENT @@@@ ###
-// * WHY: upgrade to SS4
-// * OLD: ->getFullPath() (case sensitive)
-// * NEW: ->getFilename() (COMPLEX)
-// * EXP: You may need to add ASSETS_PATH."/" in front of this ...
-// * ### @@@@ STOP REPLACEMENT @@@@ ###
-// */
-// $this->assertEquals($doc->getFilename(), $result, 'Admins can still download embargoed files');
-//
-// $this->logInWithPermission('random-user-group');
-// $result = $controller->index($this->createFakeHTTPRequest($docID));
-// $this->assertNotEquals(
-//
-// /**
-// * ### @@@@ START REPLACEMENT @@@@ ###
-// * WHY: upgrade to SS4
-// * OLD: ->getFullPath() (case sensitive)
-// * NEW: ->getFilename() (COMPLEX)
-// * EXP: You may need to add ASSETS_PATH."/" in front of this ...
-// * ### @@@@ STOP REPLACEMENT @@@@ ###
-// */
-// $doc->getFilename(),
-// $result,
-// 'File no longer returned (in test mode) when switching to other user group'
-// );
-//
-// DMSDocumentController::$testMode = $oldTestMode;
-// DMSFilesystemTestHelper::delete('assets/_unit-test-123');
-// }
-//
-// public function testEmbargoIndefinitely()
-// {
-// $doc = new DMSDocument();
-// $doc->Filename = "DMS-test-lorum-file.pdf";
-// $doc->Folder = "tests";
-// $doc->write();
-//
-// $doc->embargoIndefinitely();
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->clearEmbargo();
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-// }
-//
-// public function testExpireAtDate()
-// {
-// $doc = new DMSDocument();
-// $doc->Filename = "DMS-test-lorum-file.pdf";
-// $doc->Folder = "tests";
-// $doc->write();
-//
-// $doc->expireAtDate(strtotime('-1 second'));
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertTrue($doc->isExpired(), "Document is expired");
-//
-// $expireTime = "2019-04-05 11:43:13";
-// $doc->expireAtDate($expireTime);
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// DBDatetime::set_mock_now($expireTime);
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertTrue($doc->isExpired(), "Document is expired");
-// DBDatetime::clear_mock_now();
-//
-// $doc->expireAtDate(strtotime('-1 second'));
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertTrue($doc->isExpired(), "Document is expired");
-//
-// $doc->clearExpiry();
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-// }
-//
-// public function testEmbargoUntilDate()
-// {
-// $doc = new DMSDocument();
-// $doc->Filename = "DMS-test-lorum-file.pdf";
-// $doc->Folder = "tests";
-// $doc->write();
-//
-// $doc->embargoUntilDate(strtotime('+1 minute'));
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-//
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->embargoUntilDate(strtotime('-1 second'));
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $embargoTime = "2019-04-05 11:43:13";
-// $doc->embargoUntilDate($embargoTime);
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// DBDatetime::set_mock_now($embargoTime);
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// DBDatetime::clear_mock_now();
-//
-// $doc->clearEmbargo();
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-// }
-//
-// public function testEmbargoUntilPublished()
-// {
-// $s1 = $this->objFromFixture(SiteTree::class, 's1');
-//
-// $doc = new DMSDocument();
-// $doc->Filename = "test file";
-// $doc->Folder = "0";
-// $dID = $doc->write();
-//
-// $s1->DocumentSets()->first()->getDocuments()->add($doc);
-//
-// $s1->publish('Stage', 'Live');
-// $s1->publishRecursive();
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->embargoUntilPublished();
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $s1->publish('Stage', 'Live');
-// $s1->publishRecursive();
-// $doc = DataObject::get_by_id(DMSDocument::class, $dID);
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->embargoUntilPublished();
-// $doc = DataObject::get_by_id(DMSDocument::class, $dID);
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->embargoIndefinitely();
-// $doc = DataObject::get_by_id(DMSDocument::class, $dID);
-// $this->assertTrue($doc->isHidden(), "Document is hidden");
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $s1->publish('Stage', 'Live');
-// $s1->publishRecursive();
-// $doc = DataObject::get_by_id(DMSDocument::class, $dID);
-// $this->assertTrue(
-// $doc->isHidden(),
-// "Document is still hidden because although the untilPublish flag is cleared, the indefinitely flag is there"
-// );
-// $this->assertTrue($doc->isEmbargoed(), "Document is embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-//
-// $doc->clearEmbargo();
-// $doc = DataObject::get_by_id(DMSDocument::class, $dID);
-// $this->assertFalse($doc->isHidden(), "Document is not hidden");
-// $this->assertFalse($doc->isEmbargoed(), "Document is not embargoed");
-// $this->assertFalse($doc->isExpired(), "Document is not expired");
-// }
+
}
diff --git a/tests/DMSFilesystemTestHelper.php b/tests/DMSFilesystemTestHelper.php
index feb25ee0..d8588213 100644
--- a/tests/DMSFilesystemTestHelper.php
+++ b/tests/DMSFilesystemTestHelper.php
@@ -10,7 +10,7 @@ class DMSFilesystemTestHelper
*
* @var array
*/
- protected static $dmsFiles = array('.htaccess', 'web.config');
+ protected static $dmsFiles = ['.htaccess', 'web.config'];
/**
* Deletes a directory and all files within it, or a file. Will automatically prepend the base path.
diff --git a/tests/DMSShortcodeHandlerTest.php b/tests/DMSShortcodeHandlerTest.php
index 1f557d2c..c2f23207 100644
--- a/tests/DMSShortcodeHandlerTest.php
+++ b/tests/DMSShortcodeHandlerTest.php
@@ -51,7 +51,7 @@ public function testShortcodeOperation()
public function testShortcodeWithContentReturnsParsedContentInLink()
{
$document = $this->objFromFixture(DMSDocument::class, 'd1');
- $arguments = array('id' => $document->ID);
+ $arguments = ['id' => $document->ID];
$result = DMSShortcodeHandler::handle($arguments, 'Some content', ShortcodeParser::get('default'), '');
$this->assertSame(
@@ -67,8 +67,8 @@ public function testShortcodeWithContentReturnsParsedContentInLink()
*/
public function testReturnErrorPageWhenIdIsEmpty()
{
- ErrorPage::create(array('URLSegment' => 'testing', 'ErrorCode' => '404'))->write();
- $result = DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), '');
+ ErrorPage::create(['URLSegment' => 'testing', 'ErrorCode' => '404'])->write();
+ $result = DMSShortcodeHandler::handle([], '', ShortcodeParser::get('default'), '');
$this->assertContains('testing', $result);
}
@@ -78,6 +78,6 @@ public function testReturnErrorPageWhenIdIsEmpty()
*/
public function testReturnEmptyStringWhenNoErrorPageExistsAndIdIsEmpty()
{
- $this->assertSame('', DMSShortcodeHandler::handle(array(), '', ShortcodeParser::get('default'), ''));
+ $this->assertSame('', DMSShortcodeHandler::handle([], '', ShortcodeParser::get('default'), ''));
}
}
diff --git a/tests/DMSTest.php b/tests/DMSTest.php
index 954f21d2..096c7b02 100644
--- a/tests/DMSTest.php
+++ b/tests/DMSTest.php
@@ -37,7 +37,7 @@ class DMSTest extends FunctionalTest
*
* {@inheritDoc}
*/
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
Config::modify()->update(DMS::class, 'folder_name', $this->testDmsPath);
@@ -50,7 +50,7 @@ public function setUp()
*
* {@inheritDoc}
*/
- public function tearDown()
+ public function tearDown(): void
{
parent::tearDown();
DMSFilesystemTestHelper::delete($this->testDmsPath);
@@ -65,7 +65,7 @@ public function testDMSStorage()
$this->assertTrue(
file_exists(
DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
- . DIRECTORY_SEPARATOR . $document->Filename
+ . DIRECTORY_SEPARATOR . $document->Filename
),
"Document file copied into DMS folder"
);
@@ -81,14 +81,14 @@ public function testDMSFolderSpanning()
$document = $this->dms->storeDocument($file);
$this->assertNotNull($document, "Document object created on run number: $i");
-/**
- * ### @@@@ START REPLACEMENT @@@@ ###
- * WHY: upgrade to SS4
- * OLD: ->getFullPath() (case sensitive)
- * NEW: ->getFilename() (COMPLEX)
- * EXP: You may need to add ASSETS_PATH."/" in front of this ...
- * ### @@@@ STOP REPLACEMENT @@@@ ###
- */
+ /**
+ * ### @@@@ START REPLACEMENT @@@@ ###
+ * WHY: upgrade to SS4
+ * OLD: ->getFullPath() (case sensitive)
+ * NEW: ->getFilename() (COMPLEX)
+ * EXP: You may need to add ASSETS_PATH."/" in front of this ...
+ * ### @@@@ STOP REPLACEMENT @@@@ ###
+ */
$this->assertTrue(file_exists($document->getFilename()));
$documents[] = $document;
}
@@ -100,13 +100,13 @@ public function testDMSFolderSpanning()
$this->assertTrue(
/**
- * ### @@@@ START REPLACEMENT @@@@ ###
- * WHY: upgrade to SS4
- * OLD: ->getFullPath() (case sensitive)
- * NEW: ->getFilename() (COMPLEX)
- * EXP: You may need to add ASSETS_PATH."/" in front of this ...
- * ### @@@@ STOP REPLACEMENT @@@@ ###
- */
+ * ### @@@@ START REPLACEMENT @@@@ ###
+ * WHY: upgrade to SS4
+ * OLD: ->getFullPath() (case sensitive)
+ * NEW: ->getFilename() (COMPLEX)
+ * EXP: You may need to add ASSETS_PATH."/" in front of this ...
+ * ### @@@@ STOP REPLACEMENT @@@@ ###
+ */
strpos($documents[$i]->getFilename(), DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR) !== false,
"Correct folder name for the documents. Document path contains reference to folder name '$folderName'"
);
@@ -137,7 +137,7 @@ public function testReplaceDocument()
$this->assertTrue(
file_exists(
DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
- . DIRECTORY_SEPARATOR . $document->Filename
+ . DIRECTORY_SEPARATOR . $document->Filename
),
"Document file copied into DMS folder"
);
diff --git a/tests/DMSVersioningTest.php b/tests/DMSVersioningTest.php
index 38bb0043..c802de5e 100755
--- a/tests/DMSVersioningTest.php
+++ b/tests/DMSVersioningTest.php
@@ -34,7 +34,7 @@ class DMSVersioningTest extends SapphireTest
*
* {@inheritDoc}
*/
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -50,7 +50,7 @@ public function setUp()
*
* {@inheritDoc}
*/
- public function tearDown()
+ public function tearDown(): void
{
parent::tearDown();
@@ -72,7 +72,7 @@ public function testDMSVersionStorage()
$this->assertTrue(
file_exists(
DMS::inst()->getStoragePath() . DIRECTORY_SEPARATOR . $document->Folder
- . DIRECTORY_SEPARATOR . $document->Filename
+ . DIRECTORY_SEPARATOR . $document->Filename
),
"Document file copied into DMS folder"
);
diff --git a/tests/cms/DMSDocumentAddControllerTest.php b/tests/cms/DMSDocumentAddControllerTest.php
index 8583cb50..ab00ba93 100644
--- a/tests/cms/DMSDocumentAddControllerTest.php
+++ b/tests/cms/DMSDocumentAddControllerTest.php
@@ -18,7 +18,7 @@ class DMSDocumentAddControllerTest extends FunctionalTest
*/
protected $controller;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->logInWithPermission();
@@ -36,7 +36,7 @@ public function testCurrentPageReturnsSiteTree()
$this->assertInstanceOf(SiteTree::class, $this->controller->currentPage());
$this->assertEmpty($this->controller->currentPage()->ID);
- $this->controller->setRequest(new HTTPRequest('GET', '/', array('page_id' => $page->ID)));
+ $this->controller->setRequest(new HTTPRequest('GET', '/', ['page_id' => $page->ID]));
$this->assertEquals($page->ID, $this->controller->currentPage()->ID, 'Specified page is loaded and returned');
}
@@ -50,7 +50,7 @@ public function testGetCurrentDocumentSetReturnsDocumentSet()
$this->assertInstanceOf(DMSDocumentSet::class, $this->controller->getCurrentDocumentSet());
$this->assertEmpty($this->controller->getCurrentDocumentSet()->ID, 'Singleton does not have an ID');
- $this->controller->setRequest(new HTTPRequest('GET', '/', array('dsid' => $set->ID)));
+ $this->controller->setRequest(new HTTPRequest('GET', '/', ['dsid' => $set->ID]));
$this->assertEquals($set->ID, $this->controller->getCurrentDocumentSet()->ID, 'Specified document set is returned');
}
@@ -60,11 +60,11 @@ public function testGetCurrentDocumentSetReturnsDocumentSet()
public function testGetAllowedExtensions()
{
Config::inst()->remove(File::class, 'allowed_extensions');
- Config::modify()->update(File::class, 'allowed_extensions', array('jpg', 'gif'));
- $this->assertSame(array('jpg', 'gif'), $this->controller->getAllowedExtensions());
+ Config::modify()->update(File::class, 'allowed_extensions', ['jpg', 'gif']);
+ $this->assertSame(['jpg', 'gif'], $this->controller->getAllowedExtensions());
- Config::modify()->update(DMSDocumentAddController::class, 'allowed_extensions', array('php', 'php5'));
- $this->assertSame(array('jpg', 'gif', 'php', 'php5'), $this->controller->getAllowedExtensions());
+ Config::modify()->update(DMSDocumentAddController::class, 'allowed_extensions', ['php', 'php5']);
+ $this->assertSame(['jpg', 'gif', 'php', 'php5'], $this->controller->getAllowedExtensions());
}
/**
@@ -77,13 +77,13 @@ public function testBacklink()
$this->assertContains('admin/documents', $this->controller->Backlink());
// No page ID, has document set ID
- $request = new HTTPRequest('GET', '/', array('dsid' => 123));
+ $request = new HTTPRequest('GET', '/', ['dsid' => 123]);
$this->controller->setRequest($request);
$this->assertContains('EditForm', $this->controller->Backlink());
$this->assertContains('123', $this->controller->Backlink());
// Has page ID and document set ID
- $request = new HTTPRequest('GET', '/', array('dsid' => 123, 'page_id' => 234));
+ $request = new HTTPRequest('GET', '/', ['dsid' => 123, 'page_id' => 234]);
$this->controller->setRequest($request);
$this->assertContains('admin/pages', $this->controller->Backlink());
$this->assertContains('123', $this->controller->Backlink());
diff --git a/tests/cms/DMSDocumentAdminTest.php b/tests/cms/DMSDocumentAdminTest.php
index 9104fe57..5f8c6df2 100644
--- a/tests/cms/DMSDocumentAdminTest.php
+++ b/tests/cms/DMSDocumentAdminTest.php
@@ -2,14 +2,13 @@
use Sunnysideup\DMS\Cms\DMSDocumentAdmin;
use Sunnysideup\DMS\Cms\DMSGridFieldAddNewButton;
-use Sunnysideup\DMS\Cms\DMSGridFieldEditButton;
use SilverStripe\Dev\FunctionalTest;
class DMSDocumentAdminTest extends FunctionalTest
{
protected static $fixture_file = 'DMSDocumentAdminTest.yml';
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -27,10 +26,9 @@ public function testGridFieldHasCustomisedButtons()
$form = $modelAdmin->getEditForm();
$gridFieldConfig = $form->Fields()->first()->getConfig();
- $replacements = array(
- 'GridFieldAddNewButton'=>DMSGridFieldAddNewButton::class,
- 'GridFieldEditButton'=>DMSGridFieldEditButton::class
- );
+ $replacements = [
+ 'GridFieldAddNewButton' => DMSGridFieldAddNewButton::class
+ ];
foreach ($replacements as $oldClass => $newClass) {
// Our button is an instance of the original, so is returned when asking for the original
diff --git a/tests/cms/DMSGridFieldAddNewButtonTest.php b/tests/cms/DMSGridFieldAddNewButtonTest.php
index 7246fded..22fdc173 100644
--- a/tests/cms/DMSGridFieldAddNewButtonTest.php
+++ b/tests/cms/DMSGridFieldAddNewButtonTest.php
@@ -10,7 +10,7 @@
class DMSGridFieldAddNewButtonTest extends SapphireTest
{
- protected static $fixture_file = 'dms/tests/dmstest.yml';
+ protected static $fixture_file = 'dmstest.yml';
/**
* @var DMSGridFieldAddNewButton
@@ -22,7 +22,7 @@ class DMSGridFieldAddNewButtonTest extends SapphireTest
*/
protected $gridField;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
diff --git a/tests/cms/DMSUploadFieldTest.php b/tests/cms/DMSUploadFieldTest.php
index 63d48ab3..22348ee3 100644
--- a/tests/cms/DMSUploadFieldTest.php
+++ b/tests/cms/DMSUploadFieldTest.php
@@ -11,7 +11,7 @@ class DMSUploadFieldTest extends SapphireTest
*/
protected $field;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
diff --git a/tests/cms/DMSUploadField_ItemHandlerTest.php b/tests/cms/DMSUploadField_ItemHandlerTest.php
index bf805757..98f4f683 100644
--- a/tests/cms/DMSUploadField_ItemHandlerTest.php
+++ b/tests/cms/DMSUploadField_ItemHandlerTest.php
@@ -15,7 +15,7 @@ class DMSUploadField_ItemHandlerTest extends SapphireTest
*/
protected $document;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
diff --git a/tests/extensions/DMSDocumentTaxonomyExtensionTest.php b/tests/extensions/DMSDocumentTaxonomyExtensionTest.php
index 739f1313..d978800f 100644
--- a/tests/extensions/DMSDocumentTaxonomyExtensionTest.php
+++ b/tests/extensions/DMSDocumentTaxonomyExtensionTest.php
@@ -7,7 +7,7 @@ class DMSDocumentTaxonomyExtensionTest extends SapphireTest
{
protected static $fixture_file = 'DMSDocumentTaxonomyExtensionTest.yml';
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
diff --git a/tests/extensions/DMSSiteTreeExtensionTest.php b/tests/extensions/DMSSiteTreeExtensionTest.php
index 4869a692..bccf282f 100644
--- a/tests/extensions/DMSSiteTreeExtensionTest.php
+++ b/tests/extensions/DMSSiteTreeExtensionTest.php
@@ -10,11 +10,11 @@
class DMSSiteTreeExtensionTest extends SapphireTest
{
- protected static $fixture_file = 'dms/tests/dmstest.yml';
+ protected static $fixture_file = 'dmstest.yml';
- protected static $required_extensions = array(
- 'SiteTree' => array(DMSSiteTreeExtension::class)
- );
+ protected static $required_extensions = [
+ 'SiteTree' => [DMSSiteTreeExtension::class]
+ ];
/**
* Ensure that setting the configuration property "documents_enabled" to false for a page type will prevent the
@@ -38,10 +38,10 @@ public function testCanDisableDocumentSetsTab($configSetting, $assertionMethod)
*/
public function documentSetEnabledConfigProvider()
{
- return array(
- array(true, 'assertNotNull'),
- array(false, 'assertNull')
- );
+ return [
+ [true, 'assertNotNull'],
+ [false, 'assertNull']
+ ];
}
/**
@@ -80,7 +80,7 @@ public function testOnBeforePublishUnEmbargoesDocumentsSetAsEmbargoedUntilPublis
$siteTree->publishRecursive();
// Fixture defines this page as having two documents via one set
- foreach (array('embargo-until-publish1', 'embargo-until-publish2') as $filename) {
+ foreach (['embargo-until-publish1', 'embargo-until-publish2'] as $filename) {
$this->assertFalse(
(bool) $siteTree->getAllDocuments()
->filter('Filename', 'embargo-until-publish1')
@@ -104,7 +104,7 @@ public function testGetRelatedDocumentsForAutocompleter()
$autocompleter = $gridField->getConfig()->getComponentByType(GridFieldAddExistingAutocompleter::class);
$jsonResult = $autocompleter->doSearch(
$gridField,
- new HTTPRequest('GET', '/', array('gridfield_relationsearch' => 'Document Set'))
+ new HTTPRequest('GET', '/', ['gridfield_relationsearch' => 'Document Set'])
);
$this->assertContains('Document Set not linked', $jsonResult);
diff --git a/tests/extensions/DMSTaxonomyTypeExtensionTest.php b/tests/extensions/DMSTaxonomyTypeExtensionTest.php
index ad85e74a..73368b0a 100644
--- a/tests/extensions/DMSTaxonomyTypeExtensionTest.php
+++ b/tests/extensions/DMSTaxonomyTypeExtensionTest.php
@@ -3,30 +3,31 @@
use Sunnysideup\DMS\Extensions\DMSTaxonomyTypeExtension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
+use SilverStripe\Taxonomy\TaxonomyType;
class DMSTaxonomyTypeExtensionTest extends SapphireTest
{
protected $usesDatabase = true;
- protected static $required_extensions = array(
- 'TaxonomyType' => array(DMSTaxonomyTypeExtension::class)
- );
+ protected static $required_extensions = [
+ 'TaxonomyType' => [DMSTaxonomyTypeExtension::class]
+ ];
/**
* Ensure that the configurable list of default records are created
*/
public function testDefaultRecordsAreCreated()
{
- Config::modify()->update(DMSTaxonomyTypeExtension::class, 'default_records', array('Food', 'Beverage', 'Books'));
+ Config::modify()->set(DMSTaxonomyTypeExtension::class, 'default_records', ['Food', 'Beverage', 'Books']);
TaxonomyType::create()->requireDefaultRecords();
- $this->assertDOSContains(
- array(
- array('Name' => 'Food'),
- array('Name' => 'Beverage'),
- array('Name' => 'Books'),
- ),
+ $this->assertContains(
+ [
+ ['Name' => 'Food'],
+ ['Name' => 'Beverage'],
+ ['Name' => 'Books'],
+ ],
TaxonomyType::get()
);
}
diff --git a/tests/forms/DMSJsonFieldTest.php b/tests/forms/DMSJsonFieldTest.php
deleted file mode 100644
index c5e9b67a..00000000
--- a/tests/forms/DMSJsonFieldTest.php
+++ /dev/null
@@ -1,53 +0,0 @@
-assertEquals($jsonField->FieldList()->count(), 2);
- $this->assertNotNull($jsonField->FieldList()->dataFieldByName('MyJsonField[FirstName]'));
-
- $jsonField = new DMSJsonField('MyJsonField', array(new TextField('FirstName', 'Given name'),
- new TextField('Surname', 'Last name')));
- $this->assertEquals($jsonField->FieldList()->count(), 2);
- $this->assertNotNull($jsonField->FieldList()->dataFieldByName('MyJsonField[FirstName]'));
-
- $jsonField = new DMSJsonField(
- 'MyJsonField',
- new TextField('FirstName', 'Given name'),
- new TextField('Surname', 'Last name')
- );
- $this->assertEquals($jsonField->FieldList()->count(), 2);
- $this->assertNotNull($jsonField->FieldList()->dataFieldByName('MyJsonField[FirstName]'));
- }
-
- public function testJsonFieldDataValueCouldDealWithArray()
- {
- $jsonField = new DMSJsonField('MyJsonField', new FieldList(
- new TextField('FirstName', 'Given name'),
- new TextField('Surname', 'Last name')
- ));
- $jsonField->setValue($value = array(
- 'MyJsonField'=>array(
- 'FirstName' => 'Normann',
- 'Surname' => 'Lou',
- ),
- ));
-
- $this->assertEquals($jsonField->dataValue(), Convert::array2json($value));
- $jsonField->setValue($value = array(
- 'MyJsonField'=>array(),
- ));
- $this->assertNull($jsonField->dataValue());
- }
-}
diff --git a/tests/tasks/MigrateToDocumentSetsTaskTest.php b/tests/tasks/MigrateToDocumentSetsTaskTest.php
index 4ada904a..a0496438 100644
--- a/tests/tasks/MigrateToDocumentSetsTaskTest.php
+++ b/tests/tasks/MigrateToDocumentSetsTaskTest.php
@@ -20,10 +20,10 @@ class MigrateToDocumentSetsTaskTest extends SapphireTest
*/
public function testCanOutputToCliOrBrowser($isCli, $expected)
{
- $lines = array('Test', 'Test line 2');
+ $lines = ['Test', 'Test line 2'];
$mock = $this->getMockBuilder(MigrateToDocumentSetsTask::class)
- ->setMethods(array('isCli'))
+ ->setMethods(['isCli'])
->getMock();
$mock->expects($this->exactly(2))
@@ -43,10 +43,10 @@ public function testCanOutputToCliOrBrowser($isCli, $expected)
*/
public function outputProvider()
{
- return array(
- array(true, 'Test' . PHP_EOL . 'Test line 2' . PHP_EOL),
- array(false, 'Test
Test line 2
')
- );
+ return [
+ [true, 'Test' . PHP_EOL . 'Test line 2' . PHP_EOL],
+ [false, 'Test
Test line 2
']
+ ];
}
/**
@@ -54,7 +54,7 @@ public function outputProvider()
*/
public function testShowErrorOnInvalidAction()
{
- $result = $this->runTask(array('action' => 'coffeetime'));
+ $result = $this->runTask(['action' => 'coffeetime']);
$this->assertContains('Error! Specified action is not valid.', $result);
}
@@ -65,7 +65,7 @@ public function testCreateDefaultDocumentSets()
{
$this->fixtureOldRelations();
- $result = $this->runTask(array('action' => 'create-default-document-set'));
+ $result = $this->runTask(['action' => 'create-default-document-set']);
$this->assertContains('Finished', $result);
// There are four pages in the fixture, but one of them already has a document set, so should be unchanged
$this->assertContains('Default document set added: 3', $result);
@@ -77,7 +77,7 @@ public function testCreateDefaultDocumentSets()
$this->assertCount(1, $this->objFromFixture(SiteTree::class, 'two')->DocumentSets());
// With dryrun enabled and being run the second time, nothing should be done
- $result = $this->runTask(array('action' => 'create-default-document-set', 'dryrun' => '1'));
+ $result = $this->runTask(['action' => 'create-default-document-set', 'dryrun' => '1']);
$this->assertContains('Skipped: already has a set: 4', $result);
$this->assertContains('NOTE: Dryrun mode enabled', $result);
}
@@ -90,15 +90,15 @@ public function testReassignDocumentsToFirstSet()
$this->fixtureOldRelations();
// Ensure default sets are created
- $this->runTask(array('action' => 'create-default-document-set'));
+ $this->runTask(['action' => 'create-default-document-set']);
// Dryrun check
- $result = $this->runTask(array('action' => 'reassign-documents', 'dryrun' => '1'));
+ $result = $this->runTask(['action' => 'reassign-documents', 'dryrun' => '1']);
$this->assertContains('NOTE: Dryrun mode enabled', $result);
$this->assertContains('Reassigned to document set: 3', $result);
// Actual run
- $result = $this->runTask(array('action' => 'reassign-documents'));
+ $result = $this->runTask(['action' => 'reassign-documents']);
$this->assertNotContains('NOTE: Dryrun mode enabled', $result);
$this->assertContains('Reassigned to document set: 3', $result);
@@ -130,19 +130,19 @@ protected function runTask(array $getVars)
protected function fixtureOldRelations()
{
if (!DB::get_schema()->hasTable('DMSDocument_Pages')) {
- DB::create_table('DMSDocument_Pages', array(
+ DB::create_table('DMSDocument_Pages', [
'DMSDocumentID' => 'int(11) null',
'SiteTreeID' => 'int(11) null'
- ));
+ ]);
}
$documentIds = $this->getFixtureFactory()->getIds(DMSDocument::class);
$pageIds = $this->getFixtureFactory()->getIds(SiteTree::class);
- foreach (array('one', 'two', 'three') as $fixtureName) {
+ foreach (['one', 'two', 'three'] as $fixtureName) {
$this->getFixtureFactory()->createRaw(
'DMSDocument_Pages',
'rln_' . $fixtureName,
- array('DMSDocumentID' => $documentIds[$fixtureName], 'SiteTreeID' => $pageIds[$fixtureName])
+ ['DMSDocumentID' => $documentIds[$fixtureName], 'SiteTreeID' => $pageIds[$fixtureName]]
);
}
}