1
<?php
2

3
namespace SilverStripe\VersionedAdmin\Controllers;
4

5
use SilverStripe\CMS\Controllers\CMSPageHistoryController;
6
use SilverStripe\CMS\Model\SiteTree;
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\Core\Extensible;
9
use SilverStripe\Core\Injector\Factory;
10
use SilverStripe\Core\Injector\Injector;
11
use SilverStripe\Versioned\Versioned;
12

13
/**
14
 * The history controller factory decides which CMS history controller to use, out of the default from the
15
 * silverstripe/cms module or the history viewer controller from this module, depending on the current page type
16
 *
17
 * @deprecated 1.1.0:2.0.0
18
 */
19
class HistoryControllerFactory implements Factory
20
{
21
    use Extensible;
22

23 1
    public function create($service, array $params = array())
24
    {
25
        // If no request is available yet, return the default controller
26 1
        if (Injector::inst()->has(HTTPRequest::class)) {
27 1
            $request = Injector::inst()->get(HTTPRequest::class);
28 1
            $id = $request->param('ID');
29

30 1
            if ($id && is_numeric($id)) {
31
                // Ensure we read from the draft stage at this position
32 1
                $page = Versioned::get_one_by_stage(
33 1
                    SiteTree::class,
34 1
                    Versioned::DRAFT,
35 1
                    sprintf('"SiteTree"."ID" = \'%d\'', $id)
36
                );
37

38 1
                if ($page && !$this->isEnabled($page)) {
39
                    // Injector is not used to prevent an infinite loop
40 1
                    return new CMSPageHistoryController();
41
                }
42
            }
43
        }
44

45
        // Injector is not used to prevent an infinite loop
46 1
        return Injector::inst()->create(CMSPageHistoryViewerController::class);
47
    }
48

49
    /**
50
     * Only deactivate for pages that have a history viewer capability removed. Extensions can provide their
51
     * own two cents about this criteria.
52
     *
53
     * @param SiteTree $record
54
     * @return bool
55
     */
56 1
    public function isEnabled(SiteTree $record)
57
    {
58 1
        $enabledResults = $this->extend('updateIsEnabled', $record);
59 1
        return (empty($enabledResults) || min($enabledResults) !== false);
60
    }
61
}

Read our documentation on viewing source code .

Loading