@@ -218,23 +218,23 @@ discard block |
||
218 | 218 | $this->initCache(); |
219 | 219 | $count = 0; |
220 | 220 | // we should have these already. |
221 | - foreach($this->objects as $item) { |
|
222 | - if($item->canEdit()) { |
|
221 | + foreach ($this->objects as $item) { |
|
222 | + if ($item->canEdit()) { |
|
223 | 223 | $fields = $this->getAllValidFields($item->ClassName); |
224 | 224 | foreach ($fields as $field) { |
225 | 225 | $new = str_replace($word, $replace, $item->$field); |
226 | - if($new !== $item->$field) { |
|
226 | + if ($new !== $item->$field) { |
|
227 | 227 | $count++; |
228 | 228 | $item->$field = $new; |
229 | 229 | $isPublished = false; |
230 | - if($item->hasMethod('isPublished')) { |
|
230 | + if ($item->hasMethod('isPublished')) { |
|
231 | 231 | $isPublished = $item->isPublished(); |
232 | 232 | } |
233 | 233 | $item->write(); |
234 | - if($isPublished) { |
|
234 | + if ($isPublished) { |
|
235 | 235 | $item->publishRecursive(); |
236 | 236 | } |
237 | - if ($this->debug) { DB::alteration_message('<h2>Match: '.$item->ClassName.$item->ID.'</h2>'.$new.'<hr />');} |
|
237 | + if ($this->debug) { DB::alteration_message('<h2>Match: ' . $item->ClassName . $item->ID . '</h2>' . $new . '<hr />'); } |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | } |
@@ -245,47 +245,47 @@ discard block |
||
245 | 245 | |
246 | 246 | protected function getMatches(?string $word = ''): array |
247 | 247 | { |
248 | - if ($this->debug) {$startOuter = microtime(true);} |
|
248 | + if ($this->debug) {$startOuter = microtime(true); } |
|
249 | 249 | |
250 | 250 | $this->workOutExclusions(); |
251 | 251 | $this->workOutWords($word); |
252 | - if ($this->debug) {DB::alteration_message('Words searched for ' . implode(', ', $this->words));} |
|
252 | + if ($this->debug) {DB::alteration_message('Words searched for ' . implode(', ', $this->words)); } |
|
253 | 253 | $array = []; |
254 | 254 | |
255 | 255 | if (count($this->words)) { |
256 | 256 | foreach ($this->getAllDataObjects() as $className) { |
257 | - if ($this->debug) {DB::alteration_message(' ... Searching in ' . $className);} |
|
258 | - if (! in_array($className, $this->excludedClasses, true)) { |
|
257 | + if ($this->debug) {DB::alteration_message(' ... Searching in ' . $className); } |
|
258 | + if (!in_array($className, $this->excludedClasses, true)) { |
|
259 | 259 | $array[$className] = []; |
260 | 260 | $fields = $this->getAllValidFields($className); |
261 | 261 | $filterAny = []; |
262 | 262 | foreach ($fields as $field) { |
263 | - if (! in_array($field, $this->excludedFields, true)) { |
|
264 | - if ($this->debug) {DB::alteration_message(' ... ... Searching in ' . $className . '.' . $field);} |
|
263 | + if (!in_array($field, $this->excludedFields, true)) { |
|
264 | + if ($this->debug) {DB::alteration_message(' ... ... Searching in ' . $className . '.' . $field); } |
|
265 | 265 | $filterAny[$field . ':PartialMatch'] = $this->words; |
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | 269 | if ([] !== $filterAny) { |
270 | - if ($this->debug) {$startInner = microtime(true); DB::alteration_message(' ... Filter: ' . implode(', ', array_keys($filterAny)));} |
|
270 | + if ($this->debug) {$startInner = microtime(true); DB::alteration_message(' ... Filter: ' . implode(', ', array_keys($filterAny))); } |
|
271 | 271 | $array[$className] = $className::get() |
272 | 272 | ->filterAny($filterAny) |
273 | 273 | ->limit($this->Config()->get('limit_of_count_per_data_object')) |
274 | 274 | ->column('ID') |
275 | 275 | ; |
276 | - if ($this->debug) {$elaps = microtime(true) - $startInner;DB::alteration_message('search for ' . $className . ' taken : ' . $elaps);} |
|
276 | + if ($this->debug) {$elaps = microtime(true) - $startInner; DB::alteration_message('search for ' . $className . ' taken : ' . $elaps); } |
|
277 | 277 | } |
278 | 278 | |
279 | - if ($this->debug) {DB::alteration_message(' ... No fields in ' . $className);} |
|
279 | + if ($this->debug) {DB::alteration_message(' ... No fields in ' . $className); } |
|
280 | 280 | } |
281 | 281 | |
282 | - if ($this->debug) {DB::alteration_message(' ... Skipping ' . $className);} |
|
282 | + if ($this->debug) {DB::alteration_message(' ... Skipping ' . $className); } |
|
283 | 283 | } |
284 | 284 | } else { |
285 | 285 | $array = $this->getDefaultList(); |
286 | 286 | } |
287 | 287 | |
288 | - if ($this->debug) {$elaps = microtime(true) - $startOuter;DB::alteration_message('seconds taken find results: ' . $elaps);} |
|
288 | + if ($this->debug) {$elaps = microtime(true) - $startOuter; DB::alteration_message('seconds taken find results: ' . $elaps); } |
|
289 | 289 | return $array; |
290 | 290 | } |
291 | 291 | |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | $back = $this->config()->get('hours_back_for_recent') ?? 24; |
295 | 295 | $limit = $this->Config()->get('limit_per_class_for_recent') ?? 5; |
296 | 296 | $threshold = strtotime('-' . $back . ' hours', DBDatetime::now()->getTimestamp()); |
297 | - if (! $threshold) { |
|
297 | + if (!$threshold) { |
|
298 | 298 | $threshold = time() - 86400; |
299 | 299 | } |
300 | 300 | |
301 | 301 | $array = []; |
302 | 302 | $classNames = $this->getAllDataObjects(); |
303 | 303 | foreach ($classNames as $className) { |
304 | - if (! in_array($className, $this->excludedClasses, true)) { |
|
304 | + if (!in_array($className, $this->excludedClasses, true)) { |
|
305 | 305 | $array[$className] = $className::get() |
306 | 306 | ->filter('LastEdited:GreaterThan', date('Y-m-d H:i:s', $threshold)) |
307 | 307 | ->sort('LastEdited', 'DESC') |
@@ -316,14 +316,14 @@ discard block |
||
316 | 316 | |
317 | 317 | protected function turnArrayIntoObjects(array $matches, ?int $limit = 0) : array |
318 | 318 | { |
319 | - if(empty($this->objects)) { |
|
320 | - if(empty($limit)) { |
|
319 | + if (empty($this->objects)) { |
|
320 | + if (empty($limit)) { |
|
321 | 321 | $limit = (int) $this->Config()->get('limit_of_count_per_data_object'); |
322 | 322 | } |
323 | 323 | $this->objects = []; |
324 | - if ($this->debug) {DB::alteration_message('number of classes: ' . count($matches));} |
|
324 | + if ($this->debug) {DB::alteration_message('number of classes: ' . count($matches)); } |
|
325 | 325 | foreach ($matches as $className => $ids) { |
326 | - if ($this->debug) {$start = microtime(true);DB::alteration_message(' ... number of matches for : ' . $className . ': ' . count($ids));} |
|
326 | + if ($this->debug) {$start = microtime(true); DB::alteration_message(' ... number of matches for : ' . $className . ': ' . count($ids)); } |
|
327 | 327 | if (count($ids)) { |
328 | 328 | $className = (string) $className; |
329 | 329 | $items = $className::get() |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | } |
337 | 337 | } |
338 | 338 | } |
339 | - if ($this->debug) {$elaps = microtime(true) - $start;DB::alteration_message('seconds taken to find objects in: ' . $className . ': ' . $elaps);} |
|
339 | + if ($this->debug) {$elaps = microtime(true) - $start; DB::alteration_message('seconds taken to find objects in: ' . $className . ': ' . $elaps); } |
|
340 | 340 | } |
341 | 341 | } |
342 | 342 | |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | $finder = Injector::inst()->get(FindEditableObjects::class); |
352 | 352 | $finder->initCache(); |
353 | 353 | $items = $this->turnArrayIntoObjects($matches); |
354 | - foreach($items as $item) { |
|
354 | + foreach ($items as $item) { |
|
355 | 355 | $link = $finder->getLink($item, $this->excludedClasses); |
356 | 356 | $cmsEditLink = $item->canEdit() ? $finder->getCMSEditLink($item, $this->excludedClasses) : ''; |
357 | 357 | $list->push( |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $testWords = array_unique($testWords); |
397 | 397 | foreach ($testWords as $wordKey => $word) { |
398 | 398 | //match a exact field to full words / one word |
399 | - $fullWords = ! (bool) $wordKey; |
|
399 | + $fullWords = !(bool) $wordKey; |
|
400 | 400 | if (false === $done) { |
401 | 401 | $count = 0; |
402 | 402 | foreach ($fieldValues as $fieldValue) { |
@@ -464,14 +464,14 @@ discard block |
||
464 | 464 | |
465 | 465 | protected function workOutWords(string $word = ''): array |
466 | 466 | { |
467 | - if($this->searchWholePhrase) { |
|
467 | + if ($this->searchWholePhrase) { |
|
468 | 468 | $this->words = [implode(' ', $this->words)]; |
469 | 469 | } |
470 | 470 | if ($word) { |
471 | 471 | $this->words[] = $word; |
472 | 472 | } |
473 | 473 | |
474 | - if (! count($this->words)) { |
|
474 | + if (!count($this->words)) { |
|
475 | 475 | user_error('No word has been provided'); |
476 | 476 | } |
477 | 477 | |
@@ -483,8 +483,8 @@ discard block |
||
483 | 483 | |
484 | 484 | protected function getAllDataObjects(): array |
485 | 485 | { |
486 | - if ($this->debug) {DB::alteration_message('Base Class: ' . $this->baseClass);} |
|
487 | - if (! isset($this->cache['AllDataObjects'][$this->baseClass])) { |
|
486 | + if ($this->debug) {DB::alteration_message('Base Class: ' . $this->baseClass); } |
|
487 | + if (!isset($this->cache['AllDataObjects'][$this->baseClass])) { |
|
488 | 488 | $this->cache['AllDataObjects'][$this->baseClass] = array_values( |
489 | 489 | ClassInfo::subclassesFor($this->baseClass, false) |
490 | 490 | ); |
@@ -496,7 +496,7 @@ discard block |
||
496 | 496 | |
497 | 497 | protected function getAllValidFields(string $className): array |
498 | 498 | { |
499 | - if (! isset($this->cache['AllValidFields'][$className])) { |
|
499 | + if (!isset($this->cache['AllValidFields'][$className])) { |
|
500 | 500 | $array = []; |
501 | 501 | $fullList = Config::inst()->get($className, 'db'); |
502 | 502 | if (is_array($fullList)) { |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | |
523 | 523 | protected function getIndexedFields(string $className, array $dbFields): array |
524 | 524 | { |
525 | - if (! isset($this->cache['IndexedFields'][$className])) { |
|
525 | + if (!isset($this->cache['IndexedFields'][$className])) { |
|
526 | 526 | $this->cache['IndexedFields'][$className] = []; |
527 | 527 | $indexes = Config::inst()->get($className, 'indexes'); |
528 | 528 | if (is_array($indexes)) { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | |
558 | 558 | protected function isValidFieldType(string $className, string $fieldName, string $type): bool |
559 | 559 | { |
560 | - if (! isset($this->cache['ValidFieldTypes'][$type])) { |
|
560 | + if (!isset($this->cache['ValidFieldTypes'][$type])) { |
|
561 | 561 | $this->cache['ValidFieldTypes'][$type] = false; |
562 | 562 | $singleton = Injector::inst()->get($className); |
563 | 563 | $field = $singleton->dbObject($fieldName); |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | (new CheckboxField('SearchWholePhrase', 'Search exact phrase', $this->searchWholePhrase)) |
64 | 64 | ->setDescription('If ticked, any item will be included that includes the whole phrase (e.g. New Zealand, rather than New OR Zealand)') |
65 | 65 | ); |
66 | - if (! $this->getRequest()->requestVar('Keywords')) { |
|
66 | + if (!$this->getRequest()->requestVar('Keywords')) { |
|
67 | 67 | $resultsTitle = 'Recently Edited'; |
68 | 68 | $this->listHTML = $this->renderWith(self::class . '_Results'); |
69 | 69 | } else { |
@@ -123,11 +123,11 @@ discard block |
||
123 | 123 | |
124 | 124 | public function SearchResults(): ?ArrayList |
125 | 125 | { |
126 | - $this->isQuickSearch = ! empty($this->rawData['QuickSearch']); |
|
127 | - $this->searchWholePhrase = ! empty($this->rawData['SearchWholePhrase']); |
|
126 | + $this->isQuickSearch = !empty($this->rawData['QuickSearch']); |
|
127 | + $this->searchWholePhrase = !empty($this->rawData['SearchWholePhrase']); |
|
128 | 128 | $this->keywords = trim($this->rawData['Keywords'] ?? ''); |
129 | 129 | $this->replace = trim($this->rawData['ReplaceWith'] ?? ''); |
130 | - if($this->replace) { |
|
130 | + if ($this->replace) { |
|
131 | 131 | return Injector::inst()->get(SearchApi ::class) |
132 | 132 | ->setBaseClass(DataObject::class) |
133 | 133 | ->setIsQuickSearch(false) |