silverstripe-contentreview/src/Compatibility/ContentReviewCompatability.php

63 lines
1.7 KiB
PHP
Raw Normal View History

2015-11-02 00:27:42 +01:00
<?php
2015-09-23 00:32:23 +02:00
namespace SilverStripe\ContentReview\Compatibility;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Subsites\Model\Subsite;
use Translatable;
// @todo add translatable namespace
2015-09-23 00:32:23 +02:00
/**
2015-11-02 00:27:42 +01:00
* This is a helper class which lets us do things with content review data without subsites
2015-09-23 00:32:23 +02:00
* and translatable messing our SQL queries up.
2015-11-02 00:27:42 +01:00
*
* Make sure any DataQuery instances you are building are BOTH created & executed between start()
2015-09-23 00:32:23 +02:00
* and done() because augmentDataQueryCreate and augmentSQL happens there.
*/
2015-11-02 00:27:42 +01:00
class ContentReviewCompatability
{
const SUBSITES = 0;
const TRANSLATABLE = 1;
/**
* Returns the state of other modules before compatibility mode is started.
*
* @return array
*/
public static function start()
{
$compatibility = [
2015-11-02 00:27:42 +01:00
self::SUBSITES => null,
self::TRANSLATABLE => null,
];
2015-11-02 00:27:42 +01:00
if (ClassInfo::exists(Subsite::class)) {
2015-11-02 00:27:42 +01:00
$compatibility[self::SUBSITES] = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true);
}
if (ClassInfo::exists(Translatable::class)) {
2015-11-02 00:27:42 +01:00
$compatibility[self::TRANSLATABLE] = Translatable::locale_filter_enabled();
Translatable::disable_locale_filter();
}
return $compatibility;
}
/**
* @param array $compatibility
*/
public static function done(array $compatibility)
{
if (class_exists(Subsite::class)) {
2015-11-02 00:27:42 +01:00
Subsite::$disable_subsite_filter = $compatibility[self::SUBSITES];
}
if (class_exists(Translatable::class)) {
2015-11-02 00:27:42 +01:00
Translatable::enable_locale_filter($compatibility[self::TRANSLATABLE]);
}
}
}