1 | <?php |
||
2 | |||
3 | namespace LeKoala\EmailTemplates\Extensions; |
||
4 | |||
5 | use SilverStripe\ORM\DataQuery; |
||
6 | use SilverStripe\ORM\DataExtension; |
||
7 | use SilverStripe\Security\Permission; |
||
8 | use LeKoala\Base\Subsite\SubsiteHelper; |
||
0 ignored issues
–
show
|
|||
9 | use SilverStripe\ORM\Queries\SQLSelect; |
||
10 | |||
11 | /** |
||
12 | * Add subsites support |
||
13 | * |
||
14 | * @author lekoala |
||
15 | */ |
||
16 | class EmailSubsiteExtension extends DataExtension |
||
17 | { |
||
18 | |||
19 | private static $has_one = array( |
||
0 ignored issues
–
show
|
|||
20 | 'Subsite' => 'Subsite', |
||
21 | ); |
||
22 | |||
23 | public function isMainDataObject() |
||
24 | { |
||
25 | if ($this->owner->SubsiteID == 0) { |
||
0 ignored issues
–
show
|
|||
26 | return true; |
||
27 | } |
||
28 | return false; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * Update any requests to limit the results to the current site |
||
33 | */ |
||
34 | public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) |
||
35 | { |
||
36 | if (SubsiteHelper::subsiteFilterDisabled()) { |
||
37 | return; |
||
38 | } |
||
39 | if ($dataQuery && $dataQuery->getQueryParam('Subsite.filter') === false) { |
||
0 ignored issues
–
show
|
|||
40 | return; |
||
41 | } |
||
42 | |||
43 | // If you're querying by ID, don't filter |
||
44 | if ($query->filtersOnID()) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | // Don't run on delete queries, since they are always tied to a specific ID. |
||
49 | // if ($query->getDelete()) { |
||
50 | // return; |
||
51 | // } |
||
52 | |||
53 | // If we match on a subsite, don't filter twice |
||
54 | $regexp = '/^(.*\.)?("|`)?SubsiteID("|`)?\s?=/'; |
||
55 | foreach ($query->getWhereParameterised($parameters) as $predicate) { |
||
56 | if (preg_match($regexp, $predicate)) { |
||
57 | return; |
||
58 | } |
||
59 | } |
||
60 | |||
61 | $subsiteID = (int) SubsiteHelper::currentSubsiteID(); |
||
62 | |||
63 | $froms = $query->getFrom(); |
||
64 | $froms = array_keys($froms); |
||
65 | $tableName = array_shift($froms); |
||
66 | |||
67 | if ($subsiteID) { |
||
68 | $query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)"); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | public function onBeforeWrite() |
||
73 | { |
||
74 | parent::onBeforeWrite(); |
||
75 | |||
76 | // Assign to current subsite when created |
||
77 | if (!$this->owner->ID && !$this->owner->SubsiteID) { |
||
78 | $this->owner->SubsiteID = SubsiteHelper::currentSubsiteID(); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | public function canView($member = null) |
||
83 | { |
||
84 | return $this->canEdit($member); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @param Member |
||
89 | * @return boolean|null |
||
90 | */ |
||
91 | public function canEdit($member = null) |
||
92 | { |
||
93 | return Permission::check('CMS_ACCESS', 'any', $member); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @param Member |
||
98 | * @return boolean|null |
||
99 | */ |
||
100 | public function canCreate($member = null) |
||
101 | { |
||
102 | return Permission::check('CMS_ACCESS', 'any', $member); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param Member |
||
107 | * @return boolean|null |
||
108 | */ |
||
109 | public function canDelete($member = null) |
||
110 | { |
||
111 | return Permission::check('CMS_ACCESS', 'any', $member); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Return a piece of text to keep DataObject cache keys appropriately specific |
||
116 | */ |
||
117 | public function cacheKeyComponent() |
||
118 | { |
||
119 | return 'subsite-' . SubsiteHelper::currentSubsiteID(); |
||
120 | } |
||
121 | } |
||
122 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths