mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Ensure flush destroys temp tinymce files
This commit is contained in:
parent
34ca944bd6
commit
06efd2ac12
@ -80,15 +80,19 @@ abstract class HTMLEditorConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a new config for the given identifier
|
||||
* Assign a new config, or clear existing, for the given identifier
|
||||
*
|
||||
* @param string $identifier A specific identifier
|
||||
* @param HTMLEditorConfig $config
|
||||
* @param HTMLEditorConfig $config Config to set, or null to clear
|
||||
* @return HTMLEditorConfig The assigned config
|
||||
*/
|
||||
public static function set_config($identifier, HTMLEditorConfig $config)
|
||||
public static function set_config($identifier, HTMLEditorConfig $config = null)
|
||||
{
|
||||
self::$configs[$identifier] = $config;
|
||||
if ($config) {
|
||||
self::$configs[$identifier] = $config;
|
||||
} else {
|
||||
unset(self::$configs[$identifier]);
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
@ -6,14 +6,17 @@ use SilverStripe\Assets\Storage\GeneratedAssetHandler;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Config\Configurable;
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Flushable;
|
||||
use SilverStripe\Core\Injector\Injectable;
|
||||
|
||||
/**
|
||||
* Generates tinymce config using a combined file generated via a standard
|
||||
* SilverStripe {@link GeneratedAssetHandler}
|
||||
*/
|
||||
class TinyMCECombinedGenerator implements TinyMCEScriptGenerator
|
||||
class TinyMCECombinedGenerator implements TinyMCEScriptGenerator, Flushable
|
||||
{
|
||||
use Configurable;
|
||||
use Injectable;
|
||||
|
||||
/**
|
||||
* Named config
|
||||
@ -201,4 +204,17 @@ class TinyMCECombinedGenerator implements TinyMCEScriptGenerator
|
||||
);
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is triggered early in the request if the "flush" query
|
||||
* parameter has been set. Each class that implements Flushable implements
|
||||
* this function which looks after it's own specific flushing functionality.
|
||||
*
|
||||
* @see FlushMiddleware
|
||||
*/
|
||||
public static function flush()
|
||||
{
|
||||
$dir = dirname(static::config()->get('filename_base'));
|
||||
static::singleton()->getAssetHandler()->removeContent($dir);
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,17 @@ class TinyMCECombinedGeneratorTest extends SapphireTest
|
||||
// Set custom base_path for tinymce
|
||||
Director::config()->set('alternate_base_folder', __DIR__ . '/TinyMCECombinedGeneratorTest');
|
||||
Director::config()->set('alternate_base_url', 'http://www.mysite.com/basedir/');
|
||||
SSViewer::config()->set('themes', [ SSViewer::DEFAULT_THEME ]);
|
||||
SSViewer::config()->set('themes', [SSViewer::DEFAULT_THEME]);
|
||||
TinyMCEConfig::config()->set('base_dir', 'tinymce');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
// Flush test configs
|
||||
HTMLEditorConfig::set_config('testconfig', null);
|
||||
}
|
||||
|
||||
public function testConfig()
|
||||
{
|
||||
// Disable nonces
|
||||
@ -83,4 +90,28 @@ EOS
|
||||
$content
|
||||
);
|
||||
}
|
||||
|
||||
public function testFlush()
|
||||
{
|
||||
// Disable nonces
|
||||
$c = new TinyMCEConfig();
|
||||
$c->setTheme('testtheme');
|
||||
$c->setOption('language', 'en');
|
||||
$c->disablePlugins('table', 'emoticons', 'paste', 'code', 'link', 'importcss');
|
||||
$c->enablePlugins(['plugin1' => 'mycode/plugin1.js']);
|
||||
HTMLEditorConfig::set_config('testconfig', $c);
|
||||
|
||||
// Generate file for this
|
||||
/** @var TinyMCECombinedGenerator $generator */
|
||||
$generator = Injector::inst()->create(TinyMCECombinedGenerator::class);
|
||||
$generator->getScriptURL($c);
|
||||
$filename = $generator->generateFilename($c);
|
||||
|
||||
// Ensure content exists
|
||||
$this->assertNotEmpty($generator->getAssetHandler()->getContent($filename));
|
||||
|
||||
// Flush should destroy this
|
||||
TinyMCECombinedGenerator::flush();
|
||||
$this->assertEmpty($generator->getAssetHandler()->getContent($filename));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user