From 5a5ba1e5c001de161fbeb19d6d662391dccc4c1e Mon Sep 17 00:00:00 2001 From: Jonathon Menz Date: Fri, 1 Jun 2018 12:52:22 -0700 Subject: [PATCH 1/7] Fix: negative values in read only currency field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t strip out ‘-‘ character as this makes negative values appear to be positive (Fixes #8126) --- src/Forms/CurrencyField_Disabled.php | 2 +- src/Forms/CurrencyField_Readonly.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Forms/CurrencyField_Disabled.php b/src/Forms/CurrencyField_Disabled.php index 26a5106f8..7e743755e 100644 --- a/src/Forms/CurrencyField_Disabled.php +++ b/src/Forms/CurrencyField_Disabled.php @@ -22,7 +22,7 @@ class CurrencyField_Disabled extends CurrencyField { if ($this->value) { $val = Convert::raw2xml($this->value); - $val = _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/', "", $val), 2); + $val = _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.-]/', "", $val), 2); $valforInput = Convert::raw2att($val); } else { $valforInput = ''; diff --git a/src/Forms/CurrencyField_Readonly.php b/src/Forms/CurrencyField_Readonly.php index 866c09c61..775b9eb6b 100644 --- a/src/Forms/CurrencyField_Readonly.php +++ b/src/Forms/CurrencyField_Readonly.php @@ -20,7 +20,7 @@ class CurrencyField_Readonly extends ReadonlyField { if ($this->value) { $val = Convert::raw2xml($this->value); - $val = _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.]/', "", $val), 2); + $val = _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . number_format(preg_replace('/[^0-9.-]/', "", $val), 2); $valforInput = Convert::raw2att($val); } else { $val = '' . _t('SilverStripe\\Forms\\CurrencyField.CURRENCYSYMBOL', '$') . '0.00'; From 1cbf27e0f47c3547914b03193d0f5f77c87ff8d5 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Tue, 29 May 2018 14:16:10 +1200 Subject: [PATCH 2/7] FIX PHP 5.3 compat for referencing $this in closure, and make method public for same reason sdf --- security/Member.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/security/Member.php b/security/Member.php index cd1d22518..ea06793df 100644 --- a/security/Member.php +++ b/security/Member.php @@ -1052,7 +1052,7 @@ class Member extends DataObject implements TemplateGlobalProvider { * * @return int[] List of group IDs */ - protected function disallowedGroups() { + public function disallowedGroups() { // unless the current user is an admin already OR the logged in user is an admin if (Permission::check('ADMIN') || Permission::checkMember($this, 'ADMIN')) { return array(); @@ -1476,7 +1476,7 @@ class Member extends DataObject implements TemplateGlobalProvider { if(Permission::check('EDIT_PERMISSIONS')) { // Filter allowed groups $groups = Group::get(); - $disallowedGroupIDs = $this->disallowedGroups(); + $disallowedGroupIDs = $self->disallowedGroups(); if ($disallowedGroupIDs) { $groups = $groups->exclude('ID', $disallowedGroupIDs); } From c1b0c56788a3ca230cbc76a2f38ee4300a678730 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Sat, 2 Jun 2018 20:44:33 +1200 Subject: [PATCH 3/7] Increase memory limit to 2G in Travis builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3cb849f4a..77a77322e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,6 +34,7 @@ before_script: - composer self-update || true - phpenv rehash - phpenv config-rm xdebug.ini + - echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini - git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support - "if [ \"$BEHAT_TEST\" = \"\" ] && [ \"$CMS_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss; fi" - "if [ \"$BEHAT_TEST\" = \"1\" ] && [ \"$CMS_TEST\" = \"\" ]; then php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require silverstripe/behat-extension; fi" From 41e601a036307065d9ea2ba8862f67be738d402f Mon Sep 17 00:00:00 2001 From: Daniel Hensby Date: Mon, 4 Jun 2018 15:17:05 +0100 Subject: [PATCH 4/7] FIX Regression from #8009 --- tests/model/DataObjectDuplicationTest.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tests/model/DataObjectDuplicationTest.php b/tests/model/DataObjectDuplicationTest.php index 2fcab1c4d..7f73bf6a2 100644 --- a/tests/model/DataObjectDuplicationTest.php +++ b/tests/model/DataObjectDuplicationTest.php @@ -83,6 +83,13 @@ class DataObjectDuplicationTest extends SapphireTest { $two = DataObject::get_by_id("DataObjectDuplicateTestClass2", $two->ID); $three = DataObject::get_by_id("DataObjectDuplicateTestClass3", $three->ID); + $this->assertCount(1, $one->twos(), + "Many-to-one relation not copied (has_many)"); + $this->assertCount(1, $one->threes(), + "Object has the correct number of relations"); + $this->assertCount(1, $three->ones(), + "Object has the correct number of relations"); + //test duplication $oneCopy = $one->duplicate(); $twoCopy = $two->duplicate(); @@ -100,16 +107,16 @@ class DataObjectDuplicationTest extends SapphireTest { $this->assertEquals($text2, $twoCopy->text); $this->assertEquals($text3, $threeCopy->text); - $this->assertNotEquals($one->twos()->Count(), $oneCopy->twos()->Count(), + $this->assertCount(0, $oneCopy->twos(), "Many-to-one relation not copied (has_many)"); - $this->assertEquals($one->threes()->Count(), $oneCopy->threes()->Count(), + $this->assertCount(2, $oneCopy->threes(), "Object has the correct number of relations"); - $this->assertEquals($three->ones()->Count(), $threeCopy->ones()->Count(), + $this->assertCount(2, $threeCopy->ones(), "Object has the correct number of relations"); $this->assertEquals($one->ID, $twoCopy->one()->ID, "Match between relation of copy and the original"); - $this->assertEquals(0, $oneCopy->twos()->Count(), + $this->assertCount(0, $oneCopy->twos(), "Many-to-one relation not copied (has_many)"); $this->assertEquals($three->ID, $oneCopy->threes()->First()->ID, "Match between relation of copy and the original"); @@ -142,6 +149,8 @@ class DataObjectDuplicateTestClass1 extends DataObject implements TestOnly { 'TestExtra' => 'Varchar' ) ); + + private static $default_sort = '"ID" ASC'; } class DataObjectDuplicateTestClass2 extends DataObject implements TestOnly { @@ -154,6 +163,8 @@ class DataObjectDuplicateTestClass2 extends DataObject implements TestOnly { 'one' => 'DataObjectDuplicateTestClass1' ); + private static $default_sort = '"ID" ASC'; + } class DataObjectDuplicateTestClass3 extends DataObject implements TestOnly { @@ -165,6 +176,8 @@ class DataObjectDuplicateTestClass3 extends DataObject implements TestOnly { private static $belongs_many_many = array( 'ones' => 'DataObjectDuplicateTestClass1' ); + + private static $default_sort = '"ID" ASC'; } From 66f57bd4dac0bd4c8106f8071ddc45103c2643f2 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Thu, 7 Jun 2018 10:24:27 +0100 Subject: [PATCH 5/7] FIX: Only set MYSQL_ATTR_INIT_COMMAND when using mysql driver (fixes #8103) --- src/ORM/Connect/PDOConnector.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ORM/Connect/PDOConnector.php b/src/ORM/Connect/PDOConnector.php index ca4cf309f..f3fbae164 100644 --- a/src/ORM/Connect/PDOConnector.php +++ b/src/ORM/Connect/PDOConnector.php @@ -176,9 +176,11 @@ class PDOConnector extends DBConnector if (!isset($charset)) { $charset = $connCharset; } - $options = array( - PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . $charset . ' COLLATE ' . $connCollation - ); + + $options = []; + if ($parameters['driver'] === 'mysql') { + $options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES ' . $charset . ' COLLATE ' . $connCollation; + } // Set SSL options if they are defined if (array_key_exists('ssl_key', $parameters) && From e37e3e1746e56c866ee875f41a7fddf61c926d9f Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 8 Jun 2018 11:23:24 +1200 Subject: [PATCH 6/7] BUG Fix test that relies on implicit ID order breaking postgres --- tests/php/ORM/DataObjectDuplicationTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/php/ORM/DataObjectDuplicationTest.php b/tests/php/ORM/DataObjectDuplicationTest.php index 09c88d821..57e5b8bb7 100644 --- a/tests/php/ORM/DataObjectDuplicationTest.php +++ b/tests/php/ORM/DataObjectDuplicationTest.php @@ -151,14 +151,14 @@ class DataObjectDuplicationTest extends SapphireTest $oneCopy->twos()->Count(), "Many-to-one relation not copied (has_many)" ); - $this->assertEquals( + $this->assertContains( $three->ID, - $oneCopy->threes()->First()->ID, + $oneCopy->threes()->column('ID'), "Match between relation of copy and the original" ); - $this->assertEquals( + $this->assertContains( $one->ID, - $threeCopy->ones()->First()->ID, + $threeCopy->ones()->column('ID'), "Match between relation of copy and the original" ); From 29f9b1c18fb38dab912a0b9dcae63eacae19335d Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 8 Jun 2018 11:38:36 +1200 Subject: [PATCH 7/7] Fix linting issues --- src/Forms/HTMLEditor/HTMLEditorSanitiser.php | 19 ++++++------------- src/ORM/Queries/SQLSelect.php | 3 +-- src/View/Parsers/ShortcodeParser.php | 15 +++++---------- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Forms/HTMLEditor/HTMLEditorSanitiser.php b/src/Forms/HTMLEditor/HTMLEditorSanitiser.php index ca4e5f407..343e8253b 100644 --- a/src/Forms/HTMLEditor/HTMLEditorSanitiser.php +++ b/src/Forms/HTMLEditor/HTMLEditorSanitiser.php @@ -4,7 +4,6 @@ namespace SilverStripe\Forms\HTMLEditor; use DOMAttr; use DOMElement; -use DOMNode; use SilverStripe\Core\Injector\Injectable; use SilverStripe\View\Parsers\HTMLValue; use stdClass; @@ -114,24 +113,20 @@ class HTMLEditorSanitiser if ($attrType === '!') { $element->attributesRequired[] = $attrName; $attr->required = true; - } // Denied from global - elseif ($attrType === '-') { + } elseif ($attrType === '-') { // Denied from global unset($element->attributes[$attrName]); continue; } // Default value if ($prefix) { - // Default value - if ($prefix === '=') { + if ($prefix === '=') { // Default value $element->attributesDefault[$attrName] = $value; $attr->defaultValue = $value; - } // Forced value - elseif ($prefix === ':') { + } elseif ($prefix === ':') { // Forced value $element->attributesForced[$attrName] = $value; $attr->forcedValue = $value; - } // Required values - elseif ($prefix === '<') { + } elseif ($prefix === '<') { // Required values $attr->validValues = explode('?', $value); } } @@ -290,8 +285,7 @@ class HTMLEditorSanitiser // If it's a script or style, we don't keep contents if ($el->tagName === 'script' || $el->tagName === 'style') { $el->parentNode->removeChild($el); - } // Otherwise we replace this node with all it's children - else { + } else { // Otherwise we replace this node with all it's children // First, create a new fragment with all of $el's children moved into it $frag = $doc->createDocumentFragment(); while ($el->firstChild) { @@ -301,8 +295,7 @@ class HTMLEditorSanitiser // Then replace $el with the frags contents (which used to be it's children) $el->parentNode->replaceChild($frag, $el); } - } // Otherwise tidy the element - else { + } else { // Otherwise tidy the element // First, if we're supposed to pad & this element is empty, fix that if ($elementRule->paddEmpty && !$el->firstChild) { $el->nodeValue = ' '; diff --git a/src/ORM/Queries/SQLSelect.php b/src/ORM/Queries/SQLSelect.php index 8eef054e4..50f67c3f3 100644 --- a/src/ORM/Queries/SQLSelect.php +++ b/src/ORM/Queries/SQLSelect.php @@ -622,8 +622,7 @@ class SQLSelect extends SQLConditionalExpression if (!empty($this->having)) { $records = $this->execute(); return $records->numRecords(); - } // Choose a default column - elseif ($column == null) { + } elseif ($column == null) { // Choose a default column if ($this->groupby) { $column = 'DISTINCT ' . implode(", ", $this->groupby); } else { diff --git a/src/View/Parsers/ShortcodeParser.php b/src/View/Parsers/ShortcodeParser.php index 37be5c631..0a70ea089 100644 --- a/src/View/Parsers/ShortcodeParser.php +++ b/src/View/Parsers/ShortcodeParser.php @@ -573,8 +573,7 @@ class ShortcodeParser } elseif ($location == self::AFTER) { // Move after block parent $this->insertAfter($node, $parent); - } // Split parent at node - elseif ($location == self::SPLIT) { + } elseif ($location == self::SPLIT) { // Split parent at node $at = $node; $splitee = $node->parentNode; @@ -593,8 +592,7 @@ class ShortcodeParser } $this->insertAfter($node, $parent); - } // Do nothing - elseif ($location == self::INLINE) { + } elseif ($location == self::INLINE) { // Do nothing if (in_array(strtolower($node->tagName), self::$block_level_elements)) { user_error( 'Requested to insert block tag ' . $node->tagName . ' inline - probably this will break HTML compliance', @@ -638,7 +636,6 @@ class ShortcodeParser */ public function parse($content) { - $this->extend('onBeforeParse', $content); $continue = true; @@ -646,11 +643,9 @@ class ShortcodeParser // If no shortcodes defined, don't try and parse any if (!$this->shortcodes) { $continue = false; - } // If no content, don't try and parse it - elseif (!trim($content)) { + } elseif (!trim($content)) { // If no content, don't try and parse it $continue = false; - } // If no shortcode tag, don't try and parse it - elseif (strpos($content, '[') === false) { + } elseif (strpos($content, '[') === false) { // If no shortcode tag, don't try and parse it $continue = false; } @@ -659,7 +654,7 @@ class ShortcodeParser // use a proper DOM list($content, $tags) = $this->replaceElementTagsWithMarkers($content); - /** @var HTMLValue $htmlvalue */ + /** @var HTMLValue $htmlvalue */ $htmlvalue = Injector::inst()->create('HTMLValue', $content); // Now parse the result into a DOM