Skip to content

Commit

Permalink
Merge pull request #190 from xini/pull-ss5
Browse files Browse the repository at this point in the history
Upgrade for SS5 and PHP 8.3
  • Loading branch information
nyeholt authored Sep 13, 2024
2 parents 2adf353 + 6f52f57 commit 6e8fda8
Show file tree
Hide file tree
Showing 19 changed files with 362 additions and 332 deletions.
16 changes: 0 additions & 16 deletions .upgrade.yml

This file was deleted.

14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ Registration can be enabled or disabled in the "Behaviour" tab.

## Composer Install

**SilverStripe 4.0+**
**SilverStripe 5**
```
composer require symbiote/silverstripe-memberprofiles:~4.0
composer require symbiote/silverstripe-memberprofiles:^5
```

**SilverStripe 4**
```
composer require symbiote/silverstripe-memberprofiles:^4
```

**[SilverStripe 3.1+](https://github.com/symbiote/silverstripe-memberprofiles/tree/2.0)**
```
composer require symbiote/silverstripe-memberprofiles:~2.0
composer require symbiote/silverstripe-memberprofiles:^2
```

## Requirements

* PHP 7.0+ (PHP 5.6 not supported due to: [Issue #141](https://github.com/symbiote/silverstripe-memberprofiles/issues/141))
* SilverStripe 4.0+
* SilverStripe 3.1+ || 4.0+ || 5.0+

## Documentation

Expand Down
9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
}
],
"require": {
"php": ">=7.0.0",
"silverstripe/cms": "^4.0"
"silverstripe/cms": "^5"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.0",
"phpunit/phpunit": "^5.7"
"squizlabs/php_codesniffer": "^3.5",
"phpunit/phpunit": "^9.6"
},
"scripts": {
"phpcbf": "phpcbf -n src/Email/ src/Extensions/ src/Forms/ src/Model/ src/Pages/ tests/"
"phpcbf": "phpcbf -n src/ tests/"
},
"suggest": {
"symbiote/silverstripe-gridfieldextensions": "Allows drag-and-drop reordering of fields"
Expand Down
33 changes: 21 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</whitelist>
</filter>
<?xml version="1.0"?>
<!-- phpunit.xml -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">.</directory>
</include>
<exclude>
<directory suffix=".php">tests/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Default">
<directory>tests</directory>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>sanitychecks</group>
</exclude>
</groups>
</phpunit>
37 changes: 11 additions & 26 deletions src/Email/MemberConfirmationEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Symbiote\MemberProfiles\Email;

use SilverStripe\Control\Director;
use Symbiote\MemberProfiles\Pages\MemberProfilePage;
use SilverStripe\Security\Member;
use SilverStripe\CMS\Model\SiteTree;
Expand Down Expand Up @@ -32,14 +33,14 @@ class MemberConfirmationEmail extends Email
*
* @var string
*/
const DEFAULT_SUBJECT = '$SiteName Member Activation';
public const DEFAULT_SUBJECT = '$SiteName Member Activation';

/**
* The default email template to use if none is provided.
*
* @var string
*/
const DEFAULT_TEMPLATE = '
public const DEFAULT_TEMPLATE = '
<p>
Dear $Member.Email,
</p>
Expand Down Expand Up @@ -77,7 +78,7 @@ class MemberConfirmationEmail extends Email
*
* @var string
*/
const TEMPLATE_NOTE = '
public const TEMPLATE_NOTE = '
<p>
The following special variables will be replaced in the email template and subject line:
</p>
Expand Down Expand Up @@ -115,22 +116,6 @@ public function __construct(MemberProfilePage $page, Member $member)
$this->setBody($this->getParsedString($page->EmailTemplate));
}

/**
* Deprecated. For backwards compatibility.
* NOTE(Jake): 2018-05-01, Removed for SS4 upgrade. Also removed $isSingleton param from __construct()
*
* @param string $string
* @param Member $member
* @param SiteTree $page
* @return string
*/
/*public static function get_parsed_string($string, Member $member, $page)
{
$class = get_called_class();
$inst = new $class($page, $member, true);
return $inst->getParsedString($string);
}*/

/**
* Replaces variables inside an email template according to {@link TEMPLATE_NOTE}.
*
Expand All @@ -148,13 +133,13 @@ public function getParsedString($string)
$createdDateObj = $member->obj('Created');

$absoluteBaseURL = $this->BaseURL();
$variables = array(
'$SiteName' => SiteConfig::current_site_config()->Title,
'$LoginLink' => Controller::join_links(
$variables = [
'$SiteName' => SiteConfig::current_site_config()->Title,
'$LoginLink' => Controller::join_links(
$absoluteBaseURL,
singleton(Security::class)->Link('login')
),
'$ConfirmLink' => Controller::join_links(
'$ConfirmLink' => Controller::join_links(
$this->page->AbsoluteLink('confirm'),
$member->ID,
"?key={$member->ValidationKey}"
Expand All @@ -164,8 +149,8 @@ public function getParsedString($string)
singleton(Security::class)->Link('lostpassword')
),
'$Member.Created' => $createdDateObj->Nice()
);
foreach (array('Name', 'FirstName', 'Surname', 'Email') as $field) {
];
foreach (['Name', 'FirstName', 'Surname', 'Email'] as $field) {
$variables["\$Member.$field"] = $member->$field;
}
$this->extend('updateEmailVariables', $variables);
Expand All @@ -175,7 +160,7 @@ public function getParsedString($string)

public function BaseURL()
{
$absoluteBaseURL = parent::BaseURL();
$absoluteBaseURL = Director::absoluteBaseURL();
$this->extend('updateBaseURL', $absoluteBaseURL);
return $absoluteBaseURL;
}
Expand Down
85 changes: 55 additions & 30 deletions src/Extensions/MemberProfileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
*/
class MemberProfileExtension extends DataExtension
{
private static $db = array(
'ValidationKey' => 'Varchar(40)',
private static $db = [
'ValidationKey' => 'Varchar(40)',
'NeedsValidation' => 'Boolean',
'NeedsApproval' => 'Boolean',
'NeedsApproval' => 'Boolean',
'PublicFieldsRaw' => 'Text'
);
];

private static $has_one = array(
private static $has_one = [
'ProfilePage' => MemberProfilePage::class
);
];

public function getPublicFields()
{
return (array) unserialize($this->owner->getField('PublicFieldsRaw'));
return (array) unserialize($this->owner->getField('PublicFieldsRaw') ?? '');
}

public function setPublicFields($fields)
Expand All @@ -49,7 +49,6 @@ public function canLogIn(ValidationResult $result)
'An administrator must confirm your account before you can log in.'
));
}

if ($this->owner->NeedsValidation) {
$result->addError(_t(
'MemberProfiles.NEEDSVALIDATIONTOLOGIN',
Expand Down Expand Up @@ -104,7 +103,7 @@ public function updateMemberFormFields($fields)
// For now we just pass an empty array as the list of selectable groups -
// it's up to anything that uses this to populate it appropriately
$existing = $this->owner->Groups();
$fields->push(new CheckboxSetField('Groups', 'Groups', array(), $existing));
$fields->push(new CheckboxSetField('Groups', 'Groups', [], $existing));
}

public function updateCMSFields(FieldList $fields)
Expand All @@ -128,31 +127,57 @@ public function updateCMSFields(FieldList $fields)
'This user has not yet been approved. They cannot log in until their account is approved.'
);

$fields->addFieldsToTab('Root.Main', array(
$fields->addFieldsToTab('Root.Main', [
// ApprovalAnchor is used by MemberApprovalController (2017-02-01)
new LiteralField('ApprovalAnchor', "<div id=\"MemberProfileRegistrationApproval\"></div>"),
new HeaderField('ApprovalHeader', _t('MemberProfiles.REGAPPROVAL', 'Registration Approval')),
new LiteralField('ApprovalNote', "<p>$note</p>"),
new DropdownField('NeedsApproval', '', array(
true => _t('MemberProfiles.DONOTCHANGE', 'Do not change'),
false => _t('MemberProfiles.APPROVETHISMEMBER', 'Approve this member')
))
));
new LiteralField(
'ApprovalAnchor',
"<div id=\"MemberProfileRegistrationApproval\"></div>"
),
new HeaderField(
'ApprovalHeader',
_t('MemberProfiles.REGAPPROVAL', 'Registration Approval')
),
new LiteralField(
'ApprovalNote',
"<p>$note</p>"
),
new DropdownField(
'NeedsApproval',
'',
[
true => _t('MemberProfiles.DONOTCHANGE', 'Do not change'),
false => _t('MemberProfiles.APPROVETHISMEMBER', 'Approve this member')
]
),
]);
}

if ($this->owner->NeedsValidation) {
$fields->addFieldsToTab('Root.Main', array(
new HeaderField('ConfirmationHeader', _t('MemberProfiles.EMAILCONFIRMATION', 'Email Confirmation')),
new LiteralField('ConfirmationNote', '<p>' . _t(
'MemberProfiles.NOLOGINTILLCONFIRMED',
'The member cannot log in until their account is confirmed.'
) . '</p>'),
new DropdownField('ManualEmailValidation', '', array (
'unconfirmed' => _t('MemberProfiles.UNCONFIRMED', 'Unconfirmed'),
'resend' => _t('MemberProfiles.RESEND', 'Resend confirmation email'),
'confirm' => _t('MemberProfiles.MANUALLYCONFIRM', 'Manually confirm')
))
));
$fields->addFieldsToTab(
'Root.Main',
[
new HeaderField(
'ConfirmationHeader',
_t('MemberProfiles.EMAILCONFIRMATION', 'Email Confirmation')
),
new LiteralField(
'ConfirmationNote',
'<p>' . _t(
'MemberProfiles.NOLOGINTILLCONFIRMED',
'The member cannot log in until their account is confirmed.'
) . '</p>'
),
new DropdownField(
'ManualEmailValidation',
'',
[
'unconfirmed' => _t('MemberProfiles.UNCONFIRMED', 'Unconfirmed'),
'resend' => _t('MemberProfiles.RESEND', 'Resend confirmation email'),
'confirm' => _t('MemberProfiles.MANUALLYCONFIRM', 'Manually confirm')
]
)
]
);
}
}
}
8 changes: 4 additions & 4 deletions src/Forms/CheckableVisibilityField.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function makeAlwaysVisible()
* @param array|MemberProfileExtension $data {@see Form::loadDataFrom}
* @return $this
*/
public function setValue($value, $data = array())
public function setValue($value, $data = [])
{
$this->child->setValue($value);

Expand Down Expand Up @@ -113,9 +113,9 @@ public function saveInto(DataObjectInterface $record)
$public = $record->getPublicFields();

if ($this->checkbox->dataValue()) {
$public = array_merge($public, array($this->name));
$public = array_merge($public, [$this->name]);
} else {
$public = array_diff($public, array($this->name));
$public = array_diff($public, [$this->name]);
}

$record->setPublicFields($public);
Expand Down Expand Up @@ -149,7 +149,7 @@ public function setForm($form)
return parent::setForm($form);
}

public function Field($properties = array())
public function Field($properties = [])
{
return DBHTMLText::create_field(
'HTMLFragment',
Expand Down
5 changes: 3 additions & 2 deletions src/Forms/MemberProfileValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Symbiote\MemberProfiles\Forms;

use SilverStripe\Security\Security;
use Symbiote\MemberProfiles\Model\MemberProfileField;
use SilverStripe\Security\Member;
use SilverStripe\Core\Convert;
Expand Down Expand Up @@ -87,8 +88,8 @@ public function php($data)

// This ensures the existing member isn't the same as the current member, in case they're updating information.

if ($current = Member::currentUserID()) {
$existing = $existing->filter('ID:not', $current);
if ($current = Security::getCurrentUser()) {
$existing = $existing->filter('ID:not', $current->ID);
}
$emailOK = !$existing->first();
}
Expand Down
Loading

0 comments on commit 6e8fda8

Please sign in to comment.