Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.5' into 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Damian Mooyman committed Dec 6, 2017
2 parents badeb0c + 975d462 commit 91cf850
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 54 deletions.
7 changes: 5 additions & 2 deletions admin/code/CMSBatchActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ class CMSBatchActionHandler extends RequestHandler {
'handleConfirmation',
);

/**
* @var Controller
*/
protected $parentController;

/**
* @var String
* @var string
*/
protected $urlSegment;

Expand All @@ -38,7 +41,7 @@ class CMSBatchActionHandler extends RequestHandler {
protected $recordClass = 'SiteTree';

/**
* @param string $parentController
* @param Controller $parentController
* @param string $urlSegment
* @param string $recordClass
*/
Expand Down
2 changes: 1 addition & 1 deletion admin/code/CMSMenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class CMSMenuItem extends Object {
* Attributes for the link. For instance, custom data attributes or standard
* HTML anchor properties.
*
* @var string
* @var array
*/
protected $attributes = array();

Expand Down
12 changes: 11 additions & 1 deletion admin/code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function init() {
Requirements::css(FRAMEWORK_DIR . '/css/GridField.css');

// Browser-specific requirements
$ie = isset($_SERVER['HTTP_USER_AGENT']) ? strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') : false;
$ie = isset($_SERVER['HTTP_USER_AGENT']) ? strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false : false;
if($ie) {
$version = substr($_SERVER['HTTP_USER_AGENT'], $ie + 5, 3);

Expand Down Expand Up @@ -1838,6 +1838,16 @@ class LeftAndMainMarkingFilter {
*/
protected $params = array();

/**
* @var array
*/
public $ids = array();

/**
* @var array
*/
public $expanded = array();

/**
* @param array $params Request params (unsanitized)
*/
Expand Down
2 changes: 1 addition & 1 deletion admin/code/SecurityAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getEditForm($id = null, $fields = null) {
$groupsTab->addExtraClass('ui-state-active');
} elseif($actionParam == 'users') {
$usersTab->addExtraClass('ui-state-active');
} elseif($actionParam == 'roles') {
} elseif($actionParam == 'roles' && isset($rolesTab)) {
$rolesTab->addExtraClass('ui-state-active');
}

Expand Down
1 change: 0 additions & 1 deletion admin/javascript/LeftAndMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ jQuery.noConflict();
}

var container = this.closest('.cms-container');
container.find('.cms-edit-form').tabs('select',0); //always switch to the first tab (list view) when searching
container.loadPanel(url, "", {}, true);

return false;
Expand Down
4 changes: 3 additions & 1 deletion admin/tests/LeftAndMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ public function testCanView() {
$adminuser = $this->objFromFixture('Member', 'admin');
$securityonlyuser = $this->objFromFixture('Member', 'securityonlyuser');
$allcmssectionsuser = $this->objFromFixture('Member', 'allcmssectionsuser');
$allValsFn = create_function('$obj', 'return $obj->getValue();');
$allValsFn = function($obj) {
return $obj->getValue();
};

// anonymous user
$this->session()->inst_set('loggedInAs', null);
Expand Down
18 changes: 10 additions & 8 deletions api/RestfulService.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ protected function parseRawHeaders($rawHeaders) {
if( preg_match('/([^:]+): (.+)/m', $field, $match) ) {
$match[1] = preg_replace_callback(
'/(?<=^|[\x09\x20\x2D])./',
create_function('$matches', 'return strtoupper($matches[0]);'),
function($matches) {
return strtoupper($matches[0]);
},
trim($match[1])
);
if( isset($headers[$match[1]]) ) {
Expand Down Expand Up @@ -418,7 +420,7 @@ public function getAttributes($xml, $collection=NULL, $element=NULL){
if($element)
$childElements = $xml->{$collection}->{$element};

if($childElements){
if(isset($childElements) && $childElements){
foreach($childElements as $child){
$data = array();
foreach($child->attributes() as $key => $value){
Expand Down Expand Up @@ -448,7 +450,7 @@ public function getAttribute($xml, $collection=NULL, $element=NULL, $attr){
if($element)
$childElements = $xml->{$collection}->{$element};

if($childElements)
if(isset($childElements[$attr]))
$attr_value = (string) $childElements[$attr];

return Convert::raw2xml($attr_value);
Expand All @@ -474,7 +476,7 @@ public function getValues($xml, $collection=NULL, $element=NULL){
if($element)
$childElements = $xml->{$collection}->{$element};

if($childElements){
if(isset($childElements) && $childElements){
foreach($childElements as $child){
$data = array();
$this->getRecurseValues($child,$data);
Expand Down Expand Up @@ -523,7 +525,7 @@ public function getValue($xml, $collection=NULL, $element=NULL){
if($element)
$childElements = $xml->{$collection}->{$element};

if($childElements)
if(isset($childElements) && $childElements)
return Convert::raw2xml($childElements);
}

Expand Down Expand Up @@ -573,7 +575,7 @@ class RestfulService_Response extends SS_HTTPResponse {
protected $simpleXML;

/**
* @var boolean It should be populated with cached request
* @var RestfulService_Response|false It should be populated with cached request
* when a request referring to this response was unsuccessful
*/
protected $cachedResponse = false;
Expand All @@ -600,14 +602,14 @@ public function simpleXML() {
* get the cached response object. This allows you to access the cached
* eaders, not just the cached body.
*
* @return RestfulSerivice_Response The cached response object
* @return RestfulService_Response|false The cached response object
*/
public function getCachedResponse() {
return $this->cachedResponse;
}

/**
* @return string
* @return string|false
*/
public function getCachedBody() {
if ($this->cachedResponse) {
Expand Down
2 changes: 1 addition & 1 deletion cli-script.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if(!isset($_GET)) $_GET = array();
if(!isset($_REQUEST)) $_REQUEST = array();
foreach($args as $arg) {
if(strpos($arg,'=') == false) {
if(strpos($arg,'=') === false) {
$_GET['args'][] = $arg;
} else {
$newItems = array();
Expand Down
2 changes: 1 addition & 1 deletion control/CookieJar.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function forceExpiry($name, $path = null, $domain = null, $secure = false
* @see http://uk3.php.net/manual/en/function.setcookie.php
*
* @param string $name The name of the cookie
* @param string|array $value The value for the cookie to hold
* @param string|array|false $value The value for the cookie to hold
* @param int $expiry The number of days until expiry
* @param string $path The path to save the cookie on (falls back to site base)
* @param string $domain The domain to make the cookie available on
Expand Down
4 changes: 3 additions & 1 deletion core/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,9 @@ protected function addWrapperMethod($method, $wrap) {
*/
protected function createMethod($method, $code) {
self::$extra_methods[get_class($this)][strtolower($method)] = array (
'function' => create_function('$obj, $args', $code)
'function' => function($obj, $args) use ($code) {
eval($code);
}
);
}

Expand Down
4 changes: 3 additions & 1 deletion dev/install/install.php5
Original file line number Diff line number Diff line change
Expand Up @@ -1307,7 +1307,9 @@ class Installer extends InstallRequirements {
$locale = isset($_POST['locale']) ? addcslashes($_POST['locale'], "\'") : 'en_US';
$type = addcslashes($config['db']['type'], "\'");
$dbConfig = $config['db'][$type];
$dbConfig = array_map(create_function('$v', 'return addcslashes($v, "\\\'");'), $dbConfig);
$dbConfig = array_map(function($v) {
return addcslashes($v, "\\'");
}, $dbConfig);
if(!isset($dbConfig['path'])) $dbConfig['path'] = '';
if(!$dbConfig) {
echo "<p style=\"color: red\">Bad config submitted</p><pre>";
Expand Down
4 changes: 3 additions & 1 deletion forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ public function getAttributesHTML($attrs = null) {
$attrs = $this->getAttributes();

// Remove empty
$attrs = array_filter((array)$attrs, create_function('$v', 'return ($v || $v === 0);'));
$attrs = array_filter((array)$attrs, function($v) {
return ($v || $v === 0);
});

// Remove excluded
if($exclude) $attrs = array_diff_key($attrs, array_flip($exclude));
Expand Down
6 changes: 4 additions & 2 deletions forms/ListboxField.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public function setMultiple($bool) {
public function setSource($source) {
if($source) {
$hasCommas = array_filter(array_keys($source),
create_function('$key', 'return strpos($key, ",") !== FALSE;'));
if($hasCommas) {
function($key) {
return strpos($key, ",") !== FALSE;
});
if(!empty($hasCommas)) {
throw new InvalidArgumentException('No commas allowed in $source keys');
}
}
Expand Down
2 changes: 1 addition & 1 deletion model/Versioned.php
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,7 @@ public function allVersions($filter = "", $sort = "", $limit = "", $join = "", $
$oldMode = self::get_reading_mode();
self::reading_stage('Stage');

$list = DataObject::get(get_class($this->owner), $filter, $sort, $join, $limit);
$list = DataObject::get(ClassInfo::baseDataClass($this->owner), $filter, $sort, $join, $limit);
if($having) $having = $list->having($having);

$query = $list->dataQuery()->query();
Expand Down
4 changes: 3 additions & 1 deletion model/fieldtypes/HTMLText.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ public function Summary($maxWords = 50, $flex = 15, $add = '...') {
$doc = new DOMDocument();

// Catch warnings thrown by loadHTML and turn them into a failure boolean rather than a SilverStripe error
set_error_handler(create_function('$no, $str', 'throw new Exception("HTML Parse Error: ".$str);'), E_ALL);
set_error_handler(function($no, $str) {
throw new Exception("HTML Parse Error: " . $str);
}, E_ALL);
// Nonbreaking spaces get converted into weird characters, so strip them
$value = str_replace('&nbsp;', ' ', $this->RAW());
try {
Expand Down
3 changes: 1 addition & 2 deletions security/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -984,8 +984,7 @@ public function onBeforeWrite() {
$encryption_details = Security::encrypt_password(
$this->Password, // this is assumed to be cleartext
$this->Salt,
($this->PasswordEncryption) ?
$this->PasswordEncryption : Security::config()->password_encryption_algorithm,
$this->isChanged('PasswordEncryption') ? $this->PasswordEncryption : null,
$this
);

Expand Down
8 changes: 6 additions & 2 deletions tests/forms/uploadfield/UploadFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,9 @@ public function testSelect() {
// A bit too much coupling with GridField, but a full template overload would make things too complex
$parser = new CSSContentParser($response->getBody());
$items = $parser->getBySelector('.ss-gridfield-item');
$itemIDs = array_map(create_function('$el', 'return (int)$el["data-id"];'), $items);
$itemIDs = array_map(function($el) {
return (int)$el["data-id"];
}, $items);
$this->assertContains($file4->ID, $itemIDs, 'Contains file in assigned folder');
$this->assertContains($fileSubfolder->ID, $itemIDs, 'Contains file in subfolder');
}
Expand All @@ -746,7 +748,9 @@ public function testSelectWithDisplayFolderName() {
// A bit too much coupling with GridField, but a full template overload would make things too complex
$parser = new CSSContentParser($response->getBody());
$items = $parser->getBySelector('.ss-gridfield-item');
$itemIDs = array_map(create_function('$el', 'return (int)$el["data-id"];'), $items);
$itemIDs = array_map(function($el) {
return (int)$el["data-id"];
}, $items);
$this->assertContains($file4->ID, $itemIDs, 'Contains file in assigned folder');
$this->assertNotContains($fileSubfolder->ID, $itemIDs, 'Does not contain file in subfolder');
}
Expand Down
42 changes: 17 additions & 25 deletions tests/security/MemberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,21 @@ public function tearDown() {
parent::tearDown();
}


public function testPasswordEncryptionUpdatedOnChangedPassword()
{
Config::inst()->update('Security', 'password_encryption_algorithm', 'none');
$member = Member::create();
$member->SetPassword = 'password';
$member->write();
$this->assertEquals('password', $member->Password);
$this->assertEquals('none', $member->PasswordEncryption);
Config::inst()->update('Security', 'password_encryption_algorithm', 'blowfish');
$member->SetPassword = 'newpassword';
$member->write();
$this->assertNotEquals('password', $member->Password);
$this->assertNotEquals('newpassword', $member->Password);
$this->assertEquals('blowfish', $member->PasswordEncryption);
}

/**
* @expectedException ValidationException
Expand Down Expand Up @@ -94,28 +108,6 @@ public function testDefaultPasswordEncryptionOnMember() {
);
}

public function testDefaultPasswordEncryptionDoesntChangeExistingMembers() {
$member = new Member();
$member->Password = 'mypassword';
$member->PasswordEncryption = 'sha1_v2.4';
$member->write();

$origAlgo = Security::config()->password_encryption_algorithm;
Security::config()->password_encryption_algorithm = 'none';

$member->Password = 'mynewpassword';
$member->write();

$this->assertEquals(
$member->PasswordEncryption,
'sha1_v2.4'
);
$result = $member->checkPassword('mynewpassword');
$this->assertTrue($result->valid());

Security::config()->password_encryption_algorithm = $origAlgo;
}

public function testKeepsEncryptionOnEmptyPasswords() {
$member = new Member();
$member->Password = 'mypassword';
Expand All @@ -126,8 +118,8 @@ public function testKeepsEncryptionOnEmptyPasswords() {
$member->write();

$this->assertEquals(
$member->PasswordEncryption,
'sha1_v2.4'
Security::config()->get('password_encryption_algorithm'),
$member->PasswordEncryption
);
$result = $member->checkPassword('');
$this->assertTrue($result->valid());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static protected function dumpArray($value)
if (
(1 == count($keys) && '0' == $keys[0])
||
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return (integer) $v + $w;'), 0) == count($keys) * (count($keys) - 1) / 2))
(count($keys) > 1 && array_reduce($keys, function($v,$w) { return (integer) $v + $w;}, 0) == count($keys) * (count($keys) - 1) / 2))
{
$output = array();
foreach ($value as $val)
Expand Down

0 comments on commit 91cf850

Please sign in to comment.