diff --git a/_config/config.yml b/_config/config.yml index 3bacd7a..824e4c4 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,60 +1,11 @@ --- Name: subsiteconfig +After: + - 'framework/*' --- +SilverStripe\AssetAdmin\Controller\AssetAdmin: + treats_subsite_0_as_global: true + SilverStripe\Control\Director: rules: SubsiteXHRController: SilverStripe\Subsites\Controller\SubsiteXHRController - -SilverStripe\AssetAdmin\Controller\AssetAdmin: - treats_subsite_0_as_global: true - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension - -SilverStripe\CMS\Model\SiteTree: - extensions: - - SilverStripe\Subsites\Extensions\SiteTreeSubsites - -SilverStripe\CMS\Controllers\ContentController: - extensions: - - SilverStripe\Subsites\Extensions\ControllerSubsites - -SilverStripe\CMS\Controllers\CMSPageAddController: - extensions: - - SilverStripe\Subsites\Extensions\CMSPageAddControllerExtension - -SilverStripe\Admin\LeftAndMain: - extensions: - - SilverStripe\Subsites\Extensions\LeftAndMainSubsites - - SilverStripe\Subsites\Extensions\ControllerSubsites - -SilverStripe\Security\Group: - extensions: - - SilverStripe\Subsites\Extensions\GroupSubsites - -SilverStripe\Assets\File: - extensions: - - SilverStripe\Subsites\Extensions\FileSubsites - -SilverStripe\CMS\Model\ErrorPage: - extensions: - - SilverStripe\Subsites\Extensions\ErrorPageSubsite - -SilverStripe\SiteConfig\SiteConfig: - extensions: - - SilverStripe\Subsites\Extensions\SiteConfigSubsites - -SilverStripe\Admin\SecurityAdmin: - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension - -SilverStripe\CMS\Controllers\CMSMain: - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension - -SilverStripe\CMS\Controllers\CMSPagesController: - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension - -SilverStripe\Subsites\Admin\SubsiteAdmin: - extensions: - - SilverStripe\Subsites\Extensions\SubsiteMenuExtension diff --git a/_config/extensions.yml b/_config/extensions.yml new file mode 100644 index 0000000..1f0d3ee --- /dev/null +++ b/_config/extensions.yml @@ -0,0 +1,65 @@ +--- +Name: subsiteextensions +After: + - 'framework/*' +--- +SilverStripe\CMS\Model\SiteTree: + extensions: + - SilverStripe\Subsites\Extensions\SiteTreeSubsites + +SilverStripe\CMS\Controllers\ContentController: + extensions: + - SilverStripe\Subsites\Extensions\ControllerSubsites + +SilverStripe\CMS\Controllers\CMSPageAddController: + extensions: + - SilverStripe\Subsites\Extensions\CMSPageAddControllerExtension + +SilverStripe\Admin\LeftAndMain: + extensions: + - SilverStripe\Subsites\Extensions\LeftAndMainSubsites + - SilverStripe\Subsites\Extensions\ControllerSubsites + +SilverStripe\Security\Group: + extensions: + - SilverStripe\Subsites\Extensions\GroupSubsites + +SilverStripe\Assets\File: + extensions: + - SilverStripe\Subsites\Extensions\FileSubsites + +SilverStripe\CMS\Model\ErrorPage: + extensions: + - SilverStripe\Subsites\Extensions\ErrorPageSubsite + +SilverStripe\SiteConfig\SiteConfig: + extensions: + - SilverStripe\Subsites\Extensions\SiteConfigSubsites + +SilverStripe\Reports\Report: + extensions: + - SilverStripe\Subsites\SubsiteReportWrapper + +SilverStripe\AssetAdmin\Controller\AssetAdmin: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension + +SilverStripe\Admin\SecurityAdmin: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension + +SilverStripe\CMS\Controllers\CMSMain: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension + +SilverStripe\CMS\Controllers\CMSPagesController: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension + +SilverStripe\Subsites\SubsiteAdmin: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension + +SilverStripe\CMS\Controllers\CMSPageSettingsController: + extensions: + - SilverStripe\Subsites\Extensions\SubsiteMenuExtension diff --git a/code/extensions/CMSPageAddControllerExtension.php b/code/extensions/CMSPageAddControllerExtension.php index 934677f..4ac1ca4 100644 --- a/code/extensions/CMSPageAddControllerExtension.php +++ b/code/extensions/CMSPageAddControllerExtension.php @@ -1,8 +1,6 @@ ID )); } + } diff --git a/code/extensions/SiteConfigSubsites.php b/code/extensions/SiteConfigSubsites.php index 3dbbb17..b886361 100644 --- a/code/extensions/SiteConfigSubsites.php +++ b/code/extensions/SiteConfigSubsites.php @@ -17,9 +17,9 @@ use SilverStripe\Subsites\Model\Subsite; */ class SiteConfigSubsites extends DataExtension { - private static $has_one = [ - 'Subsite' => Subsite::class, // The subsite that this page belongs to - ]; + private static $has_one = [ + 'Subsite' => Subsite::class, // The subsite that this page belongs to + ]; /** * Update any requests to limit the results to the current site @@ -66,4 +66,5 @@ class SiteConfigSubsites extends DataExtension { $fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID())); } + } diff --git a/code/extensions/SiteTreeSubsites.php b/code/extensions/SiteTreeSubsites.php index af3b567..abcb06f 100644 --- a/code/extensions/SiteTreeSubsites.php +++ b/code/extensions/SiteTreeSubsites.php @@ -5,24 +5,24 @@ namespace SilverStripe\Subsites\Extensions; use Page; use SilverStripe\CMS\Model\SiteTree; -use SilverStripe\ORM\DataQuery; -use SilverStripe\Forms\FieldList; -use SilverStripe\Forms\DropdownField; -use SilverStripe\Forms\CheckboxField; -use SilverStripe\Forms\InlineFormAction; -use SilverStripe\Forms\ToggleCompositeField; -use SilverStripe\Core\Config\Config; use SilverStripe\Control\Controller; -use SilverStripe\ORM\Queries\SQLSelect; -use SilverStripe\SiteConfig\SiteConfig; -use SilverStripe\ORM\DataObject; -use SilverStripe\Security\Member; -use SilverStripe\View\SSViewer; use SilverStripe\Control\Director; use SilverStripe\Control\HTTP; use SilverStripe\Core\Convert; +use SilverStripe\Core\Config\Config; +use SilverStripe\Forms\CheckboxField; +use SilverStripe\Forms\DropdownField; +use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\InlineFormAction; +use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\ORM\DataExtension; +use SilverStripe\ORM\DataObject; +use SilverStripe\ORM\DataQuery; +use SilverStripe\ORM\Queries\SQLSelect; +use SilverStripe\Security\Member; +use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\Subsites\Model\Subsite; +use SilverStripe\View\SSViewer; /** @@ -30,6 +30,7 @@ use SilverStripe\Subsites\Model\Subsite; */ class SiteTreeSubsites extends DataExtension { + private static $has_one = [ 'Subsite' => Subsite::class, // The subsite that this page belongs to ]; @@ -50,11 +51,11 @@ class SiteTreeSubsites extends DataExtension return false; } - /** - * Update any requests to limit the results to the current site - * @param SQLSelect $query - * @param DataQuery $dataQuery - */ + /** + * Update any requests to limit the results to the current site + * @param SQLSelect $query + * @param DataQuery $dataQuery + */ public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { if (Subsite::$disable_subsite_filter) { @@ -114,16 +115,16 @@ class SiteTreeSubsites extends DataExtension $fields->addFieldsToTab( 'Root.Main', ToggleCompositeField::create('SubsiteOperations', - _t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'), - array( - new DropdownField("CopyToSubsiteID", _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), $subsitesMap), - new CheckboxField("CopyToSubsiteWithChildren", _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')), - $copyAction = new InlineFormAction( - "copytosubsite", - _t('SiteTreeSubsites.CopyAction', "Copy") - ) - ) - )->setHeadingLevel(4) + _t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'), + array( + new DropdownField("CopyToSubsiteID", _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), $subsitesMap), + new CheckboxField("CopyToSubsiteWithChildren", _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')), + $copyAction = new InlineFormAction( + "copytosubsite", + _t('SiteTreeSubsites.CopyAction', "Copy") + ) + ) + )->setHeadingLevel(4) ); @@ -276,10 +277,10 @@ class SiteTreeSubsites extends DataExtension Subsite::changeSubsite($oldSubsite); if($includeChildren) { - foreach($this->owner->AllChildren() as $child) { - $child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID); - } - } + foreach($this->owner->AllChildren() as $child) { + $child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID); + } + } return $page; } @@ -420,4 +421,5 @@ class SiteTreeSubsites extends DataExtension } } } + } diff --git a/code/forms/GridFieldSubsiteDetailForm.php b/code/forms/GridFieldSubsiteDetailForm.php index 6c4c619..89fec05 100644 --- a/code/forms/GridFieldSubsiteDetailForm.php +++ b/code/forms/GridFieldSubsiteDetailForm.php @@ -2,65 +2,11 @@ namespace SilverStripe\Subsites\Forms; - -use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\GridField\GridFieldDetailForm; -use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest; -use SilverStripe\Subsites\Model\Subsite; - class GridFieldSubsiteDetailForm extends GridFieldDetailForm { - protected $itemRequestClass = GridFieldSubsiteDetailForm_ItemRequest::class; -} - -class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest -{ - private static $allowed_actions = [ - 'ItemEditForm', - ]; - - /** - * Builds an item edit form. The arguments to getCMSFields() are the popupController and - * popupFormName, however this is an experimental API and may change. - * - * @todo In the future, we will probably need to come up with a tigher object representing a partially - * complete controller with gaps for extra functionality. This, for example, would be a better way - * of letting Security/login put its log-in form inside a UI specified elsewhere. - * - * @return Form - * @see GridFieldDetailForm_ItemRequest::ItemEditForm() - */ - public function ItemEditForm() - { - $form = parent::ItemEditForm(); - - if ($this->record->ID == 0) { - $templates = Subsite::get()->sort('Title'); - $templateArray = []; - if ($templates) { - $templateArray = $templates->map('ID', 'Title'); - } - - $templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), - $templateArray); - $templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')'); - $form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown); - } - - return $form; - } - - public function doSave($data, $form) - { - $new_record = $this->record->ID == 0; - if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) { - $template = Subsite::get()->byID(intval($data['TemplateID'])); - if ($template) { - $this->record = $template->duplicate(); - } - } - - return parent::doSave($data, $form); - } + + protected $itemRequestClass = 'GridFieldSubsiteDetailForm_ItemRequest'; + } diff --git a/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php b/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php new file mode 100644 index 0000000..deadc20 --- /dev/null +++ b/code/forms/GridFieldSubsiteDetailForm_ItemRequest.php @@ -0,0 +1,59 @@ +record->ID == 0) { + $templates = Subsite::get()->sort('Title'); + $templateArray = array(); + if ($templates) { + $templateArray = $templates->map('ID', 'Title'); + } + + $templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), $templateArray); + $templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')'); + $form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown); + } + + return $form; + } + + public function doSave($data, $form) + { + $new_record = $this->record->ID == 0; + if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) { + $template = Subsite::get()->byID(intval($data['TemplateID'])); + if ($template) { + $this->record = $template->duplicate(); + } + } + + return parent::doSave($data, $form); + } + +} diff --git a/code/forms/WildcardDomainField.php b/code/forms/WildcardDomainField.php index 7e3c2e0..cab611a 100644 --- a/code/forms/WildcardDomainField.php +++ b/code/forms/WildcardDomainField.php @@ -1,5 +1,7 @@ controllerAugmentInit() - * @return Subsite - */ - public static function currentSubsite() - {// get_by_id handles caching so we don't have to - return DataObject::get_by_id(Subsite::class, self::currentSubsiteID()); - } + /** + * Gets the subsite currently set in the session. + * + * @uses ControllerSubsites->controllerAugmentInit() + * @return Subsite + */ + public static function currentSubsite() + {// get_by_id handles caching so we don't have to + return DataObject::get_by_id(Subsite::class, self::currentSubsiteID()); + } - /** - * This function gets the current subsite ID from the session. It used in the backend so Ajax requests - * use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain - * directly from ModelAsController::getNestedController. Only gets Subsite instances which have their - * {@link IsPublic} flag set to TRUE. - * - * You can simulate subsite access without creating virtual hosts by appending ?SubsiteID= to the request. - * - * @todo Pass $request object from controller so we don't have to rely on $_GET - * - * @return int ID of the current subsite instance - */ - public static function currentSubsiteID() - {$id = null; + /** + * This function gets the current subsite ID from the session. It used in the backend so Ajax requests + * use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain + * directly from ModelAsController::getNestedController. Only gets Subsite instances which have their + * {@link IsPublic} flag set to TRUE. + * + * You can simulate subsite access without creating virtual hosts by appending ?SubsiteID= to the request. + * + * @todo Pass $request object from controller so we don't have to rely on $_GET + * + * @return int ID of the current subsite instance + */ + public static function currentSubsiteID() + { + $id = null; if (isset($_GET['SubsiteID'])) { $id = (int)$_GET['SubsiteID']; @@ -155,114 +156,126 @@ class Subsite extends DataObject $id = Session::get('SubsiteID'); } - if($id === null) { - $id = self::getSubsiteIDForDomain(); - } + if ($id === null) { + $id = self::getSubsiteIDForDomain(); + } - return (int)$id; - } + return (int)$id; + } - /** - * Switch to another subsite through storing the subsite identifier in the current PHP session. - * Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE. - * - * @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself - */ - public static function changeSubsite($subsite) { - // Session subsite change only meaningful if the session is active. - // Otherwise we risk setting it to wrong value, e.g. if we rely on currentSubsiteID. - if (!Subsite::$use_session_subsiteid) return; + /** + * Switch to another subsite through storing the subsite identifier in the current PHP session. + * Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE. + * + * @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself + */ + public static function changeSubsite($subsite) + { + // Session subsite change only meaningful if the session is active. + // Otherwise we risk setting it to wrong value, e.g. if we rely on currentSubsiteID. + if (!Subsite::$use_session_subsiteid) { + return; + } - if(is_object($subsite)) $subsiteID = $subsite->ID; - else $subsiteID = $subsite; + if (is_object($subsite)) { + $subsiteID = $subsite->ID; + } else { + $subsiteID = $subsite; + } - Session::set('SubsiteID', (int)$subsiteID); + Session::set('SubsiteID', (int)$subsiteID); - // Set locale - if (is_object($subsite) && $subsite->Language != '') { - $locale = i18n::get_locale_from_lang($subsite->Language); - if($locale) { - i18n::set_locale($locale); - } - } + // Set locale + if (is_object($subsite) && $subsite->Language != '') { + $locale = i18n::get_locale_from_lang($subsite->Language); + if ($locale) { + i18n::set_locale($locale); + } + } - Permission::flush_permission_cache(); - } + Permission::flush_permission_cache(); + } - /** - * Get a matching subsite for the given host, or for the current HTTP_HOST. - * Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string, - * for example matching all subdomains on *.example.com with one subsite, - * and all subdomains on *.example.org on another. - * - * @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used. - * @return int Subsite ID - */ - public static function getSubsiteIDForDomain($host = null, $checkPermissions = true) { - if($host == null && isset($_SERVER['HTTP_HOST'])) { - $host = $_SERVER['HTTP_HOST']; - } + /** + * Get a matching subsite for the given host, or for the current HTTP_HOST. + * Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string, + * for example matching all subdomains on *.example.com with one subsite, + * and all subdomains on *.example.org on another. + * + * @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used. + * @return int Subsite ID + */ + public static function getSubsiteIDForDomain($host = null, $checkPermissions = true) + { + if ($host == null && isset($_SERVER['HTTP_HOST'])) { + $host = $_SERVER['HTTP_HOST']; + } - $matchingDomains = null; - $cacheKey = null; - if ($host) { - if(!self::$strict_subdomain_matching) $host = preg_replace('/^www\./', '', $host); + $matchingDomains = null; + $cacheKey = null; + if ($host) { + if (!self::$strict_subdomain_matching) { + $host = preg_replace('/^www\./', '', $host); + } $cacheKey = implode('_', [$host, Member::currentUserID(), self::$check_is_public]); if (isset(self::$_cache_subsite_for_domain[$cacheKey])) { return self::$_cache_subsite_for_domain[$cacheKey]; } - $SQL_host = Convert::raw2sql($host); - $matchingDomains = DataObject::get( - SubsiteDomain::class, - "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')", - "\"IsPrimary\" DESC" - )->innerJoin('Subsite', "\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1"); - } + $SQL_host = Convert::raw2sql($host); + $matchingDomains = DataObject::get( + SubsiteDomain::class, + "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')", + "\"IsPrimary\" DESC" + )->innerJoin('Subsite', + "\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1"); + } - if($matchingDomains && $matchingDomains->Count()) { - $subsiteIDs = array_unique($matchingDomains->column('SubsiteID')); - $subsiteDomains = array_unique($matchingDomains->column('Domain')); - if(sizeof($subsiteIDs) > 1) { - throw new UnexpectedValueException(sprintf( - "Multiple subsites match on '%s': %s", - $host, - implode(',', $subsiteDomains) - )); - } + if ($matchingDomains && $matchingDomains->Count()) { + $subsiteIDs = array_unique($matchingDomains->column('SubsiteID')); + $subsiteDomains = array_unique($matchingDomains->column('Domain')); + if (sizeof($subsiteIDs) > 1) { + throw new UnexpectedValueException(sprintf( + "Multiple subsites match on '%s': %s", + $host, + implode(',', $subsiteDomains) + )); + } - $subsiteID = $subsiteIDs[0]; - } else { - if($default = DataObject::get_one(Subsite::class, "\"DefaultSite\" = 1")) { - // Check for a 'default' subsite - $subsiteID = $default->ID; - } else { - // Default subsite id = 0, the main site - $subsiteID = 0; - }} + $subsiteID = $subsiteIDs[0]; + } else { + if ($default = DataObject::get_one(Subsite::class, "\"DefaultSite\" = 1")) { + // Check for a 'default' subsite + $subsiteID = $default->ID; + } else { + // Default subsite id = 0, the main site + $subsiteID = 0; + } + } - if ($cacheKey) { - self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID; - } + if ($cacheKey) { + self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID; + } - return $subsiteID; - } + return $subsiteID; + } - /** - * - * @param string $className - * @param string $filter - * @param string $sort - * @param string $join - * @param string $limit - * @return DataList - */ - public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "") { - $result = DataObject::get($className, $filter, $sort, $join, $limit); - $result = $result->setDataQueryParam('Subsite.filter', false); - return $result; - } + /** + * + * @param string $className + * @param string $filter + * @param string $sort + * @param string $join + * @param string $limit + * @return DataList + */ + public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "") + { + $result = DataObject::get($className, $filter, $sort, $join, $limit); + $result = $result->setDataQueryParam('Subsite.filter', false); + return $result; + } /** * Disable the sub-site filtering; queries will select from all subsites @@ -290,18 +303,18 @@ class Subsite extends DataObject { $subsites = Subsite::get(); - if($includeMainSite) { - $subsites = $subsites->toArray(); + if ($includeMainSite) { + $subsites = $subsites->toArray(); - $mainSite = new Subsite(); - $mainSite->Title = $mainSiteTitle; - array_unshift($subsites, $mainSite); + $mainSite = new Subsite(); + $mainSite->Title = $mainSiteTitle; + array_unshift($subsites, $mainSite); - $subsites = ArrayList::create($subsites); - } + $subsites = ArrayList::create($subsites); + } - return $subsites; - } + return $subsites; + } /* * Returns an ArrayList of the subsites accessible to the current user. @@ -322,27 +335,27 @@ class Subsite extends DataObject $member = DataObject::get_by_id(Member::class, $member); } - $subsites = new ArrayList(); + $subsites = new ArrayList(); - // Collect subsites for all sections. - $menu = CMSMenu::get_viewable_menu_items(); - foreach($menu as $candidate) { - if ($candidate->controller) { - $accessibleSites = singleton($candidate->controller)->sectionSites( - $includeMainSite, - $mainSiteTitle, - $member - ); + // Collect subsites for all sections. + $menu = CMSMenu::get_viewable_menu_items(); + foreach ($menu as $candidate) { + if ($candidate->controller) { + $accessibleSites = singleton($candidate->controller)->sectionSites( + $includeMainSite, + $mainSiteTitle, + $member + ); - // Replace existing keys so no one site appears twice. - $subsites->merge($accessibleSites); - } - } + // Replace existing keys so no one site appears twice. + $subsites->merge($accessibleSites); + } + } - $subsites->removeDuplicates(); + $subsites->removeDuplicates(); - return $subsites; - } + return $subsites; + } /** * Return the subsites that the current user can access by given permission. @@ -354,7 +367,12 @@ class Subsite extends DataObject * @param $member * @return DataList of {@link Subsite} instances */ - public static function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) + public static function accessible_sites( + $permCode, + $includeMainSite = true, + $mainSiteTitle = "Main site", + $member = null + ) { // Rationalise member arguments if (!$member) { @@ -367,15 +385,18 @@ class Subsite extends DataObject $member = DataObject::get_by_id(Member::class, $member); } - // Rationalise permCode argument - if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'"; - else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'"; + // Rationalise permCode argument + if (is_array($permCode)) { + $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'"; + } else { + $SQL_codes = "'" . Convert::raw2sql($permCode) . "'"; + } - // Cache handling - $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; - if(isset(self::$_cache_accessible_sites[$cacheKey])) { - return self::$_cache_accessible_sites[$cacheKey]; - } + // Cache handling + $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; + if (isset(self::$_cache_accessible_sites[$cacheKey])) { + return self::$_cache_accessible_sites[$cacheKey]; + } $subsites = DataList::create(Subsite::class) ->where("\"Subsite\".\"Title\" != ''") @@ -387,8 +408,11 @@ class Subsite extends DataObject ->innerJoin('Permission', "\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); - if(!$subsites) $subsites = new ArrayList(); + if (!$subsites) { + $subsites = new ArrayList(); + } + /** @var DataList $rolesSubsites */ $rolesSubsites = DataList::create(Subsite::class) ->where("\"Subsite\".\"Title\" != ''") ->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"") @@ -401,15 +425,19 @@ class Subsite extends DataObject ->innerJoin('PermissionRoleCode', "\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); - if(!$subsites && $rolesSubsites) return $rolesSubsites; + if (!$subsites && $rolesSubsites) { + return $rolesSubsites; + } - $subsites = new ArrayList($subsites->toArray()); + $subsites = new ArrayList($subsites->toArray()); - if($rolesSubsites) foreach($rolesSubsites as $subsite) { - if(!$subsites->find('ID', $subsite->ID)) { - $subsites->push($subsite); - } - } + if ($rolesSubsites) { + foreach ($rolesSubsites as $subsite) { + if (!$subsites->find('ID', $subsite->ID)) { + $subsites->push($subsite); + } + } + } if ($includeMainSite) { if (!is_array($permCode)) { @@ -501,43 +529,46 @@ class Subsite extends DataObject $member = Member::currentUser(); } - if(!$member) return false; + if (!$member) { + return false; + } - if(!in_array("ADMIN", $permissionCodes)) $permissionCodes[] = "ADMIN"; + if (!in_array("ADMIN", $permissionCodes)) { + $permissionCodes[] = "ADMIN"; + } - $SQLa_perm = Convert::raw2sql($permissionCodes); - $SQL_perms = join("','", $SQLa_perm); - $memberID = (int)$member->ID; + $SQLa_perm = Convert::raw2sql($permissionCodes); + $SQL_perms = join("','", $SQLa_perm); + $memberID = (int)$member->ID; - // Count this user's groups which can access the main site - $groupCount = DB::query(" - SELECT COUNT(\"Permission\".\"ID\") - FROM \"Permission\" - INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\" AND \"Group\".\"AccessAllSubsites\" = 1 - INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Permission\".\"GroupID\" - WHERE \"Permission\".\"Code\" IN ('$SQL_perms') - AND \"MemberID\" = {$memberID} - ")->value(); + // Count this user's groups which can access the main site + $groupCount = DB::query(" + SELECT COUNT(\"Permission\".\"ID\") + FROM \"Permission\" + INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\" AND \"Group\".\"AccessAllSubsites\" = 1 + INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Permission\".\"GroupID\" + WHERE \"Permission\".\"Code\" IN ('$SQL_perms') + AND \"MemberID\" = {$memberID} + ")->value(); - // Count this user's groups which have a role that can access the main site - $roleCount = DB::query(" - SELECT COUNT(\"PermissionRoleCode\".\"ID\") - FROM \"Group\" - INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" - INNER JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\" - INNER JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\" - INNER JOIN \"PermissionRoleCode\" ON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" - WHERE \"PermissionRoleCode\".\"Code\" IN ('$SQL_perms') - AND \"Group\".\"AccessAllSubsites\" = 1 - AND \"MemberID\" = {$memberID} - ")->value(); + // Count this user's groups which have a role that can access the main site + $roleCount = DB::query(" + SELECT COUNT(\"PermissionRoleCode\".\"ID\") + FROM \"Group\" + INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\" + INNER JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\" + INNER JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\" + INNER JOIN \"PermissionRoleCode\" ON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" + WHERE \"PermissionRoleCode\".\"Code\" IN ('$SQL_perms') + AND \"Group\".\"AccessAllSubsites\" = 1 + AND \"MemberID\" = {$memberID} + ")->value(); // There has to be at least one that allows access. return ($groupCount + $roleCount > 0); } /** - * * @var array */ private static $db = [ @@ -547,16 +578,15 @@ class Subsite extends DataObject 'Theme' => 'Varchar', 'Language' => 'Varchar(6)', - // Used to hide unfinished/private subsites from public view. - // If unset, will default to true - 'IsPublic' => 'Boolean', + // Used to hide unfinished/private subsites from public view. + // If unset, will default to true + 'IsPublic' => 'Boolean', - // Comma-separated list of disallowed page types - 'PageTypeBlacklist' => 'Text', - ]; + // Comma-separated list of disallowed page types + 'PageTypeBlacklist' => 'Text', + ]; /** - * * @var array */ private static $has_many = [ @@ -564,44 +594,41 @@ class Subsite extends DataObject ]; /** - * * @var array */ private static $belongs_many_many = [ "Groups" => Group::class, ]; - /** - * - * @var array - */ - private static $defaults = [ - 'IsPublic' => 1 - ]; + /** + * @var array + */ + private static $defaults = [ + 'IsPublic' => 1 + ]; - /** - * - * @var array - */ - private static $searchable_fields = [ - 'Title', - 'Domains.Domain', - 'IsPublic', - ]; + /** + * @var array + */ + private static $searchable_fields = [ + 'Title', + 'Domains.Domain', + 'IsPublic', + ]; - /** - * - * @var string - */ - private static $default_sort = "\"Title\" ASC"; + /** + * @var string + */ + private static $default_sort = "\"Title\" ASC"; - /** - * @todo Possible security issue, don't grant edit permissions to everybody. - * @return boolean - */ - public function canEdit($member = false) - {return true; - } + /** + * @todo Possible security issue, don't grant edit permissions to everybody. + * @return boolean + */ + public function canEdit($member = false) + { + return true; + } /** * Show the configuration fields for each subsite @@ -610,7 +637,7 @@ class Subsite extends DataObject */ public function getCMSFields() { - if ($this->ID!=0) { + if ($this->ID != 0) { $domainTable = new GridField( "Domains", _t('Subsite.DomainsListTitle', "Domains"), @@ -620,7 +647,8 @@ class Subsite extends DataObject } else { $domainTable = new LiteralField( 'Domains', - '

'._t('Subsite.DOMAINSAVEFIRST', 'You can only add domains after saving for the first time').'

' + '

' . _t('Subsite.DOMAINSAVEFIRST', + 'You can only add domains after saving for the first time') . '

' ); } @@ -630,7 +658,7 @@ class Subsite extends DataObject Injector::inst()->get(IntlLocales::class)->getLocales() ); - $pageTypeMap = array(); + $pageTypeMap = []; $pageTypes = SiteTree::page_type_classes(); foreach ($pageTypes as $pageType) { $pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name(); @@ -655,98 +683,103 @@ class Subsite extends DataObject new CheckboxField('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite), new CheckboxField('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), - new DropdownField('Theme',$this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme), + new DropdownField('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme), - new LiteralField( - 'PageTypeBlacklistToggle', - sprintf( - '', - _t('Subsite.PageTypeBlacklistField', 'Disallow page types?') - ) - ), - new CheckboxSetField( - 'PageTypeBlacklist', - false, - $pageTypeMap - ) - ) - ), - new HiddenField('ID', '', $this->ID), - new HiddenField('IsSubsite', '', 1) - ); + new LiteralField( + 'PageTypeBlacklistToggle', + sprintf( + '', + _t('Subsite.PageTypeBlacklistField', 'Disallow page types?') + ) + ), + new CheckboxSetField( + 'PageTypeBlacklist', + false, + $pageTypeMap + ) + ) + ), + new HiddenField('ID', '', $this->ID), + new HiddenField('IsSubsite', '', 1) + ); - $subsiteTabs->addExtraClass('subsite-model'); + $subsiteTabs->addExtraClass('subsite-model'); - $this->extend('updateCMSFields', $fields); - return $fields; - } + $this->extend('updateCMSFields', $fields); + return $fields; + } - /** - * - * @param boolean $includerelations - * @return array - */ - public function fieldLabels($includerelations = true) { - $labels = parent::fieldLabels($includerelations); - $labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name'); - $labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL'); - $labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site'); - $labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme'); - $labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language'); - $labels['IsPublic'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access'); - $labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist'); - $labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain'); - $labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain'); + /** + * + * @param boolean $includerelations + * @return array + */ + public function fieldLabels($includerelations = true) + { + $labels = parent::fieldLabels($includerelations); + $labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name'); + $labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL'); + $labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site'); + $labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme'); + $labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language'); + $labels['IsPublic'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access'); + $labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist'); + $labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain'); + $labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain'); - return $labels; - } + return $labels; + } - /** + /** + * Return the themes that can be used with this subsite, as an array of themecode => description + * + * @return array + */ + public function allowedThemes() + { + if ($themes = $this->stat('allowed_themes')) { + return ArrayLib::valuekey($themes); + } else { + $themes = []; + if (is_dir(THEMES_PATH)) { + foreach (scandir(THEMES_PATH) as $theme) { + if ($theme[0] == '.') { + continue; + } + $theme = strtok($theme, '_'); + $themes[$theme] = $theme; + } + ksort($themes); + } + return $themes; + } + } - * Return the themes that can be used with this subsite, as an array of themecode => description - * - * @return array - */ - public function allowedThemes() - {if($themes = $this->stat('allowed_themes')) { - return ArrayLib::valuekey($themes); - } else { - $themes = []; - if(is_dir(THEMES_PATH)) { - foreach(scandir(THEMES_PATH) as $theme) { - if($theme[0] == '.') {continue;} - $theme = strtok($theme,'_'); - $themes[$theme] = $theme; - } - ksort($themes); - } - return $themes; - } - } + /** + * @return string Current locale of the subsite + */ + public function getLanguage() + { + if ($this->getField('Language')) { + return $this->getField('Language'); + } else { + return i18n::get_locale(); + } + } - /** - * @return string Current locale of the subsite - */ - public function getLanguage() { - if($this->getField('Language')) { - return $this->getField('Language'); - } else { - return i18n::get_locale(); - } - } - - /** - * - * @return ValidationResult - */ - public function validate() { - $result = parent::validate(); - if(!$this->Title) { - $result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"')); - } - return $result; - } + /** + * + * @return ValidationResult + */ + public function validate() + { + $result = parent::validate(); + if (!$this->Title) { + $result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"')); + } + return $result; + } /** * Whenever a Subsite is written, rewrite the hostmap @@ -815,38 +848,41 @@ class Subsite extends DataObject return Director::absoluteBaseURL(); } - /** - * @todo getClassName is redundant, already stored as a database field? - */ - public function getClassName() { - return $this->class; - } + /** + * @todo getClassName is redundant, already stored as a database field? + */ + public function getClassName() + { + return $this->class; + } - /** - * Javascript admin action to duplicate this subsite - * - * @return string - javascript - */ - public function adminDuplicate() - {$newItem = $this->duplicate(); - $message = _t( - 'Subsite.CopyMessage', - 'Created a copy of {title}', - ['title' => Convert::raw2js($this->Title)] - ); + /** + * Javascript admin action to duplicate this subsite + * + * @return string - javascript + */ + public function adminDuplicate() + { + $newItem = $this->duplicate(); + $message = _t( + 'Subsite.CopyMessage', + 'Created a copy of {title}', + ['title' => Convert::raw2js($this->Title)] + ); - return <<ID'); + return <<ID'); JS; - } + } - /** - * Make this subsite the current one - */ - public function activate() { - Subsite::changeSubsite($this); - } + /** + * Make this subsite the current one + */ + public function activate() + { + Subsite::changeSubsite($this); + } /** * @@ -860,26 +896,27 @@ JS; } $SQL_permissionCodes = Convert::raw2sql($permissionCodes); - $SQL_permissionCodes = join("','", $SQL_permissionCodes); + $SQL_permissionCodes = join("','", $SQL_permissionCodes); return DataObject::get( Member::class, "\"Group\".\"SubsiteID\" = $this->ID AND \"Permission\".\"Code\" IN ('$SQL_permissionCodes')", '', "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" - LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\" - LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\"" - ); - } + LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\" + LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\"" + ); + } - /** - * Duplicate this subsite - */ - public function duplicate($doWrite = true) { - $duplicate = parent::duplicate($doWrite); + /** + * Duplicate this subsite + */ + public function duplicate($doWrite = true) + { + $duplicate = parent::duplicate($doWrite); - $oldSubsiteID = Session::get('SubsiteID'); - self::changeSubsite($this->ID); + $oldSubsiteID = Session::get('SubsiteID'); + self::changeSubsite($this->ID); /* * Copy data from this object to the given subsite. Does this using an iterative depth-first search. @@ -892,24 +929,24 @@ JS; list($sourceParentID, $destParentID) = array_pop($stack); $children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", ''); - if($children) { - foreach($children as $child) { - self::changeSubsite($duplicate->ID); //Change to destination subsite + if ($children) { + foreach ($children as $child) { + self::changeSubsite($duplicate->ID); //Change to destination subsite - $childClone = $child->duplicateToSubsite($duplicate, false); - $childClone->ParentID = $destParentID; - $childClone->writeToStage('Stage'); - $childClone->publish('Stage', 'Live'); + $childClone = $child->duplicateToSubsite($duplicate, false); + $childClone->ParentID = $destParentID; + $childClone->writeToStage('Stage'); + $childClone->publish('Stage', 'Live'); - self::changeSubsite($this->ID); //Change Back to this subsite + self::changeSubsite($this->ID); //Change Back to this subsite array_push($stack, [$child->ID, $childClone->ID]); } } } - self::changeSubsite($oldSubsiteID); + self::changeSubsite($oldSubsiteID); - return $duplicate; - } + return $duplicate; + } } diff --git a/code/model/SubsiteDomain.php b/code/model/SubsiteDomain.php index f5e9c81..cbd928b 100644 --- a/code/model/SubsiteDomain.php +++ b/code/model/SubsiteDomain.php @@ -2,12 +2,13 @@ namespace SilverStripe\Subsites\Model; -use SilverStripe\Control\Director; use SilverStripe\Control\Controller; +use SilverStripe\Control\Director; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\OptionsetField; use SilverStripe\ORM\DataObject; +use SilverStripe\Subsites\Forms\WildcardDomainField; /** @@ -21,7 +22,7 @@ use SilverStripe\ORM\DataObject; class SubsiteDomain extends DataObject { - private static $table_name = 'SubsiteDomain'; + private static $table_name = 'SubsiteDomain'; /** * @@ -30,15 +31,16 @@ class SubsiteDomain extends DataObject private static $default_sort = "\"IsPrimary\" DESC"; /** * - * @var array - */ - private static $db = [ - "Domain" => "Varchar(255)", - "Protocol" => "Enum('http,https,automatic','automatic')", + * @var array + */ + private static $db = [ + "Domain" => "Varchar(255)", + "Protocol" => "Enum('http,https,automatic','automatic')", "IsPrimary" => "Boolean", - ]; + ]; - /*** Specifies that this subsite is http only + /** + * Specifies that this subsite is http only */ const PROTOCOL_HTTP = 'http'; @@ -63,53 +65,55 @@ class SubsiteDomain extends DataObject } /** - * - * @var array - */ - private static $has_one = [ - "Subsite" => Subsite::class, - ]; - - /** - *@config - * @var array - */ - private static $summary_fields=[ - 'Domain', - 'IsPrimary', - ]; - - /*** @config + * * @var array */ - private static $casting = array( + private static $has_one = [ + "Subsite" => Subsite::class, + ]; + + /** + * @config + * @var array + */ + private static $summary_fields = [ + 'Domain', + 'IsPrimary', + ]; + + /*** @config + * @var array + */ + private static $casting = [ 'SubstitutedDomain' => 'Varchar', 'FullProtocol' => 'Varchar', 'AbsoluteLink' => 'Varchar', - ); + ]; /** - * Whenever a Subsite Domain is written, rewrite the hostmap - * - * @return void - */ - public function onAfterWrite() - {Subsite::writeHostMap(); - } + * Whenever a Subsite Domain is written, rewrite the hostmap + * + * @return void + */ + public function onAfterWrite() + { + Subsite::writeHostMap(); + } - /** - * - * @return \FieldList - */ - public function getCMSFields() - { - $protocols = array( + /** + * + * @return \FieldList + */ + public function getCMSFields() + { + $protocols = [ self::PROTOCOL_HTTP => _t('SubsiteDomain.PROTOCOL_HTTP', 'http://'), self::PROTOCOL_HTTPS => _t('SubsiteDomain.PROTOCOL_HTTPS', 'https://'), self::PROTOCOL_AUTOMATIC => _t('SubsiteDomain.PROTOCOL_AUTOMATIC', 'Automatic') - );$fields = new FieldList( - WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255) - ->setDescription(_t( + ]; + $fields = new FieldList( + WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255) + ->setDescription(_t( 'SubsiteDomain.DOMAIN_DESCRIPTION', 'Hostname of this subsite (exclude protocol). Allows wildcards (*).' )), @@ -119,10 +123,10 @@ class SubsiteDomain extends DataObject 'When generating links to this subsite, use the selected protocol.
' . 'Selecting \'Automatic\' means subsite links will default to the current protocol.' )), CheckboxField::create('IsPrimary', $this->fieldLabel('IsPrimary')) - ->setDescription(_t( - 'SubsiteDomain.PROTOCOL_DESCRIPTION', - 'Mark this as the default domain for this subsite' - ))); + ->setDescription(_t( + 'SubsiteDomain.PROTOCOL_DESCRIPTION', + 'Mark this as the default domain for this subsite' + ))); $this->extend('updateCMSFields', $fields); return $fields; @@ -162,7 +166,7 @@ class SubsiteDomain extends DataObject return $this->getFullProtocol() . $this->Domain; } - /** + /** * Gets the full protocol (including ://) for this domain * * @return string @@ -170,16 +174,13 @@ class SubsiteDomain extends DataObject public function getFullProtocol() { switch ($this->Protocol) { - case self::PROTOCOL_HTTPS: - { + case self::PROTOCOL_HTTPS: { return 'https://'; } - case self::PROTOCOL_HTTP: - { + case self::PROTOCOL_HTTP: { return 'http://'; } - default: - { + default: { return Director::protocol(); } } @@ -198,7 +199,7 @@ class SubsiteDomain extends DataObject // If there are wildcards in the primary domain (not recommended), make some // educated guesses about what to replace them with: - $domain = preg_replace('/\.\*$/', ".{$currentHost}", $this->Domain ); + $domain = preg_replace('/\.\*$/', ".{$currentHost}", $this->Domain); // Default to "subsite." prefix for first wildcard // TODO Whats the significance of "subsite" inthiscontext?! @@ -230,5 +231,5 @@ class SubsiteDomain extends DataObject return Controller::join_links( $this->getAbsoluteLink(), Director::baseURL()); - } + } } diff --git a/code/pages/SubsitesVirtualPage.php b/code/pages/SubsitesVirtualPage.php index bd04bdf..85a2a29 100644 --- a/code/pages/SubsitesVirtualPage.php +++ b/code/pages/SubsitesVirtualPage.php @@ -18,7 +18,6 @@ use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField; use SilverStripe\Subsites\Model\Subsite; use SilverStripe\View\ArrayData; - class SubsitesVirtualPage extends VirtualPage { diff --git a/code/reports/SubsiteReportWrapper.php b/code/reports/SubsiteReportWrapper.php index 9780c28..57f6695 100644 --- a/code/reports/SubsiteReportWrapper.php +++ b/code/reports/SubsiteReportWrapper.php @@ -15,9 +15,10 @@ use SilverStripe\Subsites\Model\Subsite; */ class SubsiteReportWrapper extends ReportWrapper { - /////////////////////////////////////////////////////////////////////////////////////////// - // Filtering + /** + * @return FieldList + */ public function parameterFields() { $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true); @@ -44,9 +45,9 @@ class SubsiteReportWrapper extends ReportWrapper return $fields; } - /////////////////////////////////////////////////////////////////////////////////////////// - // Columns - + /** + * @return array + */ public function columns() { $columns = parent::columns(); @@ -57,6 +58,10 @@ class SubsiteReportWrapper extends ReportWrapper /////////////////////////////////////////////////////////////////////////////////////////// // Querying + /** + * @param arary $params + * @return void + */ public function beforeQuery($params) { // The user has select a few specific sites @@ -70,6 +75,10 @@ class SubsiteReportWrapper extends ReportWrapper Subsite::$force_subsite = join(',', array_keys($options)); } } + + /** + * @return void + */ public function afterQuery() { // Manually manage the subsite filtering diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..b4a30c4 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,7 @@ + + + + tests/php + + + diff --git a/tests/behat/features/bootstrap/Context/FeatureContext.php b/tests/behat/features/bootstrap/Context/FeatureContext.php index 5256e00..1cd4c39 100644 --- a/tests/behat/features/bootstrap/Context/FeatureContext.php +++ b/tests/behat/features/bootstrap/Context/FeatureContext.php @@ -1,6 +1,6 @@ array( 'SecureFileExtension', 'VersionedFileExtension' ), - 'SiteTree' => array( - 'Translatable', - ) - ); + 'SiteTree' => array( + 'Translatable', + ) + ); public function testTrivialFeatures() { diff --git a/tests/GroupSubsitesTest.php b/tests/php/GroupSubsitesTest.php similarity index 96% rename from tests/GroupSubsitesTest.php rename to tests/php/GroupSubsitesTest.php index 2799522..d0b8fc2 100644 --- a/tests/GroupSubsitesTest.php +++ b/tests/php/GroupSubsitesTest.php @@ -1,5 +1,7 @@ assertTrue(is_array(singleton('GroupSubsites')->extraStatics())); diff --git a/tests/LeftAndMainSubsitesTest.php b/tests/php/LeftAndMainSubsitesTest.php similarity index 97% rename from tests/LeftAndMainSubsitesTest.php rename to tests/php/LeftAndMainSubsitesTest.php index 69deb7c..6dc43f4 100644 --- a/tests/LeftAndMainSubsitesTest.php +++ b/tests/php/LeftAndMainSubsitesTest.php @@ -1,5 +1,8 @@ objFromFixture(Subsite::class, 'domaintest1'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $subsite3 = $this->objFromFixture(Subsite::class, 'domaintest3'); - $ids[] = $subsite1->ID; $ids[] = $subsite2->ID; $ids[] = $subsite3->ID; diff --git a/tests/SiteConfigSubsitesTest.php b/tests/php/SiteConfigSubsitesTest.php similarity index 88% rename from tests/SiteConfigSubsitesTest.php rename to tests/php/SiteConfigSubsitesTest.php index bfc9afc..7eacf92 100644 --- a/tests/SiteConfigSubsitesTest.php +++ b/tests/php/SiteConfigSubsitesTest.php @@ -1,5 +1,7 @@ objFromFixture(Subsite::class, 'domaintest1'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2'); diff --git a/tests/SiteTreeSubsitesTest.php b/tests/php/SiteTreeSubsitesTest.php similarity index 99% rename from tests/SiteTreeSubsitesTest.php rename to tests/php/SiteTreeSubsitesTest.php index bbd48f7..1258a22 100644 --- a/tests/SiteTreeSubsitesTest.php +++ b/tests/php/SiteTreeSubsitesTest.php @@ -1,5 +1,7 @@