Skip to content

Commit

Permalink
Merge branch 'release/3.1.14'
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Feb 21, 2019
2 parents 457f0f4 + be1962d commit c917b9d
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 52 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG-v3.md
@@ -1,5 +1,22 @@
# Release Notes for Craft CMS 3.x

## 3.1.14 - 2019-02-21

### Added
- Added `craft\helpers\ProjectConfig::cleanupConfig()`.
- Added `craft\web\Request::$maxPageNum`, which determines the maximum page number Craft should accept (100,000 by default). ([#3880](https://github.com/craftcms/cms/issues/3880))

### Deprecated
- Deprecated `craft\mutex\FileMutex`.

### Fixed
- Fixed a bug where Craft could update the `dateModified` value in the project config even when nothing had changed. ([#3792](https://github.com/craftcms/cms/issues/3792))
- Fixed a SQL error that occurred when running the “Localizing relations” task if using PostgreSQL. ([#3877](https://github.com/craftcms/cms/issues/3877))
- Fixed a bug where file locking wasn’t working on Windows. ([#3879](https://github.com/craftcms/cms/issues/3879))

### Security
- Fixed a bug where sensitive environment variable values weren’t getting redacted correctly.

## 3.1.13 - 2019-02-20

### Added
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/bootstrap.php
Expand Up @@ -202,7 +202,7 @@
$cmsPath = $vendorPath . '/craftcms/cms';
$libPath = $cmsPath . '/lib';
$srcPath = $cmsPath . '/src';
require $srcPath . '/Yii.php';
require $libPath . '/yii2/Yii.php';
require $srcPath . '/Craft.php';

// Move Yii's autoloader to the end (Composer's is faster when optimized)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "craftcms/cms",
"description": "Craft CMS",
"version": "3.1.13",
"version": "3.1.14",
"keywords": [
"cms",
"craftcms",
Expand Down
File renamed without changes.
39 changes: 39 additions & 0 deletions lib/yii2/helpers/Inflector.php
@@ -0,0 +1,39 @@
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/

namespace yii\helpers;

use Craft;

/**
* @inheritdoc
*/
class Inflector extends BaseInflector
{
/**
* @inheritdoc
* @todo remove this once Yii 2.0.16.1 is released
*/
public static function camel2words($name, $ucwords = true)
{
$label = mb_strtolower(trim(str_replace([
'-',
'_',
'.',
], ' ', preg_replace('/(?<!\p{Lu})(\p{Lu})|(\p{Lu})(?=\p{Ll})/u', ' \0', $name))), self::encoding());

return $ucwords ? StringHelper::mb_ucwords($label, self::encoding()) : $label;
}

/**
* @return string
*/
private static function encoding(): string
{
return isset(Craft::$app) ? Craft::$app->charset : 'UTF-8';
}
}
11 changes: 10 additions & 1 deletion src/Craft.php
Expand Up @@ -11,8 +11,10 @@
use craft\db\Table;
use craft\helpers\FileHelper;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\FileCookieJar;
use yii\base\ExitException;
use yii\db\Expression;
use yii\helpers\Inflector;
use yii\helpers\VarDumper;
use yii\web\Request;

Expand Down Expand Up @@ -151,8 +153,15 @@ public static function cookieConfig(array $config = [], Request $request = null)
*/
public static function autoload($className)
{
// todo: remove this when Yii 2.0.16.1 is released
// Use our own Inflector class
if ($className === Inflector::class) {
require dirname(__DIR__) . '/lib/yii2/helpers/Inflector.php';
return;
}

// FileCookieJar is not supported
if ($className === 'GuzzleHttp\Cookie\FileCookieJar') {
if ($className === FileCookieJar::class) {
require dirname(__DIR__) . '/lib/guzzle/FileCookieJar.php';
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/app.php
Expand Up @@ -3,7 +3,7 @@
return [
'id' => 'CraftCMS',
'name' => 'Craft CMS',
'version' => '3.1.13',
'version' => '3.1.14',
'schemaVersion' => '3.1.25',
'minVersionRequired' => '2.6.2788',
'basePath' => dirname(__DIR__), // Defines the @app alias
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/App.php
Expand Up @@ -20,7 +20,6 @@
use craft\mail\Message;
use craft\mail\transportadapters\Sendmail;
use craft\models\MailSettings;
use craft\mutex\FileMutex;
use craft\services\ProjectConfig as ProjectConfigService;
use craft\web\AssetManager;
use craft\web\Request as WebRequest;
Expand All @@ -32,6 +31,7 @@
use yii\helpers\Inflector;
use yii\log\Dispatcher;
use yii\log\Logger;
use yii\mutex\FileMutex;

/**
* App helper.
Expand Down
29 changes: 29 additions & 0 deletions src/helpers/ProjectConfig.php
Expand Up @@ -110,4 +110,33 @@ public static function ensureAllUserGroupsProcessed()
}
}
}

/**
* Traverse and clean a config array, removing empty values and sorting keys.
*
* @param array $config Config array to clean
*
* @return array
*/
public static function cleanupConfig(array $config) {
$remove = [];
foreach ($config as $key => &$value) {
if (\is_array($value)) {
$value = static::cleanupConfig($value);

if (empty($value)) {
$remove[] = $key;
}
}
}

// Remove empty stuff
foreach ($remove as $removeKey) {
unset($config[$removeKey]);
}

ksort($config);

return $config;
}
}
25 changes: 1 addition & 24 deletions src/mutex/FileMutex.php
Expand Up @@ -14,33 +14,10 @@
/**
* @inheritdoc
* @see Mutex
* @todo Remove this class when Yii 2.0.11 comes out
* @author Pixel & Tonic, Inc. <support@pixelandtonic.com>
* @since 3.0
* @deprecated in 3.1.14. Use [[\yii\mutex\FileMutex]] instead.
*/
class FileMutex extends \yii\mutex\FileMutex
{
/**
* @inheritdoc
*/
public function init()
{
$mutexPath = Craft::getAlias($this->mutexPath);

if ($mutexPath === false) {
throw new Exception('There was a problem getting the mutex path.');
}
$this->mutexPath = $mutexPath;
if (!is_dir($this->mutexPath)) {
FileHelper::createDirectory($this->mutexPath, $this->dirMode, true);
}
}

/**
* @inheritdoc
*/
protected function getLockFilePath($name)
{
return $this->mutexPath . DIRECTORY_SEPARATOR . md5($name) . '.lock';
}
}
2 changes: 1 addition & 1 deletion src/queue/jobs/LocalizeRelations.php
Expand Up @@ -67,7 +67,7 @@ public function execute($queue)
->insert(
Table::RELATIONS,
[
'fieldid' => $this->fieldId,
'fieldId' => $this->fieldId,
'sourceId' => $relation['sourceId'],
'sourceSiteId' => $siteId,
'targetId' => $relation['targetId'],
Expand Down
29 changes: 7 additions & 22 deletions src/services/ProjectConfig.php
Expand Up @@ -14,12 +14,12 @@
use craft\helpers\DateTimeHelper;
use craft\helpers\FileHelper;
use craft\helpers\Json;
use craft\helpers\ProjectConfig as ProjectConfigHelper;
use craft\helpers\Path as PathHelper;
use Symfony\Component\Yaml\Yaml;
use yii\base\Application;
use yii\base\Component;
use yii\base\ErrorException;
use yii\base\Event;
use yii\base\Exception;
use yii\base\NotSupportedException;
use yii\web\ServerErrorHttpException;
Expand Down Expand Up @@ -341,6 +341,10 @@ public function get(string $path = null, $getFromYaml = false)
*/
public function set(string $path, $value)
{
if (\is_array($value)) {
$value = ProjectConfigHelper::cleanupConfig($value);
}

if ($value !== $this->get($path)) {
if ($this->readOnly) {
throw new NotSupportedException('Changes to the project config are not possible while in read-only mode.');
Expand Down Expand Up @@ -585,38 +589,19 @@ public function updateParsedConfigTimes(): bool
*/
public function saveModifiedConfigData()
{
$traverseAndClean = function(&$array) use (&$traverseAndClean) {
$remove = [];
foreach ($array as $key => &$value) {
if (\is_array($value)) {
$traverseAndClean($value);
if (empty($value)) {
$remove[] = $key;
}
}
}

// Remove empty stuff
foreach ($remove as $removeKey) {
unset($array[$removeKey]);
}

ksort($array);
};

if (!empty($this->_modifiedYamlFiles) && $this->_useConfigFile()) {
// Save modified yaml files

foreach (array_keys($this->_modifiedYamlFiles) as $filePath) {
$data = $this->_parsedConfigs[$filePath];
$traverseAndClean($data);
$data = ProjectConfigHelper::cleanupConfig($data);
FileHelper::writeToFile($filePath, Yaml::dump($data, 20, 2));
}
}

if (($this->_updateConfigMap && $this->_useConfigFile()) || $this->_updateConfig) {
$previousConfig = $this->_getStoredConfig();
$traverseAndClean($previousConfig);
$value = ProjectConfigHelper::cleanupConfig($previousConfig);
$this->_storeYamlHistory($previousConfig);

$info = Craft::$app->getInfo();
Expand Down
7 changes: 7 additions & 0 deletions src/web/Request.php
Expand Up @@ -59,6 +59,11 @@ class Request extends \yii\web\Request
'Forwarded',
];

/**
* @param int The highest page number that Craft should accept.
*/
public $maxPageNum = 100000;

/**
* @var
*/
Expand Down Expand Up @@ -240,6 +245,8 @@ public function init()
}
}

$this->_pageNum = min($this->_pageNum, $this->maxPageNum);

// Now that we've chopped off the admin/page segments, set the path
$this->_path = implode('/', $this->_segments);
}
Expand Down

0 comments on commit c917b9d

Please sign in to comment.