@@ -90,7 +90,7 @@ |
||
| 90 | 90 | _t(__CLASS__ . '.ReplaceToggle', 'Replace with ... (optional - make a backup first!)'), |
| 91 | 91 | [ |
| 92 | 92 | (new CheckboxField('ApplyReplace', 'Run replace (please make sure to make a backup first!)', $this->applyReplace)) |
| 93 | - ->setDescription('Check this to replace the searched value set above with its replacement value. Note that searches ignore uppercase / lowercase, but replace actions will only search and replace values with the same upper / lowercase.'), |
|
| 93 | + ->setDescription('Check this to replace the searched value set above with its replacement value. Note that searches ignore uppercase / lowercase, but replace actions will only search and replace values with the same upper / lowercase.'), |
|
| 94 | 94 | (new TextField('ReplaceWith', 'Replace (optional - careful!)', $this->replace ?? '')) |
| 95 | 95 | ->setAttribute('placeholder', 'e.g. contract - make sure to also tick checkbox below'), |
| 96 | 96 | ] |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | protected function init() |
| 59 | 59 | { |
| 60 | - if($this->request->param('Action')) { |
|
| 61 | - if(empty($this->request->postVars())) { |
|
| 60 | + if ($this->request->param('Action')) { |
|
| 61 | + if (empty($this->request->postVars())) { |
|
| 62 | 62 | $this->redirect('/admin/find'); |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | |
| 112 | 112 | if (!$this->getRequest()->requestVar('Keywords')) { |
| 113 | 113 | $lastResults = $this->lastSearchResults(); |
| 114 | - if($lastResults) { |
|
| 114 | + if ($lastResults) { |
|
| 115 | 115 | $resultsTitle = 'Last Results'; |
| 116 | 116 | } else { |
| 117 | 117 | $resultsTitle = 'Last Edited'; |
@@ -181,9 +181,9 @@ discard block |
||
| 181 | 181 | Environment::increaseTimeLimitTo(300); |
| 182 | 182 | Environment::setMemoryLimitMax(-1); |
| 183 | 183 | Environment::increaseMemoryLimitTo(-1); |
| 184 | - if(empty($this->rawData)) { |
|
| 184 | + if (empty($this->rawData)) { |
|
| 185 | 185 | $lastResults = $this->lastSearchResults(); |
| 186 | - if($lastResults) { |
|
| 186 | + if ($lastResults) { |
|
| 187 | 187 | return $lastResults; |
| 188 | 188 | } |
| 189 | 189 | } |
@@ -208,18 +208,18 @@ discard block |
||
| 208 | 208 | ->setWordsAsString($this->keywords) |
| 209 | 209 | ->getLinks() |
| 210 | 210 | ; |
| 211 | - if($results->count() === 1) { |
|
| 211 | + if ($results->count() === 1) { |
|
| 212 | 212 | $result = $results->first(); |
| 213 | - if($result->HasCMSEditLink) { |
|
| 213 | + if ($result->HasCMSEditLink) { |
|
| 214 | 214 | // files do not redirect nicely... |
| 215 | - if(!in_array(File::class, ClassInfo::ancestry($result->ClassName), true)) { |
|
| 215 | + if (!in_array(File::class, ClassInfo::ancestry($result->ClassName), true)) { |
|
| 216 | 216 | $this->redirect($result->CMSEditLink); |
| 217 | 217 | } |
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | // Accessing the session |
| 221 | 221 | $session = $this->getRequest()->getSession(); |
| 222 | - if($session) { |
|
| 222 | + if ($session) { |
|
| 223 | 223 | $session->set('QuickSearchLastResults', serialize($results->toArray())); |
| 224 | 224 | } |
| 225 | 225 | return $results; |
@@ -250,16 +250,16 @@ discard block |
||
| 250 | 250 | { |
| 251 | 251 | // Accessing the session |
| 252 | 252 | $session = $this->getRequest()->getSession(); |
| 253 | - if($this->quickSearchType) { |
|
| 253 | + if ($this->quickSearchType) { |
|
| 254 | 254 | $session->set('QuickSearchType', $this->quickSearchType); |
| 255 | - } elseif($session) { |
|
| 255 | + } elseif ($session) { |
|
| 256 | 256 | $this->quickSearchType = $session->get('QuickSearchType'); |
| 257 | - if(isset($_GET['flush'])) { |
|
| 257 | + if (isset($_GET['flush'])) { |
|
| 258 | 258 | $this->quickSearchType = ''; |
| 259 | 259 | $session->set('QuickSearchType', ''); |
| 260 | 260 | } |
| 261 | 261 | } |
| 262 | - if(!$this->quickSearchType) { |
|
| 262 | + if (!$this->quickSearchType) { |
|
| 263 | 263 | $this->quickSearchType = $this->Config()->get('default_quick_search_type'); |
| 264 | 264 | } |
| 265 | 265 | return (string) $this->quickSearchType; |
@@ -269,15 +269,15 @@ discard block |
||
| 269 | 269 | { |
| 270 | 270 | // Accessing the session |
| 271 | 271 | $session = $this->getRequest()->getSession(); |
| 272 | - if($session) { |
|
| 273 | - if(isset($_GET['flush'])) { |
|
| 272 | + if ($session) { |
|
| 273 | + if (isset($_GET['flush'])) { |
|
| 274 | 274 | $session->clear('QuickSearchLastResults'); |
| 275 | 275 | } else { |
| 276 | 276 | $data = $session->get('QuickSearchLastResults'); |
| 277 | - if($data) { |
|
| 277 | + if ($data) { |
|
| 278 | 278 | $array = unserialize($data); |
| 279 | 279 | $al = ArrayList::create(); |
| 280 | - foreach($array as $item) { |
|
| 280 | + foreach ($array as $item) { |
|
| 281 | 281 | $al->push($item); |
| 282 | 282 | } |
| 283 | 283 | return $al; |
@@ -52,10 +52,10 @@ |
||
| 52 | 52 | 'limited' => 'Limited search', |
| 53 | 53 | ]; |
| 54 | 54 | $availableSearchClasses = self::available_quick_searches(); |
| 55 | - if(!empty($availableSearchClasses) > 0) { |
|
| 56 | - foreach($availableSearchClasses as $availableSearchClass) { |
|
| 55 | + if (!empty($availableSearchClasses) > 0) { |
|
| 56 | + foreach ($availableSearchClasses as $availableSearchClass) { |
|
| 57 | 57 | $singleton = Injector::inst()->get($availableSearchClass); |
| 58 | - if($singleton->isEnabled()) { |
|
| 58 | + if ($singleton->isEnabled()) { |
|
| 59 | 59 | $array[$availableSearchClass] = $singleton->getTitle(); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | public static function inst(string $baseClass) |
| 89 | 89 | { |
| 90 | - if(self::$singleton === null) { |
|
| 90 | + if (self::$singleton === null) { |
|
| 91 | 91 | self::$singleton = Injector::inst()->get(static::class); |
| 92 | 92 | } |
| 93 | 93 | self::$singleton->setBaseClass($baseClass); |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | foreach ($this->cache['AllValidFields'][$className] as $name => $type) { |
| 129 | 129 | if ($this->isValidFieldType($type, $className, $name)) { |
| 130 | 130 | $array[] = $name; |
| 131 | - } elseif(in_array($name, $includedFields, true)) { |
|
| 131 | + } elseif (in_array($name, $includedFields, true)) { |
|
| 132 | 132 | $array[] = $name; |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | - if(isset($includedClassFieldCombos[$className])) { |
|
| 136 | - foreach($includedClassFieldCombos[$className] as $name) { |
|
| 135 | + if (isset($includedClassFieldCombos[$className])) { |
|
| 136 | + foreach ($includedClassFieldCombos[$className] as $name) { |
|
| 137 | 137 | $array[] = $name; |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -112,13 +112,13 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | public function setQuickSearchType(string $nameOrType): SearchApi |
| 114 | 114 | { |
| 115 | - if($nameOrType === 'all') { |
|
| 115 | + if ($nameOrType === 'all') { |
|
| 116 | 116 | $this->isQuickSearch = false; |
| 117 | 117 | $this->quickSearchType = ''; |
| 118 | - } elseif($nameOrType === 'limited') { |
|
| 118 | + } elseif ($nameOrType === 'limited') { |
|
| 119 | 119 | $this->isQuickSearch = true; |
| 120 | 120 | $this->quickSearchType = ''; |
| 121 | - } elseif(class_exists($nameOrType)) { |
|
| 121 | + } elseif (class_exists($nameOrType)) { |
|
| 122 | 122 | $this->quickSearchType = $nameOrType; |
| 123 | 123 | $object = Injector::inst()->get($nameOrType); |
| 124 | 124 | $this->setIncludedClasses($object->getClassesToSearch()); |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | |
| 150 | 150 | public function setBaseClass(string $class): SearchApi |
| 151 | 151 | { |
| 152 | - if(class_exists($class)) { |
|
| 152 | + if (class_exists($class)) { |
|
| 153 | 153 | $this->baseClass = $class; |
| 154 | 154 | } |
| 155 | 155 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | |
| 225 | 225 | public function buildCache(?string $word = ''): SearchApi |
| 226 | 226 | { |
| 227 | - if($this->cacheHasBeenBuilt !== $word) { |
|
| 227 | + if ($this->cacheHasBeenBuilt !== $word) { |
|
| 228 | 228 | $this->getLinksInner($word); |
| 229 | 229 | $this->cacheHasBeenBuilt = $word; |
| 230 | 230 | } |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | public function doReplacement(string $word, string $replace): int |
| 256 | 256 | { |
| 257 | 257 | $count = 0; |
| 258 | - if($word) { |
|
| 258 | + if ($word) { |
|
| 259 | 259 | $this->buildCache($word); |
| 260 | 260 | $replace = $this->securityCheckInput($replace); |
| 261 | 261 | foreach ($this->objects as $item) { |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | if ($item->canEdit()) { |
| 264 | 264 | $fields = $this->getAllValidFields($className); |
| 265 | 265 | foreach ($fields as $field) { |
| 266 | - if(!$this->includeFieldTest($className, $field)) { |
|
| 266 | + if (!$this->includeFieldTest($className, $field)) { |
|
| 267 | 267 | continue; |
| 268 | 268 | } |
| 269 | 269 | $new = str_replace($word, $replace, $item->{$field}); |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | $this->workOutInclusionsAndExclusions(); |
| 329 | 329 | |
| 330 | 330 | // important to do this first |
| 331 | - if($word) { |
|
| 331 | + if ($word) { |
|
| 332 | 332 | $this->setWordsAsString($word); |
| 333 | 333 | } |
| 334 | 334 | $this->workOutWordsForSearching(); |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | if (count($this->words)) { |
| 342 | 342 | foreach ($this->getAllDataObjects() as $className) { |
| 343 | 343 | |
| 344 | - if(!$this->includeClassTest($className)) { |
|
| 344 | + if (!$this->includeClassTest($className)) { |
|
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | 347 | |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | $fields = $this->getAllValidFields($className); |
| 350 | 350 | $filterAny = []; |
| 351 | 351 | foreach ($fields as $field) { |
| 352 | - if(!$this->includeFieldTest($className, $field)) { |
|
| 352 | + if (!$this->includeFieldTest($className, $field)) { |
|
| 353 | 353 | continue; |
| 354 | 354 | } |
| 355 | 355 | $filterAny[$field . ':PartialMatch'] = $this->words; |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | DB::alteration_message(' ... Filter: ' . implode(', ', array_keys($filterAny))); |
| 364 | 364 | } |
| 365 | 365 | $defaultList = $this->getDefaultList($className); |
| 366 | - if(empty($defaultList)) { |
|
| 366 | + if (empty($defaultList)) { |
|
| 367 | 367 | $array[$className] = $className::get(); |
| 368 | 368 | } |
| 369 | 369 | $array[$className] = $array[$className]->filter(['ClassName' => $className]); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $array = []; |
| 407 | 407 | $classNames = $this->getAllDataObjects(); |
| 408 | 408 | foreach ($classNames as $className) { |
| 409 | - if($this->includeClassTest($className)) { |
|
| 409 | + if ($this->includeClassTest($className)) { |
|
| 410 | 410 | $array[$className] = $className::get() |
| 411 | 411 | ->filter('LastEdited:GreaterThan', date('Y-m-d H:i:s', $threshold)) |
| 412 | 412 | ->sort(['LastEdited' => 'DESC']) |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | ->limit($limit) |
| 455 | 455 | ; |
| 456 | 456 | foreach ($items as $item) { |
| 457 | - if(isset($fullListCheck[$item->ClassName][$item->ID])) { |
|
| 457 | + if (isset($fullListCheck[$item->ClassName][$item->ID])) { |
|
| 458 | 458 | continue; |
| 459 | 459 | } |
| 460 | 460 | if ($item->canView()) { |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | |
| 488 | 488 | $items = $this->turnArrayIntoObjects($matches); |
| 489 | 489 | foreach ($items as $item) { |
| 490 | - if($item->canView()) { |
|
| 490 | + if ($item->canView()) { |
|
| 491 | 491 | $link = $finder->getLink($item, $this->excludedClasses); |
| 492 | 492 | $cmsEditLink = $item->canEdit() ? $finder->getCMSEditLink($item) : ''; |
| 493 | 493 | $list->push( |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | } |
| 512 | 512 | $finder->saveCache(); |
| 513 | 513 | |
| 514 | - if(!empty($this->sortOverride)) { |
|
| 514 | + if (!empty($this->sortOverride)) { |
|
| 515 | 515 | return $list->sort($this->sortOverride); |
| 516 | 516 | } else { |
| 517 | 517 | return $list->sort(['SiteWideSearchSortValue' => 'ASC']); |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | |
| 665 | 665 | protected function includeClassTest(string $className): bool |
| 666 | 666 | { |
| 667 | - if(count($this->includedClassesWithSubClassess) && !in_array($className, $this->includedClassesWithSubClassess, true)) { |
|
| 667 | + if (count($this->includedClassesWithSubClassess) && !in_array($className, $this->includedClassesWithSubClassess, true)) { |
|
| 668 | 668 | if ($this->debug) { |
| 669 | 669 | DB::alteration_message(' ... Skipping as not included ' . $className); |
| 670 | 670 | } |
| 671 | 671 | return false; |
| 672 | 672 | } |
| 673 | - if(count($this->excludedClassesWithSubClassess) && in_array($className, $this->excludedClassesWithSubClassess, true)) { |
|
| 673 | + if (count($this->excludedClassesWithSubClassess) && in_array($className, $this->excludedClassesWithSubClassess, true)) { |
|
| 674 | 674 | if ($this->debug) { |
| 675 | 675 | DB::alteration_message(' ... Skipping as excluded ' . $className); |
| 676 | 676 | } |
@@ -685,9 +685,9 @@ discard block |
||
| 685 | 685 | |
| 686 | 686 | protected function includeFieldTest(string $className, string $field): bool |
| 687 | 687 | { |
| 688 | - if(isset($this->includedClassFieldCombos[$className][$field])) { |
|
| 688 | + if (isset($this->includedClassFieldCombos[$className][$field])) { |
|
| 689 | 689 | return true; |
| 690 | - } elseif(count($this->includedFields)) { |
|
| 690 | + } elseif (count($this->includedFields)) { |
|
| 691 | 691 | return in_array($field, $this->includedFields, true); |
| 692 | 692 | } elseif (count($this->excludedFields)) { |
| 693 | 693 | return in_array($field, $this->includedFields, true) ? false : true; |
@@ -699,7 +699,7 @@ discard block |
||
| 699 | 699 | protected function includeSubClasses(array $classes): array |
| 700 | 700 | { |
| 701 | 701 | $toAdd = []; |
| 702 | - foreach($classes as $class) { |
|
| 702 | + foreach ($classes as $class) { |
|
| 703 | 703 | $toAdd = array_merge($toAdd, ClassInfo::subclassesFor($class, false)); |
| 704 | 704 | } |
| 705 | 705 | return array_unique(array_merge($classes, $toAdd)); |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | $rels = $dataObject->{$relationName}(); |
| 247 | 247 | if ($rels) { |
| 248 | 248 | if ($rels instanceof DataList) { |
| 249 | - if(!$rels instanceof UnsavedRelationList) { |
|
| 249 | + if (!$rels instanceof UnsavedRelationList) { |
|
| 250 | 250 | $rels = $rels->first(); |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -301,8 +301,8 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | protected function classCanBeIncluded(string $dataObjectClassName): bool |
| 303 | 303 | { |
| 304 | - if(count($this->excludedClasses)) { |
|
| 305 | - if(!class_exists($dataObjectClassName)) { |
|
| 304 | + if (count($this->excludedClasses)) { |
|
| 305 | + if (!class_exists($dataObjectClassName)) { |
|
| 306 | 306 | return false; |
| 307 | 307 | } |
| 308 | 308 | return !in_array($dataObjectClassName, $this->excludedClasses, true); |