ContentReviewCompatability::start()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 4
nop 0
1
<?php
2
3
namespace SilverStripe\ContentReview\Compatibility;
4
5
use SilverStripe\Core\ClassInfo;
6
use SilverStripe\Subsites\Model\Subsite;
7
// @todo add translatable namespace
8
use Translatable;
9
10
/**
11
 * This is a helper class which lets us do things with content review data without subsites
12
 * and translatable messing our SQL queries up.
13
 *
14
 * Make sure any DataQuery instances you are building are BOTH created & executed between start()
15
 * and done() because augmentDataQueryCreate and augmentSQL happens there.
16
 */
17
class ContentReviewCompatability
18
{
19
    const SUBSITES = 0;
20
21
    const TRANSLATABLE = 1;
22
23
    /**
24
     * Returns the state of other modules before compatibility mode is started.
25
     *
26
     * @return array
27
     */
28
    public static function start()
29
    {
30
        $compatibility = array(
31
            self::SUBSITES     => null,
32
            self::TRANSLATABLE => null,
33
        );
34
35
        if (ClassInfo::exists(Subsite::class)) {
36
            $compatibility[self::SUBSITES] = Subsite::$disable_subsite_filter;
37
            Subsite::disable_subsite_filter(true);
38
        }
39
40
        if (ClassInfo::exists(Translatable::class)) {
41
            $compatibility[self::TRANSLATABLE] = Translatable::locale_filter_enabled();
42
            Translatable::disable_locale_filter();
43
        }
44
45
        return $compatibility;
46
    }
47
48
    /**
49
     * @param array $compatibility
50
     */
51
    public static function done(array $compatibility)
52
    {
53
        if (class_exists(Subsite::class)) {
54
            Subsite::$disable_subsite_filter = $compatibility[self::SUBSITES];
55
        }
56
57
        if (class_exists(Translatable::class)) {
58
            Translatable::enable_locale_filter($compatibility[self::TRANSLATABLE]);
59
        }
60
    }
61
}
62