Issues (39)

src/RegistryImportFeedController.php (2 issues)

Severity
1
<?php
2
3
namespace SilverStripe\Registry;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\ORM\FieldType\DBHTMLText;
8
use SilverStripe\Registry\RegistryDataInterface;
9
10
class RegistryImportFeedController extends Controller
11
{
12
    private static $allowed_actions = [
0 ignored issues
show
The private property $allowed_actions is not used, and could be removed.
Loading history...
13
        'latest',
14
    ];
15
16
    private static $url_handlers = [
0 ignored issues
show
The private property $url_handlers is not used, and could be removed.
Loading history...
17
        '$Action/$ModelClass' => 'handleAction',
18
    ];
19
20
    /**
21
     * Get an RSS feed of the latest data imports that were made for this registry model. This will only
22
     * return a valid result for classes that exist and implement the {@link RegistryDataInterface} interface.
23
     *
24
     * @param HTTPRequest $request
25
     * @return DBHTMLText
26
     */
27
    public function latest($request)
28
    {
29
        $feed = RegistryImportFeed::create();
30
        $modelClass = $this->unsanitiseClassName($request->param('ModelClass'));
31
32
        if (!class_exists($modelClass) || !(singleton($modelClass) instanceof RegistryDataInterface)) {
33
            return $this->httpError(404);
34
        }
35
36
        $feed->setModelClass($modelClass);
37
        return $feed->getLatest()->outputToBrowser();
38
    }
39
40
    /**
41
     * See {@link \SilverStripe\Admin\ModelAdmin::unsanitiseClassName}
42
     */
43
    protected function unsanitiseClassName($class)
44
    {
45
        return str_replace('-', '\\', $class);
46
    }
47
}
48