@@ -377,7 +377,9 @@ discard block |
||
| 377 | 377 | */ |
| 378 | 378 | protected function filtersOnLocale($query) { |
| 379 | 379 | foreach($query->getWhere() as $condition) { |
| 380 | - if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) return true; |
|
| 380 | + if(preg_match('/("|\'|`)Locale("|\'|`)/', $condition)) { |
|
| 381 | + return true; |
|
| 382 | + } |
|
| 381 | 383 | } |
| 382 | 384 | } |
| 383 | 385 | |
@@ -429,7 +431,9 @@ discard block |
||
| 429 | 431 | // FIXME - NO TEST COVERAGE BUT REQUIRED |
| 430 | 432 | function augmentDatabase() { |
| 431 | 433 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
| 432 | - if($this->owner->class != $baseDataClass) return; |
|
| 434 | + if($this->owner->class != $baseDataClass) { |
|
| 435 | + return; |
|
| 436 | + } |
|
| 433 | 437 | |
| 434 | 438 | $fields = array( |
| 435 | 439 | 'OriginalID' => 'Int', |
@@ -456,7 +460,9 @@ discard block |
||
| 456 | 460 | */ |
| 457 | 461 | public function requireDefaultRecords() { |
| 458 | 462 | // @todo This relies on the Locale attribute being on the base data class, and not any subclasses |
| 459 | - if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) return false; |
|
| 463 | + if($this->owner->class != ClassInfo::baseDataClass($this->owner->class)) { |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 460 | 466 | |
| 461 | 467 | // Permissions: If a group doesn't have any specific TRANSLATE_<locale> edit rights, |
| 462 | 468 | // but has CMS_ACCESS_CMSMain (general CMS access), then assign TRANSLATE_ALL permissions as a default. |
@@ -468,14 +474,20 @@ discard block |
||
| 468 | 474 | 'CMS_ACCESS_LeftAndMain', |
| 469 | 475 | 'ADMIN' |
| 470 | 476 | )); |
| 471 | - if($groups) foreach($groups as $group) { |
|
| 477 | + if($groups) { |
|
| 478 | + foreach($groups as $group) { |
|
| 472 | 479 | $codes = $group->Permissions()->column('Code'); |
| 480 | + } |
|
| 473 | 481 | $hasTranslationCode = false; |
| 474 | 482 | foreach($codes as $code) { |
| 475 | - if(preg_match('/^TRANSLATE_/', $code)) $hasTranslationCode = true; |
|
| 483 | + if(preg_match('/^TRANSLATE_/', $code)) { |
|
| 484 | + $hasTranslationCode = true; |
|
| 485 | + } |
|
| 476 | 486 | } |
| 477 | 487 | // Only add the code if no more restrictive code exists |
| 478 | - if(!$hasTranslationCode) Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
| 488 | + if(!$hasTranslationCode) { |
|
| 489 | + Permission::grant($group->ID, 'TRANSLATE_ALL'); |
|
| 490 | + } |
|
| 479 | 491 | } |
| 480 | 492 | |
| 481 | 493 | // If the Translatable extension was added after the first records were already |
@@ -485,7 +497,9 @@ discard block |
||
| 485 | 497 | 'SELECT "ID" FROM "%s" WHERE "Locale" IS NULL OR "Locale" = \'\'', |
| 486 | 498 | ClassInfo::baseDataClass($this->owner->class) |
| 487 | 499 | ))->column(); |
| 488 | - if(!$idsWithoutLocale) return; |
|
| 500 | + if(!$idsWithoutLocale) { |
|
| 501 | + return; |
|
| 502 | + } |
|
| 489 | 503 | |
| 490 | 504 | |
| 491 | 505 | |
@@ -502,7 +516,9 @@ discard block |
||
| 502 | 516 | * @param boolean $overwrite |
| 503 | 517 | */ |
| 504 | 518 | public function addTranslationGroup($originalID, $overwrite = false) { |
| 505 | - if(!$this->owner->exists()) return false; |
|
| 519 | + if(!$this->owner->exists()) { |
|
| 520 | + return false; |
|
| 521 | + } |
|
| 506 | 522 | |
| 507 | 523 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
| 508 | 524 | $existingGroupID = $this->getTranslationGroup($originalID); |
@@ -539,7 +555,9 @@ discard block |
||
| 539 | 555 | * @return int Numeric ID of the translationgroup in the <classname>_translationgroup table |
| 540 | 556 | */ |
| 541 | 557 | public function getTranslationGroup() { |
| 542 | - if(!$this->owner->exists()) return false; |
|
| 558 | + if(!$this->owner->exists()) { |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 543 | 561 | |
| 544 | 562 | $baseDataClass = ClassInfo::baseDataClass($this->owner->class); |
| 545 | 563 | return DB::query( |
@@ -646,8 +664,10 @@ discard block |
||
| 646 | 664 | $this->owner->ClassName = $changedFields['ClassName']['before']; |
| 647 | 665 | $translations = $this->owner->getTranslations(); |
| 648 | 666 | $this->owner->ClassName = $changedFields['ClassName']['after']; |
| 649 | - if($translations) foreach($translations as $translation) { |
|
| 667 | + if($translations) { |
|
| 668 | + foreach($translations as $translation) { |
|
| 650 | 669 | $translation->setClassName($this->owner->ClassName); |
| 670 | + } |
|
| 651 | 671 | $translation = $translation->newClassInstance($translation->ClassName); |
| 652 | 672 | $translation->populateDefaults(); |
| 653 | 673 | $translation->forceChange(); |
@@ -745,7 +765,9 @@ discard block |
||
| 745 | 765 | * @return DataObjectSet |
| 746 | 766 | */ |
| 747 | 767 | function getTranslations($locale = null, $stage = null) { |
| 748 | - if(!$this->owner->exists()) return new ArrayList(); |
|
| 768 | + if(!$this->owner->exists()) { |
|
| 769 | + return new ArrayList(); |
|
| 770 | + } |
|
| 749 | 771 | |
| 750 | 772 | // HACK need to disable language filtering in augmentSQL(), |
| 751 | 773 | // as we purposely want to get different language |
@@ -770,14 +792,18 @@ discard block |
||
| 770 | 792 | $currentStage = Versioned::current_stage(); |
| 771 | 793 | $joinOnClause = sprintf('"%s_translationgroups"."OriginalID" = "%s"."ID"', $baseDataClass, $baseDataClass); |
| 772 | 794 | if($this->owner->hasExtension("Versioned")) { |
| 773 | - if($stage) Versioned::reading_stage($stage); |
|
| 795 | + if($stage) { |
|
| 796 | + Versioned::reading_stage($stage); |
|
| 797 | + } |
|
| 774 | 798 | $translations = Versioned::get_by_stage( |
| 775 | 799 | $baseDataClass, |
| 776 | 800 | Versioned::current_stage(), |
| 777 | 801 | $filter, |
| 778 | 802 | null |
| 779 | 803 | )->leftJoin("{$baseDataClass}_translationgroups", $joinOnClause); |
| 780 | - if($stage) Versioned::reading_stage($currentStage); |
|
| 804 | + if($stage) { |
|
| 805 | + Versioned::reading_stage($currentStage); |
|
| 806 | + } |
|
| 781 | 807 | } else { |
| 782 | 808 | $class = $this->owner->class; |
| 783 | 809 | $translations = $baseDataClass::get() |
@@ -861,7 +887,9 @@ discard block |
||
| 861 | 887 | self::set_current_locale($originalLocale); |
| 862 | 888 | |
| 863 | 889 | if($original) { |
| 864 | - if($translation = $original->getTranslation($locale)) return trim($translation->RelativeLink(true), '/'); |
|
| 890 | + if($translation = $original->getTranslation($locale)) { |
|
| 891 | + return trim($translation->RelativeLink(true), '/'); |
|
| 892 | + } |
|
| 865 | 893 | } |
| 866 | 894 | } |
| 867 | 895 | |
@@ -916,7 +944,9 @@ discard block |
||
| 916 | 944 | $existingPage = SiteTree::get() |
| 917 | 945 | // disable get_one cache, as this otherwise may pick up results from when locale_filter was on |
| 918 | 946 | ->where("\"URLSegment\" = '{$this->owner->URLSegment}' $IDFilter $parentFilter")->First(); |
| 919 | - if($reEnableFilter) self::enable_locale_filter(); |
|
| 947 | + if($reEnableFilter) { |
|
| 948 | + self::enable_locale_filter(); |
|
| 949 | + } |
|
| 920 | 950 | |
| 921 | 951 | // By returning TRUE or FALSE, we overrule the base SiteTree->validateURLSegment() logic |
| 922 | 952 | return !$existingPage; |
@@ -511,7 +511,7 @@ |
||
| 511 | 511 | } |
| 512 | 512 | } |
| 513 | 513 | $cache->save(json_encode($result),$key); |
| 514 | - } else { |
|
| 514 | + } else { |
|
| 515 | 515 | // true is necessary here to decode the array hash back to an array and not a struct |
| 516 | 516 | self::$cacheHitCtr++; |
| 517 | 517 | $result = json_decode($result,true); |
@@ -514,8 +514,7 @@ discard block |
||
| 514 | 514 | // this goes to elastica service |
| 515 | 515 | $this->service->remove($this->owner); |
| 516 | 516 | } |
| 517 | - } |
|
| 518 | - catch (\Elastica\Exception\NotFoundException $e) { |
|
| 517 | + } catch (\Elastica\Exception\NotFoundException $e) { |
|
| 519 | 518 | trigger_error("Deleted document " . $this->owner->ClassName . " (" . $this->owner->ID . |
| 520 | 519 | ") not found in search index.", E_USER_NOTICE); |
| 521 | 520 | } |
@@ -533,7 +532,9 @@ discard block |
||
| 533 | 532 | $fields = \Config::inst()->get(get_class($this->owner), 'searchable_fields'); |
| 534 | 533 | |
| 535 | 534 | // fallback to default method |
| 536 | - if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName); |
|
| 535 | + if(!$fields) { |
|
| 536 | + user_error('The field $searchable_fields must be set for the class ' . $this->owner->ClassName); |
|
| 537 | + } |
|
| 537 | 538 | |
| 538 | 539 | // get the values of these fields |
| 539 | 540 | $elasticaMapping = $this->fieldsToElasticaConfig($fields); |
@@ -554,7 +555,9 @@ discard block |
||
| 554 | 555 | |
| 555 | 556 | $relClass = $has_lists[$methodName]; |
| 556 | 557 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 557 | - if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 558 | + if(!$fields) { |
|
| 559 | + user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 560 | + } |
|
| 558 | 561 | $rewrite = $this->fieldsToElasticaConfig($fields); |
| 559 | 562 | |
| 560 | 563 | // mark as a method, the resultant fields are correct |
@@ -562,7 +565,9 @@ discard block |
||
| 562 | 565 | } else if(isset($has_ones[$methodName])) { |
| 563 | 566 | $relClass = $has_ones[$methodName]; |
| 564 | 567 | $fields = \Config::inst()->get($relClass, 'searchable_fields'); |
| 565 | - if(!$fields) user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 568 | + if(!$fields) { |
|
| 569 | + user_error('The field $searchable_fields must be set for the class ' . $relClass); |
|
| 570 | + } |
|
| 566 | 571 | $rewrite = $this->fieldsToElasticaConfig($fields); |
| 567 | 572 | |
| 568 | 573 | // mark as a method, the resultant fields are correct |