Skip to content

Commit

Permalink
Merge pull request #36 from silverstripe/bugfix/stable-branch-cleanup
Browse files Browse the repository at this point in the history
BUG: Stable branch cleanup
  • Loading branch information
mfendeksilverstripe authored Oct 21, 2021
2 parents 6777e41 + 6e84b03 commit 95f8759
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 130 deletions.
113 changes: 31 additions & 82 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,39 @@
language: php
version: ~> 1.0

dist: xenial
import:
- silverstripe/silverstripe-travis-shared:config/provision/standard.yml

services:
- mysql
- postgresql
- xvfb

cache:
directories:
- $HOME/.composer/cache/files

addons:
apt:
packages:
- tidy
- chromium-chromedriver
- chromium-browser

env:
global:
- DB=MYSQL
- COMPOSER_ROOT_VERSION=1.x-dev
- DISPLAY=":99"
- XVFBARGS=":99 -ac -screen 0 1024x768x16"
- SS_BASE_URL="http://localhost:8080/"
- SS_ENVIRONMENT_TYPE="dev"

matrix:
jobs:
include:
- php: 7.1
env: PHPUNIT_TEST=1
- php: 7.2
env: BEHAT_TEST=1
- php: 7.3
env: PHPUNIT_TEST=1
- php: 7.4
env: PHPUNIT_TEST=1
- php: 7.1
env: NPM_TEST=1
- php: 7.2
env: PHPCS_TEST=1
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev"
- PHPUNIT_TEST=1
- PHPCS_TEST=1
- PHPSTAN_TEST=1
- php: 7.3
env:
- DB=PGSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev"
- PHPUNIT_TEST=1

before_script:
# Extra $PATH
- export PATH=/usr/lib/chromium-browser/:$PATH

# Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini
- echo 'memory_limit = 2048M' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- echo 'always_populate_raw_post_data = -1' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini

# Install composer
- composer validate
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.x-dev --prefer-dist; fi
- composer require silverstripe/recipe-testing:^1 silverstripe/recipe-cms 4.x-dev --no-update --prefer-dist
- composer update

# Remove preinstalled Chrome (google-chrome)
# this would conflict with our chromium-browser installation
# and its version is incompatible with chromium-chromedriver
- sudo apt-get remove -y --purge google-chrome-stable || true

# Start behat services
- if [[ $BEHAT_TEST ]]; then mkdir artifacts; fi
- if [[ $BEHAT_TEST ]]; then cp composer.lock artifacts/; fi
- if [[ $BEHAT_TEST ]]; then sh -e /etc/init.d/xvfb start; sleep 3; fi
- if [[ $BEHAT_TEST ]]; then (chromedriver > artifacts/chromedriver.log 2>&1 &); fi
- if [[ $BEHAT_TEST ]]; then (vendor/bin/serve --bootstrap-file vendor/silverstripe/cms/tests/behat/serve-bootstrap.php &> artifacts/serve.log &); fi

# Install NPM dependencies
- if [[ $NPM_TEST ]]; then rm -rf client/dist && nvm install && nvm use && npm install -g yarn && yarn install --network-concurrency 1 && (cd vendor/silverstripe/admin && yarn install --network-concurrency 1) && yarn run build; fi

script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php; fi
- if [[ $NPM_TEST ]]; then git diff-files --quiet -w --relative=client; fi
- if [[ $NPM_TEST ]]; then git diff --name-status --relative=client; fi
- if [[ $NPM_TEST ]]; then yarn run test; fi
- if [[ $NPM_TEST ]]; then yarn run lint; fi
- if [[ $BEHAT_TEST ]]; then vendor/bin/behat @link; fi
- if [[ $PHPCS_TEST ]]; then composer run-script lint; fi

after_failure:
- php ./vendor/silverstripe/framework/tests/behat/travis-upload-artifacts.php --if-env BEHAT_TEST,ARTIFACTS_BUCKET,ARTIFACTS_KEY,ARTIFACTS_SECRET --target-path $TRAVIS_REPO_SLUG/$TRAVIS_BUILD_ID/$TRAVIS_JOB_ID --artifacts-base-url https://s3.amazonaws.com/$ARTIFACTS_BUCKET/ --artifacts-path ./artifacts/
- COW_TEST=1
- php: 7.4
env:
- DB=MYSQL
- PDO=1
- REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev"
- PHPUNIT_COVERAGE_TEST=1
- php: 7.4
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev"
- PHPUNIT_TEST=1
- REQUIRE_GRAPHQL="^3@dev"
- php: 8.0
env:
- DB=MYSQL
- REQUIRE_INSTALLER="$REQUIRE_RECIPE 4.x-dev"
- PHPUNIT_TEST=1
- REQUIRE_GRAPHQL="^3@dev"
- COMPOSER_INSTALL_ARG=--ignore-platform-reqs
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,32 @@

Experimental module looking at how we could implement a link field and a link data object.

# Sample usage
## Installation

Installation via composer.

### Stable version (GraphQL v3)

`composer require silverstripe/linkfield 1.x-dev`

### Experimental version (GraphQL v4)

`composer require silverstripe/linkfield 2.x-dev`

### Known issues

You may need to add the repository URL into your `composer.json` via the `repositories` field (example below).

```json
"repositories": {
"silverstripe/linkfield": {
"type": "git",
"url": "https://github.com/silverstripe/silverstripe-linkfield.git"
}
},
```

## Sample usage

```php
<?php
Expand Down
20 changes: 13 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"name": "silverstripe/link",
"name": "silverstripe/linkfield",
"description": "Add advanced link functionality to Silverstripe.",
"type": "silverstripe-vendormodule",
"require": {
"silverstripe/admin": "^1.5",
"silverstripe/admin": "^1.7",
"silverstripe/cms": "^4.7",
"silverstripe/asset-admin": "^1.7",
"silverstripe/graphql": "^3.4",
"silverstripe/vendor-plugin": "^1"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"silverstripe/cms": "^4.5",
"silverstripe/asset-admin": "^1.5"
"sminnee/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3"
},
"license": "BSD-3-Clause",
"authors": [
Expand All @@ -19,14 +21,18 @@
}
],
"extra": {
"branch-alias": {
"dev-master": "2.x-dev",
"dev-1": "1.x-dev"
},
"expose": [
"client/dist",
"client/lang"
]
},
"scripts": {
"lint": "phpcs -s code/ tests/",
"lint-clean": "phpcbf code/ tests/"
"lint": "phpcs src/ tests/php/",
"lint-clean": "phpcbf src/ tests/php/"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 20 additions & 18 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
</rule>
<file>src</file>
<file>tests</file>

<!-- base rules are PSR-2 -->
<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
<exclude name="PSR1.Files.SideEffects.FoundWithSymbols" />
<exclude name="PSR2.Classes.PropertyDeclaration" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration" /> <!-- causes php notice while linting -->
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.WrongOpenerdefault" />
<exclude name="PSR2.ControlStructures.SwitchDeclaration.TerminatingComment" />
<exclude name="PSR2.Methods.MethodDeclaration.Underscore" />
<exclude name="Squiz.Scope.MethodScope" />
<exclude name="Squiz.Classes.ValidClassName.NotCamelCaps" />
<exclude name="Generic.Files.LineLength.TooLong" />
<exclude name="PEAR.Functions.ValidDefaultValue.NotAtEnd" />
</rule>

<!-- PHP-PEG generated file not intended for human consumption -->
<exclude-pattern>*/SSTemplateParser.php$</exclude-pattern>
</ruleset>

13 changes: 6 additions & 7 deletions src/Form/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function saveInto(DataObjectInterface $record)
$jsonDataObject->write();
$record->{"{$fieldname}ID"} = $jsonDataObject->ID;
}

} elseif ((DataObject::getSchema()->databaseField(get_class($record), $fieldname))) {
$record->{$fieldname} = $value;
}
Expand All @@ -76,11 +75,12 @@ protected function parseString(string $value): ?array
$data = json_decode($value, true);

if (json_last_error() !== JSON_ERROR_NONE) {
var_dump($value);
throw new InvalidArgumentException(sprintf(
'%s: Could not parse provided JSON string. Failed with "%s"',
__CLASS__,
json_last_error_msg())
throw new InvalidArgumentException(
sprintf(
'%s: Could not parse provided JSON string. Failed with "%s"',
__CLASS__,
json_last_error_msg()
)
);
}

Expand All @@ -90,5 +90,4 @@ protected function parseString(string $value): ?array

return $data;
}

}
3 changes: 2 additions & 1 deletion src/JsonData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/**
* An object that can be serialize and deserialize to JSON.
*/
interface JsonData extends JsonSerializable {
interface JsonData extends JsonSerializable
{

/**
* @param array|JsonData $data
Expand Down
1 change: 0 additions & 1 deletion src/Models/EmailLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class EmailLink extends Link
public function generateLinkDescription(array $data): string
{
return isset($data['Email']) ? $data['Email'] : '';

}

public function getCMSFields()
Expand Down
1 change: 0 additions & 1 deletion src/Models/ExternalLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class ExternalLink extends Link
public function generateLinkDescription(array $data): string
{
return isset($data['ExternalUrl']) ? $data['ExternalUrl'] : '';

}

public function getURL()
Expand Down
8 changes: 3 additions & 5 deletions src/Models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class Link extends DataObject implements JsonData, Type

public function defineLinkTypeRequirements()
{
Requirements::add_i18n_javascript('silverstripe/link:client/lang', false, true);
Requirements::javascript('silverstripe/link:client/dist/js/bundle.js');
Requirements::css('silverstripe/link:client/dist/styles/bundle.css');
Requirements::add_i18n_javascript('silverstripe/linkfield:client/lang', false, true);
Requirements::javascript('silverstripe/linkfield:client/dist/js/bundle.js');
Requirements::css('silverstripe/linkfield:client/dist/styles/bundle.css');
}

public function LinkTypeHandlerName(): string
Expand Down Expand Up @@ -90,7 +90,6 @@ function setData($data): JsonData
} else {
$jsonData = Injector::inst()->create(get_class($type));
}

}

foreach ($data as $key => $value) {
Expand Down Expand Up @@ -141,5 +140,4 @@ public function forTemplate()
{
return $this->renderWith([self::class]);
}

}
3 changes: 1 addition & 2 deletions src/Models/SiteTreeLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function generateLinkDescription(array $data): string
}

$page = SiteTree::get()->byID($data['PageID']);
return $page ? $page->URLSegment : '';

return $page ? $page->URLSegment : '';
}

public function getCMSFields()
Expand Down Expand Up @@ -66,5 +66,4 @@ public function getURL()
}
return $url;
}

}
3 changes: 2 additions & 1 deletion src/ORM/DBJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public function nullValue()
return null;
}

public function setValue($value, $record = null, $markChanged = true) {
public function setValue($value, $record = null, $markChanged = true)
{
if (empty($value)) {
$value = null;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Type/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,20 @@ public function list(): array
*/
public function keys(): array
{

return [];
}

/**
* @return string[]
*/
public function keysEnabledByDefault(): array
{

return [];
}

public function init()
{
foreach ($this->list() as $type)
{
foreach ($this->list() as $type) {
$type->defineLinkTypeRequirements();
}
}
Expand Down
Loading

0 comments on commit 95f8759

Please sign in to comment.