本文整理汇总了PHP中Subsite::changeSubsite方法的典型用法代码示例。如果您正苦于以下问题:PHP Subsite::changeSubsite方法的具体用法?PHP Subsite::changeSubsite怎么用?PHP Subsite::changeSubsite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subsite
的用法示例。
在下文中一共展示了Subsite::changeSubsite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSubsiteCreation
/**
* Create a new subsite from the template and verify that all the template's pages are copied
*/
function testSubsiteCreation()
{
Subsite::$write_hostmap = false;
// Create the instance
$template = $this->objFromFixture('Subsite', 'main');
// Test that changeSubsite is working
Subsite::changeSubsite($template->ID);
$tmplStaff = $this->objFromFixture('Page', 'staff');
$tmplHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
$pages = DataObject::get("SiteTree");
$totalPages = $pages->Count();
foreach ($pages as $page) {
$this->assertEquals($template->ID, $page->SubsiteID);
$page->publish('Stage', 'Live');
}
// Create a new site
$subsite = $template->duplicate();
// Check title
$this->assertEquals($subsite->Title, $template->Title);
// Another test that changeSubsite is working
$subsite->activate();
$siteHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
$this->assertNotEquals($siteHome, false, 'Home Page for subsite not found');
$this->assertEquals($subsite->ID, $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment');
Subsite::changeSubsite(0);
}
示例2: testSubsiteCreation
/**
* Create a new subsite from the template and verify that all the template's pages are copied
*/
function testSubsiteCreation()
{
Subsite::$write_hostmap = false;
// Create the instance
$template = $this->objFromFixture('Subsite_Template', 'main');
// Test that changeSubsite is working
Subsite::changeSubsite($template->ID);
$tmplHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'");
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
$pages = DataObject::get("SiteTree");
$totalPages = $pages->TotalItems();
foreach ($pages as $page) {
$this->assertEquals($template->ID, $page->SubsiteID);
$page->publish('Stage', 'Live');
}
// Create a new site
$subsite = $template->createInstance('My Site', 'something.test.com');
// Check title
$this->assertEquals($subsite->Title, 'My Site');
// Check that domain generation is working
$this->assertEquals('something.test.com', $subsite->domain());
// Another test that changeSubsite is working
$subsite->activate();
$siteHome = DataObject::get_one('SiteTree', "\"URLSegment\" = 'home'");
$this->assertNotNull($siteHome);
$this->assertEquals($subsite->ID, $siteHome->SubsiteID, 'createInstance() copies existing pages retaining the same URLSegment');
$this->assertEquals($siteHome->MasterPageID, $tmplHome->ID, 'Check master page value');
// Check linking of child pages
$tmplStaff = $this->objFromFixture('SiteTree', 'staff');
$siteStaff = DataObject::get_one('SiteTree', "\"URLSegment\" = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
$this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID);
Subsite::changeSubsite(0);
}
示例3: testWritingSubsiteID
function testWritingSubsiteID()
{
$this->objFromFixture('Member', 'admin')->logIn();
$subsite = $this->objFromFixture('Subsite', 'domaintest1');
FileSubsites::$default_root_folders_global = true;
Subsite::changeSubsite(0);
$file = new File();
$file->write();
$file->onAfterUpload();
$this->assertEquals((int) $file->SubsiteID, 0);
Subsite::changeSubsite($subsite->ID);
$this->assertTrue($file->canEdit());
$file = new File();
$file->write();
$this->assertEquals((int) $file->SubsiteID, 0);
$this->assertTrue($file->canEdit());
FileSubsites::$default_root_folders_global = false;
Subsite::changeSubsite($subsite->ID);
$file = new File();
$file->write();
$this->assertEquals($file->SubsiteID, $subsite->ID);
// Test inheriting from parent folder
$folder = new Folder();
$folder->write();
$this->assertEquals($folder->SubsiteID, $subsite->ID);
FileSubsites::$default_root_folders_global = true;
$file = new File();
$file->ParentID = $folder->ID;
$file->onAfterUpload();
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}
示例4: testEachSubsiteHasAUniqueSiteConfig
function testEachSubsiteHasAUniqueSiteConfig()
{
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
$this->assertTrue(is_array(singleton('SiteConfigSubsites')->extraStatics()));
Subsite::changeSubsite(0);
$sc = SiteConfig::current_site_config();
$sc->Title = 'RootSite';
$sc->write();
Subsite::changeSubsite($subsite1->ID);
$sc = SiteConfig::current_site_config();
$sc->Title = 'Subsite1';
$sc->write();
Subsite::changeSubsite($subsite2->ID);
$sc = SiteConfig::current_site_config();
$sc->Title = 'Subsite2';
$sc->write();
Subsite::changeSubsite(0);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'RootSite');
Subsite::changeSubsite($subsite1->ID);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite1');
Subsite::changeSubsite($subsite2->ID);
$this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite2');
$keys = SiteConfig::current_site_config()->extend('cacheKeyComponent');
$this->assertContains('subsite-' . $subsite2->ID, $keys);
}
示例5: activateState
function activateState($state)
{
if (Controller::has_curr()) {
Subsite::changeSubsite($state);
} else {
// TODO: This is a nasty hack - calling Subsite::changeSubsite after request ends
// throws error because no current controller to access session on
$_REQUEST['SubsiteID'] = $state;
}
}
开发者ID:peavers,项目名称:silverstripe-fulltextsearch,代码行数:10,代码来源:SearchVariantSiteTreeSubsitesPolyhome.php
示例6: run
function run($request)
{
$subsiteFromId = $request->getVar('from');
if (!is_numeric($subsiteFromId)) {
throw new InvalidArgumentException('Missing "from" parameter');
}
$subsiteFrom = DataObject::get_by_id('Subsite', $subsiteFromId);
if (!$subsiteFrom) {
throw new InvalidArgumentException('Subsite not found');
}
$subsiteToId = $request->getVar('to');
if (!is_numeric($subsiteToId)) {
throw new InvalidArgumentException('Missing "to" parameter');
}
$subsiteTo = DataObject::get_by_id('Subsite', $subsiteToId);
if (!$subsiteTo) {
throw new InvalidArgumentException('Subsite not found');
}
$useVirtualPages = (bool) $request->getVar('virtual');
Subsite::changeSubsite($subsiteFrom);
// Copy data from this template to the given subsite. Does this using an iterative depth-first search.
// This will make sure that the new parents on the new subsite are correct, and there are no funny
// issues with having to check whether or not the new parents have been added to the site tree
// when a page, etc, is duplicated
$stack = array(array(0, 0));
while (count($stack) > 0) {
list($sourceParentID, $destParentID) = array_pop($stack);
$children = Versioned::get_by_stage('SiteTree', 'Live', "\"ParentID\" = {$sourceParentID}", '');
if ($children) {
foreach ($children as $child) {
if ($useVirtualPages) {
$childClone = new SubsitesVirtualPage();
$childClone->writeToStage('Stage');
$childClone->CopyContentFromID = $child->ID;
$childClone->SubsiteID = $subsiteTo->ID;
} else {
$childClone = $child->duplicateToSubsite($subsiteTo->ID, true);
}
$childClone->ParentID = $destParentID;
$childClone->writeToStage('Stage');
$childClone->publish('Stage', 'Live');
array_push($stack, array($child->ID, $childClone->ID));
$this->log(sprintf('Copied "%s" (#%d, %s)', $child->Title, $child->ID, $child->Link()));
}
}
unset($children);
}
}
示例7: loadFixtures
public function loadFixtures()
{
if (ClassInfo::exists('Subsite')) {
$currentSubsite = Subsite::currentSubsiteID();
}
foreach (self::$preload_fixtures as $desc) {
$fixtureFile = $desc['file'];
if (file_exists(Director::baseFolder() . '/' . $fixtureFile)) {
$siteID = null;
if (isset($desc['subsite'])) {
$site = DataObject::get_one('Subsite', '"Title" = \'' . Convert::raw2sql($desc['subsite']) . '\'');
if ($site && $site->ID) {
$siteID = $site->ID;
}
if (!$siteID) {
// no site, so just skip this file load
continue;
}
}
// need to disable the filter when running dev/build so that it actually searches
// within the relevant subsite, not the 'current' one.
if (ClassInfo::exists('Subsite')) {
Subsite::$disable_subsite_filter = true;
}
$filter = $desc['filter'] . ($siteID ? ' AND "SubsiteID"=' . $siteID : '');
$existing = DataObject::get_one($desc['type'], $filter);
if (ClassInfo::exists('Subsite')) {
Subsite::$disable_subsite_filter = false;
}
if (!$existing) {
if ($siteID) {
Subsite::changeSubsite($siteID);
}
$fixture = new YamlFixture($fixtureFile);
$fixture->saveIntoDatabase();
DB::alteration_message('YAML bootstrap loaded from ' . $fixtureFile, 'created');
}
}
}
if (ClassInfo::exists('Subsite')) {
Subsite::changeSubsite($currentSubsite);
}
}
示例8: testAlternateAccessCheck
function testAlternateAccessCheck()
{
$admin = $this->objFromFixture("Member", "admin");
$this->loginAs($admin);
$ids = array();
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3');
$ids[] = $subsite1->ID;
$ids[] = $subsite2->ID;
$ids[] = $subsite3->ID;
$ids[] = 0;
foreach ($ids as $id) {
Subsite::changeSubsite($id);
//switch to main site (subsite ID zero)
$left = new LeftAndMain();
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '{$id}'");
$this->assertEquals($id, Subsite::currentSubsiteID(), "The current subsite has not been changed in the process of checking permissions for admin user.");
}
}
示例9: test_calc_directory_for_subsite
public function test_calc_directory_for_subsite()
{
//Template:
$subsite = $this->objFromFixture('Subsite', 'main');
//check calculation
$this->assertEquals('template', SubsiteUploadDirRules::calc_directory_for_subsite($subsite));
//check the generated folder
Subsite::changeSubsite($subsite->ID);
$this->assertEquals('template', SubsiteUploadDirRules::get_directory_for_current_subsite());
//Subsite1 Template:
$subsite = $this->objFromFixture('Subsite', 'subsite1');
//check calculation
$this->assertEquals('subsite1-template', SubsiteUploadDirRules::calc_directory_for_subsite($subsite));
//check the generated folder
Subsite::changeSubsite($subsite->ID);
$this->assertEquals('subsite1-template', SubsiteUploadDirRules::get_directory_for_current_subsite());
//Test 3:
$subsite = $this->objFromFixture('Subsite', 'domaintest3');
//check calculation
$this->assertEquals('test-3', SubsiteUploadDirRules::calc_directory_for_subsite($subsite));
//check the generated folder
Subsite::changeSubsite($subsite->ID);
$this->assertEquals('test-3', SubsiteUploadDirRules::get_directory_for_current_subsite());
Subsite::changeSubsite(0);
// if (class_exists('Subsite') && Object::has_extension('Subsite', 'AssetsFolderExtension')) {
//
// $subsite = Subsite::get()->first();
//
//
// //Setting subsite via $_GET
// //this is not bes practice, but this seems to be the only way that works
// //when running this over the command line
//
// //Subsite::changeSubsite($subsite->ID);
// $_GET['SubsiteID'] = $subsite->ID;
//
// $this->assertEquals('my-test-subsite', SubsiteUploadDirRules::calc_directory_for_subsite());
// }
}
示例10: testAdminIsRedirectedToObjectsSubsite
function testAdminIsRedirectedToObjectsSubsite()
{
$member = $this->objFromFixture('Member', 'admin');
Session::set("loggedInAs", $member->ID);
$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
$subsite1Home = $this->objFromFixture('Page', 'subsite1_home');
Config::inst()->nest();
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', false);
Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/{$subsite1Home->ID}");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading an object switches the subsite');
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', true);
Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/{$subsite1Home->ID}");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global');
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');
$this->getAndFollowAll("admin/pages/edit/show/{$mainSubsitePage->ID}");
$this->assertNotEquals(Subsite::currentSubsiteID(), $mainSubsitePage->SubsiteID, 'Loading a main-site object does not change the subsite if configured with treats_subsite_0_as_global');
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');
Config::inst()->unnest();
}
开发者ID:helpfulrobot,项目名称:mikenz-silverstripe-simplesubsites,代码行数:22,代码来源:SubsiteAdminFunctionalTest.php
示例11: testAccessChecksDontChangeCurrentSubsite
function testAccessChecksDontChangeCurrentSubsite()
{
$admin = $this->objFromFixture("Member", "admin");
$this->loginAs($admin);
$ids = array();
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
$subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
$subsite3 = $this->objFromFixture('Subsite', 'domaintest3');
$ids[] = $subsite1->ID;
$ids[] = $subsite2->ID;
$ids[] = $subsite3->ID;
$ids[] = 0;
// Enable session-based subsite tracking.
Subsite::$use_session_subsiteid = true;
foreach ($ids as $id) {
Subsite::changeSubsite($id);
$this->assertEquals($id, Subsite::currentSubsiteID());
$left = new LeftAndMain();
$this->assertTrue($left->canView(), "Admin user can view subsites LeftAndMain with id = '{$id}'");
$this->assertEquals($id, Subsite::currentSubsiteID(), "The current subsite has not been changed in the process of checking permissions for admin user.");
}
}
示例12: duplicateToSubsite
/**
* Create a duplicate of this page and save it to another subsite
* @param $subsiteID int|Subsite The Subsite to copy to, or its ID
*/
public function duplicateToSubsite($subsiteID = null)
{
if (is_object($subsiteID)) {
$subsite = $subsiteID;
$subsiteID = $subsite->ID;
} else {
$subsite = DataObject::get_by_id('Subsite', $subsiteID);
}
$oldSubsite = Subsite::currentSubsiteID();
if ($subsiteID) {
Subsite::changeSubsite($subsiteID);
} else {
$subsiteID = $oldSubsite;
}
$page = $this->owner->duplicate(false);
$page->CheckedPublicationDifferences = $page->AddedToStage = true;
$subsiteID = $subsiteID ? $subsiteID : $oldSubsite;
$page->SubsiteID = $subsiteID;
// MasterPageID is here for legacy purposes, to satisfy the subsites_relatedpages module
$page->MasterPageID = $this->owner->ID;
$page->write();
Subsite::changeSubsite($oldSubsite);
return $page;
}
示例13: testPageTypesBlacklistInCMSMain
function testPageTypesBlacklistInCMSMain()
{
$editor = $this->objFromFixture('Member', 'editor');
Session::set("loggedInAs", $editor->ID);
$cmsmain = new CMSMain();
$s1 = $this->objFromFixture('Subsite', 'domaintest1');
$s2 = $this->objFromFixture('Subsite', 'domaintest2');
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
$s1->write();
Subsite::changeSubsite($s1);
$hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren'];
$this->assertContains('ErrorPage', $classes);
$this->assertContains('SiteTreeSubsitesTest_ClassA', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
Subsite::changeSubsite($s2);
$hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren'];
$this->assertNotContains('ErrorPage', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
}
示例14: alternateAccessCheck
/**
* Alternative security checker for LeftAndMain.
* If security isn't found, then it will switch to a subsite where we do have access.
*/
public function alternateAccessCheck()
{
$className = $this->owner->class;
// Switch to the subsite of the current page
if ($this->owner->class == 'CMSMain' && ($currentPage = $this->owner->currentPage())) {
if (Subsite::currentSubsiteID() != $currentPage->SubsiteID) {
Subsite::changeSubsite($currentPage->SubsiteID);
}
}
// Switch to a subsite that this user can actually access.
$member = Member::currentUser();
if ($member && $member->isAdmin()) {
return true;
}
//admin can access all subsites
$sites = Subsite::accessible_sites("CMS_ACCESS_{$this->owner->class}")->toDropdownMap();
if ($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]);
return true;
}
// Switch to a different top-level menu item
$menu = CMSMenu::get_menu_items();
foreach ($menu as $candidate) {
if ($candidate->controller != $this->owner->class) {
$sites = Subsite::accessible_sites("CMS_ACCESS_{$candidate->controller}")->toDropdownMap();
if ($sites && !isset($sites[Subsite::currentSubsiteID()])) {
$siteIDs = array_keys($sites);
Subsite::changeSubsite($siteIDs[0]);
$cClass = $candidate->controller;
$cObj = new $cClass();
Director::redirect($cObj->Link());
return null;
}
}
}
// If all of those fail, you really don't have access to the CMS
return null;
}
示例15: testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite
/**
* Similar to {@link SiteTreeSubsitesTest->testTwoPagesWithSameURLOnDifferentSubsites()}
* and {@link SiteTreeSubsitesTest->testPagesInDifferentSubsitesCanShareURLSegment()}.
*/
function testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()
{
Subsite::$write_hostmap = false;
$subsite1 = $this->objFromFixture('Subsite', 'subsite1');
$subsite2 = $this->objFromFixture('Subsite', 'subsite2');
Subsite::changeSubsite($subsite1->ID);
$subsite1Page = $this->objFromFixture('Page', 'subsite1_staff');
$subsite1Page->URLSegment = 'staff';
$subsite1Page->write();
// saving on subsite1, and linking to subsite1
$subsite1Vp = new SubsitesVirtualPage();
$subsite1Vp->CopyContentFromID = $subsite1Page->ID;
$subsite1Vp->SubsiteID = $subsite1->ID;
$subsite1Vp->write();
$this->assertNotEquals($subsite1Vp->URLSegment, $subsite1Page->URLSegment, "Doesn't allow explicit URLSegment overrides when already existing in same subsite");
//Change to subsite 2
Subsite::changeSubsite($subsite2->ID);
// saving in subsite2 (which already has a page with URLSegment 'contact-us'),
// but linking to a page in subsite1
$subsite2Vp = new SubsitesVirtualPage();
$subsite2Vp->CopyContentFromID = $subsite1Page->ID;
$subsite2Vp->SubsiteID = $subsite2->ID;
$subsite2Vp->write();
$this->assertEquals($subsite2Vp->URLSegment, $subsite1Page->URLSegment, "Does allow explicit URLSegment overrides when only existing in a different subsite");
}