Conditions | 10 |
Paths | 4 |
Total Lines | 67 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
99 | public function allchanges() |
||
100 | { |
||
101 | // Check viewability of allchanges |
||
102 | if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled') |
||
103 | || !SiteConfig::current_site_config()->AllChangesEnabled |
||
104 | ) { |
||
105 | return $this->owner->httpError(404, 'Global history not viewable'); |
||
106 | } |
||
107 | |||
108 | $limit = (int)Config::inst()->get(VersionFeed::class, 'allchanges_limit'); |
||
109 | $latestChanges = DB::query(' |
||
110 | SELECT * FROM "SiteTree_Versions" |
||
111 | WHERE "WasPublished" = \'1\' |
||
112 | AND "CanViewType" IN (\'Anyone\', \'Inherit\') |
||
113 | AND "ShowInSearch" = 1 |
||
114 | AND ("PublicHistory" IS NULL OR "PublicHistory" = \'1\') |
||
115 | ORDER BY "LastEdited" DESC LIMIT ' . $limit); |
||
116 | $lastChange = $latestChanges->record(); |
||
117 | $latestChanges->rewind(); |
||
118 | |||
119 | if ($lastChange) { |
||
120 | // Cache the diffs to remove DOS possibility. |
||
121 | $key = 'allchanges' |
||
122 | . preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited']) |
||
123 | . (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public'); |
||
124 | $changeList = $this->filterContent($key, function () use ($latestChanges) { |
||
125 | $changeList = new ArrayList(); |
||
126 | $canView = array(); |
||
127 | foreach ($latestChanges as $record) { |
||
128 | // Check if the page should be visible. |
||
129 | // WARNING: although we are providing historical details, we check the current configuration. |
||
130 | $id = $record['RecordID']; |
||
131 | if (!isset($canView[$id])) { |
||
132 | $page = DataObject::get_by_id(SiteTree::class, $id); |
||
133 | $canView[$id] = $page && $page->canView(Security::getCurrentUser()); |
||
134 | } |
||
135 | if (!$canView[$id]) { |
||
136 | continue; |
||
137 | } |
||
138 | |||
139 | // Get the diff to the previous version. |
||
140 | $record['ID'] = $record['RecordID']; |
||
141 | $version = SiteTree::create($record); |
||
142 | if ($diff = $version->getDiff()) { |
||
143 | $changeList->push($diff); |
||
144 | } |
||
145 | } |
||
146 | |||
147 | return $changeList; |
||
148 | }); |
||
149 | } else { |
||
150 | $changeList = new ArrayList(); |
||
151 | } |
||
152 | |||
153 | // Produce output |
||
154 | $url = $this->owner->getRequest()->getURL(); |
||
155 | $rss = new RSSFeed( |
||
156 | $changeList, |
||
157 | $url, |
||
158 | $this->linkToAllSitesRSSFeedTitle(), |
||
159 | '', |
||
160 | 'Title', |
||
161 | '', |
||
162 | null |
||
163 | ); |
||
164 | $rss->setTemplate('Page_allchanges_rss'); |
||
165 | return $rss->outputToBrowser(); |
||
166 | } |
||
217 |