commit 5966fd9eda1941af02a41e464c3d4125ec5af204
parent ea41cc9c81f8732c3b207aeda7f9c70c0637cbf6
Author: Jan Dankert <develop@jandankert.de>
Date: Mon, 28 Sep 2020 21:07:21 +0200
Cleanup: Removing unused code.
Diffstat:
5 files changed, 33 insertions(+), 88 deletions(-)
diff --git a/modules/cms/action/FileAction.class.php b/modules/cms/action/FileAction.class.php
@@ -164,10 +164,10 @@ class FileAction extends ObjectAction
*/
function showView()
{
- $producer = new Producer();
- $producer->generate( $this->file,Producer::SCHEME_PREVIEW );
+ $fileContext = new FileContext($this->file->objectid, Producer::SCHEME_PREVIEW );
+
+ $generator = new FileGenerator( $fileContext);
- //$this->file->publisher = new PublishPreview();
$this->lastModified( $this->file->lastchangeDate );
if ( $this->file->extension == 'gz' )
@@ -238,12 +238,12 @@ class FileAction extends ObjectAction
// PHP-Code ausfuehren
ob_start();
- require( $producer->getCache()->getFilename() );
+ require( $generator->getCache()->load()->getFilename() );
$this->setTemplateVar('value',$encodingFunction(ob_get_contents()) );
ob_end_clean();
}
else
- $this->setTemplateVar('value',$encodingFunction( $producer->getValue() ) );
+ $this->setTemplateVar('value',$encodingFunction( $generator->getCache()->get() ) );
// Maybe we want some gzip-encoding?
}
diff --git a/modules/cms/generator/BaseGenerator.class.php b/modules/cms/generator/BaseGenerator.class.php
@@ -13,6 +13,9 @@ abstract class BaseGenerator implements Generator
*/
protected $context;
+ /**
+ * @return FileCache
+ */
public function getCache() {
return new FileCache( $this->context->getCacheKey(),function() {
diff --git a/modules/cms/generator/Producer.class.php b/modules/cms/generator/Producer.class.php
@@ -9,82 +9,6 @@ use cms\model\Page;
class Producer {
- public $objectid;
-
- public $languages;
- public $models;
-
const SCHEME_PREVIEW = 1;
- const SCHEME_EDIT = 2;
const SCHEME_PUBLIC = 3;
-
-
- /**
- * @var \util\cache\FileCache
- */
- private $cache;
-
-
- /**
- * @param $object BaseObject
- * @param $scheme
- * @throws \ObjectNotFoundException
- */
- public function generate( $object,$scheme ) {
-
- $project = $object->getProject();
-
- if ( $this->languages )
- $languages = $this->languages;
- else
- $languages = $project->getLanguageIds();
-
- if ( $this->models )
- $models = $this->models;
- else
- $models = $project->getModelIds();
-
-
- if ( $object instanceof File ) {
-
- $fileContext = new FileContext($object->objectid, $scheme);
-
- $generator = new FileGenerator( $fileContext);
- }
-
- if ( $object instanceof Page ) {
-
- foreach( $models as $model ) {
-
- foreach ( $languages as $language ) {
- $pageContext = new PageContext( $object->objectid,$scheme);
- $pageContext->modelId = $model;
- $pageContext->languageId = $language;
-
- $generator = new PageGenerator( $pageContext );
- }
- }
- }
-
- $this->cache = $generator->getCache();
- }
-
-
- public function getValue() {
- return $this->cache->get();
- }
-
-
- public function getCache() {
- return $this->cache;
- }
-
-
- public function publish() {
- $publisher = new Publisher( );
- $publisher->publish( $this->cache->getFilename(), $this->filename, time() );
- }
-
-
-
}
\ No newline at end of file
diff --git a/modules/util/cache/Cache.class.php b/modules/util/cache/Cache.class.php
@@ -8,7 +8,7 @@ namespace util\cache;
*/
interface Cache
{
- public function invalidateIfOlderThan($lastModified);
+ public function invalidateIfOlderThan($invalidateIfOlderDate);
/**
* Invalidates a cache entry.
diff --git a/modules/util/cache/FileCache.class.php b/modules/util/cache/FileCache.class.php
@@ -2,6 +2,7 @@
namespace util\cache;
+use cms\base\Configuration as C;
use cms\base\DB;
use cms\base\Startup;
use util\FileUtils;
@@ -13,12 +14,16 @@ use util\FileUtils;
class FileCache implements Cache
{
const CACHE_FILENAME_PREFIX = 'openrat-cache';
+
/**
+ * A loader which gets the value
* @var Callable
*/
private $loader;
/**
+ * Filename of the cache.
+ *
* @var string
*/
private $filename;
@@ -26,13 +31,13 @@ class FileCache implements Cache
/**
* Creates a new Cache entry.
*
- * @param $key array Cache-Key
+ * @param $key array|string Cache-Key
* @param $loader Callable
*/
public function __construct( $key, $loader, $lastModified = 0 )
{
if ( !is_array($key))
- $key = [ $key ];
+ $key = [ (string) $key ];
$key = array_merge([ DB::get()->id ], $key);
$filename = FileUtils::getTempDir() . '/'. self::CACHE_FILENAME_PREFIX;
@@ -44,16 +49,20 @@ class FileCache implements Cache
$this->filename = $filename;
$this->loader = $loader;
- if ( \cms\base\Configuration::config()->subset('publishing')->is('cache_enabled',false) )
+ if ( C::config()->subset('publishing')->is('cache_enabled',false) )
$this->invalidateIfOlderThan( $lastModified );
else
$this->invalidateIfOlderThan( Startup::getStartTime() ); // Invalidate all before this request.
}
- public function invalidateIfOlderThan($lastModified) {
+ /**
+ * Invalidates the cache entry, if it is older than a specific date.
+ * @param $invalidateIfOlderDate
+ */
+ public function invalidateIfOlderThan($invalidateIfOlderDate) {
- if ( is_file($this->filename) && filemtime($this->filename) < $lastModified )
+ if ( is_file($this->filename) && filemtime($this->filename) < $invalidateIfOlderDate )
$this->invalidate();
}
@@ -83,7 +92,9 @@ class FileCache implements Cache
/**
- * Get the content.
+ * Makes sure that the value is loaded.
+ *
+ * @return FileCache
*/
public function load() {
@@ -97,6 +108,7 @@ class FileCache implements Cache
/**
* Refreshes the cache.
+ *
* @return $this
*/
public function refresh() {
@@ -107,6 +119,12 @@ class FileCache implements Cache
}
+ /**
+ * Gets the filename of the cache value.
+ * Warning: The file may not exist. If you want to make sure that the file exists, you have to call #load() first.
+ *
+ * @return string filename of cache content
+ */
public function getFilename() {
return $this->filename;
}