/**
  * 
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     $cacheBaseDir = singleton('FilesystemPublisher')->getDestDir();
     // First generate the search file for the base site
     $viewer = new SSViewer(array('StaticSearchJSON'));
     $item = new ViewableData($this);
     $json = $viewer->process($this->getAllLivePages(0));
     $domain = Config::inst()->get('FilesystemPublisher', 'static_base_url');
     $urlFragments = parse_url($domain);
     $cacheDir = $cacheBaseDir . "/" . $urlFragments['host'];
     file_put_contents($cacheDir . '/search_index.html', $json);
     if (class_exists('Subsite')) {
         // Then generate the files for the subsites
         $subsites = Subsite::all_sites();
         foreach ($subsites as $subsite) {
             $viewer = new SSViewer(array('StaticSearchJSON'));
             $item = new ViewableData($this);
             $json = $viewer->process($this->getAllLivePages($subsite->ID));
             $domains = DataObject::get("SubsiteDomain")->filter(array("SubsiteID" => $subsite->ID));
             foreach ($domains as $domain) {
                 $urlFragments = parse_url($domain->Domain);
                 $cacheDir = $cacheBaseDir . "/" . $urlFragments['path'];
                 file_put_contents($cacheDir . '/search_index.html', $json);
             }
         }
     }
     return true;
 }
 /**
  * Find all subsites accessible for current user on this controller.
  *
  * @return ArrayList of {@link Subsite} instances.
  */
 function sectionSites($includeMainSite = true, $mainSiteTitle = "Main site", $member = null)
 {
     if ($mainSiteTitle == 'Main site') {
         $mainSiteTitle = _t('Subsites.MainSiteTitle', 'Main site');
     }
     // Rationalise member arguments
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return new ArrayList();
     }
     if (!is_object($member)) {
         $member = DataObject::get_by_id('Member', $member);
     }
     // Collect permissions - honour the LeftAndMain::required_permission_codes, current model requires
     // us to check if the user satisfies ALL permissions. Code partly copied from LeftAndMain::canView.
     $codes = array();
     $extraCodes = Config::inst()->get($this->owner->class, 'required_permission_codes');
     if ($extraCodes !== false) {
         if ($extraCodes) {
             $codes = array_merge($codes, (array) $extraCodes);
         } else {
             $codes[] = "CMS_ACCESS_{$this->owner->class}";
         }
     } else {
         // Check overriden - all subsites accessible.
         return Subsite::all_sites();
     }
     // Find subsites satisfying all permissions for the Member.
     $codesPerSite = array();
     $sitesArray = array();
     foreach ($codes as $code) {
         $sites = Subsite::accessible_sites($code, $includeMainSite, $mainSiteTitle, $member);
         foreach ($sites as $site) {
             // Build the structure for checking how many codes match.
             $codesPerSite[$site->ID][$code] = true;
             // Retain Subsite objects for later.
             $sitesArray[$site->ID] = $site;
         }
     }
     // Find sites that satisfy all codes conjuncitvely.
     $accessibleSites = new ArrayList();
     foreach ($codesPerSite as $siteID => $siteCodes) {
         if (count($siteCodes) == count($codes)) {
             $accessibleSites->push($sitesArray[$siteID]);
         }
     }
     return $accessibleSites;
 }
 /**
  * @return FieldList
  */
 public function getCMSFields()
 {
     Requirements::javascript(SITEWIDE_CONTENT_REPORT . '/javascript/sitewidecontentreport.js');
     $fields = parent::getCMSFields();
     if (class_exists('Subsite')) {
         $subsites = Subsite::all_sites()->map();
         $fields->insertBefore(HeaderField::create('PagesTitle', _t('SitewideContentReport.Pages', 'Pages'), 3), 'Report-Pages');
         $fields->insertBefore(DropdownField::create('AllSubsites', _t('SitewideContentReport.FilterBy', 'Filter by:'), $subsites)->addExtraClass('subsite-filter no-change-track')->setEmptyString('All Subsites'), 'Report-Pages');
     }
     $fields->push(HeaderField::create('FilesTitle', _t('SitewideContentReport.Files', 'Files'), 3));
     $fields->push($this->getReportField('Files'));
     return $fields;
 }
 function testAllSites()
 {
     $subsites = Subsite::all_sites();
     $this->assertDOSEquals(array(array('Title' => 'Main site'), array('Title' => 'Template'), array('Title' => 'Subsite1 Template'), array('Title' => 'Subsite2 Template'), array('Title' => 'Test 1'), array('Title' => 'Test 2'), array('Title' => 'Test 3')), $subsites, 'Lists all subsites');
 }