Merge branch '4.2' into 4

This commit is contained in:
Robbie Averill 2018-09-06 13:26:46 +02:00
commit 373a8afeb5
5 changed files with 131 additions and 35 deletions

View File

@ -79,7 +79,9 @@ class CLIRequestBuilder extends HTTPRequestBuilder
$request = parent::createFromVariables($variables, $input, $url); $request = parent::createFromVariables($variables, $input, $url);
// unset scheme so that SS_BASE_URL can provide `is_https` information if required // unset scheme so that SS_BASE_URL can provide `is_https` information if required
$scheme = parse_url(Environment::getEnv('SS_BASE_URL'), PHP_URL_SCHEME); $scheme = parse_url(Environment::getEnv('SS_BASE_URL'), PHP_URL_SCHEME);
if ($scheme) {
$request->setScheme($scheme); $request->setScheme($scheme);
}
return $request; return $request;
} }

View File

@ -216,8 +216,46 @@ class TinyMCEConfig extends HTMLEditorConfig
* *
* @var array * @var array
*/ */
protected $settings = array( protected $settings = [
'fix_list_elements' => true, // https://www.tinymce.com/docs/configure/content-filtering/#fix_list_elements 'fix_list_elements' => true, // https://www.tinymce.com/docs/configure/content-filtering/#fix_list_elements
'formats' => [
'alignleft' => [
[
'selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,li',
'classes' =>'text-left'
],
[
'selector' => 'div,ul,ol,table,img,figure',
'classes' =>'left'
]
],
'aligncenter' => [
[
'selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,li',
'classes' =>'text-center'
],
[
'selector' => 'div,ul,ol,table,img,figure',
'classes' =>'center'
]
],
'alignright' => [
[
'selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,li',
'classes' =>'text-right'
],
[
'selector' => 'div,ul,ol,table,img,figure',
'classes' =>'right'
]
],
'alignjustify' => [
[
'selector' => 'p,h1,h2,h3,h4,h5,h6,td,th,li',
'classes' =>'text-justify'
],
],
],
'friendly_name' => '(Please set a friendly name for this config)', 'friendly_name' => '(Please set a friendly name for this config)',
'priority' => 0, // used for Per-member config override 'priority' => 0, // used for Per-member config override
'browser_spellcheck' => true, 'browser_spellcheck' => true,
@ -230,7 +268,7 @@ class TinyMCEConfig extends HTMLEditorConfig
'menubar' => false, 'menubar' => false,
'language' => 'en', 'language' => 'en',
'branding' => false, 'branding' => false,
); ];
/** /**
* Holder list of enabled plugins * Holder list of enabled plugins

View File

@ -7,9 +7,11 @@ use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Environment; use SilverStripe\Core\Environment;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Manifest\ClassLoader; use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Dev\DevelopmentAdmin; use SilverStripe\Dev\DevelopmentAdmin;
use SilverStripe\Dev\TestOnly; use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\FieldType\DBClassName;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
@ -337,35 +339,12 @@ class DatabaseAdmin extends Controller
} }
// Remap obsolete class names // Remap obsolete class names
$schema = DataObject::getSchema(); $remappingConfig = $this->config()->get('classname_value_remapping');
foreach ($this->config()->classname_value_remapping as $oldClassName => $newClassName) { $remappingFields = $this->getClassNameRemappingFields();
$baseDataClass = $schema->baseDataClass($newClassName); foreach ($remappingFields as $className => $fieldNames) {
$badRecordCount = DataObject::get($baseDataClass) foreach ($fieldNames as $fieldName) {
->filter(["ClassName" => $oldClassName ]) foreach ($remappingConfig as $oldClassName => $newClassName) {
->count(); $this->updateLegacyClassNames($className, $fieldName, $oldClassName, $newClassName);
if ($badRecordCount > 0) {
if (Director::is_cli()) {
echo " * Correcting $badRecordCount obsolete classname values for $newClassName\n";
} else {
echo "<li>Correcting $badRecordCount obsolete classname values for $newClassName</li>\n";
}
$table = $schema->baseDataTable($baseDataClass);
$updateQuery = "UPDATE \"$table%s\" SET \"ClassName\" = ? WHERE \"ClassName\" = ?";
$updateQueries = [sprintf($updateQuery, '')];
// Remap versioned table ClassName values as well
/** @var Versioned|DataObject $class */
$class = DataObject::singleton($newClassName);
if ($class->hasExtension(Versioned::class)) {
if ($class->hasStages()) {
$updateQueries[] = sprintf($updateQuery, '_Live');
}
$updateQueries[] = sprintf($updateQuery, '_Versions');
}
foreach ($updateQueries as $query) {
DB::prepared_query($query, [$newClassName, $oldClassName]);
} }
} }
} }
@ -408,6 +387,81 @@ class DatabaseAdmin extends Controller
ClassInfo::reset_db_cache(); ClassInfo::reset_db_cache();
} }
/**
* Given a base data class, a field name and an old and new class name (value), look for obsolete ($oldClassName)
* values in the $dataClass's $fieldName column and replace it with $newClassName.
*
* @param string $dataClass The data class to look up
* @param string $fieldName The field name to look in for obsolete class names
* @param string $oldClassName The old class name
* @param string $newClassName The new class name
*/
protected function updateLegacyClassNames($dataClass, $fieldName, $oldClassName, $newClassName)
{
$schema = DataObject::getSchema();
// Check first to ensure that the class has the specified field to update
if (!$schema->databaseField($dataClass, $fieldName, false)) {
return;
}
// Load a list of any records that have obsolete class names
$badRecordCount = DataObject::get($dataClass)
->filter([$fieldName => $oldClassName])
->count();
if (!$badRecordCount) {
return;
}
if (Director::is_cli()) {
echo " * Correcting {$badRecordCount} obsolete {$fieldName} values for {$newClassName}\n";
} else {
echo "<li>Correcting {$badRecordCount} obsolete {$fieldName} values for {$newClassName}</li>\n";
}
$table = $schema->tableName($dataClass);
$updateQuery = "UPDATE \"{$table}%s\" SET \"{$fieldName}\" = ? WHERE \"{$fieldName}\" = ?";
$updateQueries = [sprintf($updateQuery, '')];
// Remap versioned table class name values as well
/** @var Versioned|DataObject $class */
$class = DataObject::singleton($dataClass);
if ($class->hasExtension(Versioned::class)) {
if ($class->hasStages()) {
$updateQueries[] = sprintf($updateQuery, '_Live');
}
$updateQueries[] = sprintf($updateQuery, '_Versions');
}
foreach ($updateQueries as $query) {
DB::prepared_query($query, [$newClassName, $oldClassName]);
}
}
/**
* Find all DBClassName fields on valid subclasses of DataObject that should be remapped. This includes
* `ClassName` fields as well as polymorphic class name fields.
*
* @return array[]
*/
protected function getClassNameRemappingFields()
{
$dataClasses = ClassInfo::getValidSubClasses(DataObject::class);
$schema = DataObject::getSchema();
$remapping = [];
foreach ($dataClasses as $className) {
$fieldSpecs = $schema->fieldSpecs($className);
foreach ($fieldSpecs as $fieldName => $fieldSpec) {
if (Injector::inst()->create($fieldSpec, 'Dummy') instanceof DBClassName) {
$remapping[$className][] = $fieldName;
}
}
}
return $remapping;
}
/** /**
* Remove invalid records from tables - that is, records that don't have * Remove invalid records from tables - that is, records that don't have
* corresponding records in their parent class tables. * corresponding records in their parent class tables.

View File

@ -11,6 +11,7 @@ use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse; use SilverStripe\Control\HTTPResponse;
use SilverStripe\Control\HTTPResponse_Exception; use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
use SilverStripe\Control\RequestHandler; use SilverStripe\Control\RequestHandler;
use SilverStripe\Core\ClassInfo; use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
@ -494,6 +495,7 @@ class Security extends Controller implements TemplateGlobalProvider
*/ */
public function ping() public function ping()
{ {
HTTPCacheControlMiddleware::singleton()->disableCache();
Requirements::clear(); Requirements::clear();
return 1; return 1;
} }

View File

@ -156,11 +156,11 @@ class CmsFormsContext implements Context
if($formatting == 'bold') { if($formatting == 'bold') {
call_user_func($assertFn, 'strong', $matchedNode->nodeName); call_user_func($assertFn, 'strong', $matchedNode->nodeName);
} else if($formatting == 'left aligned') { } else if($formatting == 'left aligned') {
if($matchedNode->getAttribute('style')) { if($matchedNode->getAttribute('class')) {
call_user_func($assertFn, 'text-align: left;', $matchedNode->getAttribute('style')); call_user_func($assertFn, 'text-left', $matchedNode->getAttribute('class'));
} }
} else if($formatting == 'right aligned') { } else if($formatting == 'right aligned') {
call_user_func($assertFn, 'text-align: right;', $matchedNode->getAttribute('style')); call_user_func($assertFn, 'text-right', $matchedNode->getAttribute('class'));
} }
} }
// @codingStandardsIgnoreEnd // @codingStandardsIgnoreEnd