public function testAllowsProtocolRelative()
 {
     $noProtocol = new RedirectorPage(array('ExternalURL' => 'mydomain.com'));
     $noProtocol->write();
     $this->assertEquals('http://mydomain.com', $noProtocol->ExternalURL);
     $protocolAbsolute = new RedirectorPage(array('ExternalURL' => 'http://mydomain.com'));
     $protocolAbsolute->write();
     $this->assertEquals('http://mydomain.com', $protocolAbsolute->ExternalURL);
     $protocolRelative = new RedirectorPage(array('ExternalURL' => '//mydomain.com'));
     $protocolRelative->write();
     $this->assertEquals('//mydomain.com', $protocolRelative->ExternalURL);
 }
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('RedirectorDescHeader');
     $fields->removeByName('RedirectionType');
     $fields->removeByName('LinkToID');
     $fields->removeByName('ExternalURL');
     return $fields;
 }
 public function testRevertToLiveFixesBrokenLinks()
 {
     // Create page and virutal page
     $p = new Page();
     $p->Title = "source";
     $p->write();
     $pageID = $p->ID;
     $this->assertTrue($p->doPublish());
     // Content links are one kind of link to pages
     $p2 = new Page();
     $p2->Title = "regular link";
     $p2->Content = "<a href=\"[sitetree_link,id={$p->ID}]\">test</a>";
     $p2->write();
     $this->assertTrue($p2->doPublish());
     // Virtual pages are another
     $vp = new VirtualPage();
     $vp->CopyContentFromID = $p->ID;
     $vp->write();
     // Redirector links are a third
     $rp = new RedirectorPage();
     $rp->Title = "redirector";
     $rp->LinkType = 'Internal';
     $rp->LinkToID = $p->ID;
     $rp->write();
     $this->assertTrue($rp->doPublish());
     // Confirm that there are no broken links to begin with
     $this->assertFalse($p2->HasBrokenLink);
     $this->assertFalse($vp->HasBrokenLink);
     $this->assertFalse($rp->HasBrokenLink);
     // Delete from draft and confirm that broken links are marked
     $pID = $p->ID;
     $p->delete();
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $p2->flushCache();
     $p2 = DataObject::get_by_id('SiteTree', $p2->ID);
     $rp->flushCache();
     $rp = DataObject::get_by_id('SiteTree', $rp->ID);
     $this->assertEquals(1, $p2->HasBrokenLink);
     $this->assertEquals(1, $vp->HasBrokenLink);
     $this->assertEquals(1, $rp->HasBrokenLink);
     // Call doRevertToLive and confirm that broken links are restored
     $pLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $pID);
     $pLive->doRevertToLive();
     $p2->flushCache();
     $p2 = DataObject::get_by_id('SiteTree', $p2->ID);
     $vp->flushCache();
     $vp = DataObject::get_by_id('SiteTree', $vp->ID);
     $rp->flushCache();
     $rp = DataObject::get_by_id('SiteTree', $rp->ID);
     $this->assertFalse((bool) $p2->HasBrokenLink);
     $this->assertFalse((bool) $vp->HasBrokenLink);
     $this->assertFalse((bool) $rp->HasBrokenLink);
 }
Пример #4
0
 /**
  *	Test the broken links report.
  */
 public function testBrokenLinksReport()
 {
     // ---
     // BROKEN LINKS
     // ---
     // Create a "draft" page with a broken link.
     $page = Page::create();
     $page->Content = "<a href='[sitetree_link,id=987654321]'>This</a> is a broken link.";
     $page->writeToStage('Stage');
     // Retrieve the broken links report.
     $reports = SS_Report::get_reports();
     $brokenLinksReport = null;
     foreach ($reports as $report) {
         if ($report instanceof BrokenLinksReport) {
             $brokenLinksReport = $report;
             break;
         }
     }
     // Determine that the report exists, otherwise it has been excluded.
     if ($brokenLinksReport) {
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
         $this->isReportBroken($brokenLinksReport, true, false, 'BROKENLINK');
         // Make sure the page is now "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, true, true, 'BROKENLINK');
         // Correct the "draft" broken link.
         $page->Content = str_replace('987654321', $page->ID, $page->Content);
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
         $this->isReportBroken($brokenLinksReport, false, true, 'BROKENLINK');
         // Make sure the change has now been "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, false, false, 'BROKENLINK');
         $page->delete();
         // ---
         // BROKEN FILES
         // ---
         // Create a "draft" page with a broken file.
         $page = Page::create();
         $page->Content = "<a href='[file_link,id=987654321]'>This</a> is a broken file.";
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has detected the page having a broken file.
         // ASSERT that the "published" report has NOT detected the page having a broken file, as the page has not been "published" yet.
         $this->isReportBroken($brokenLinksReport, true, false, 'BROKENFILE');
         // Make sure the page is now "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has detected the page having a broken file.
         // ASSERT that the "published" report has detected the page having a broken file.
         $this->isReportBroken($brokenLinksReport, true, true, 'BROKENFILE');
         // Correct the "draft" broken file.
         $file = File::create();
         $file->Filename = 'name.pdf';
         $file->write();
         $page->Content = str_replace('987654321', $file->ID, $page->Content);
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has NOT detected the page having a broken file.
         // ASSERT that the "published" report has detected the page having a broken file, as the previous content remains "published".
         $this->isReportBroken($brokenLinksReport, false, true, 'BROKENFILE');
         // Make sure the change has now been "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has NOT detected the page having a broken file.
         // ASSERT that the "published" report has NOT detected the page having a broken file.
         $this->isReportBroken($brokenLinksReport, false, false, 'BROKENFILE');
         $page->delete();
         // ---
         // BROKEN VIRTUAL PAGES
         // ---
         // Create a "draft" virtual page with a broken link.
         $page = VirtualPage::create();
         $page->CopyContentFromID = 987654321;
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
         $this->isReportBroken($brokenLinksReport, true, false, 'VPBROKENLINK');
         // Make sure the page is now "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, true, true, 'VPBROKENLINK');
         // Correct the "draft" broken link.
         $contentPage = Page::create();
         $contentPage->Content = 'This is some content.';
         $contentPage->writeToStage('Stage');
         $contentPage->writeToStage('Live');
         $page->CopyContentFromID = $contentPage->ID;
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
         $this->isReportBroken($brokenLinksReport, false, true, 'VPBROKENLINK');
         // Make sure the change has now been "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, false, false, 'VPBROKENLINK');
         $contentPage->delete();
         $page->delete();
         // ---
         // BROKEN REDIRECTOR PAGES
         // ---
         // Create a "draft" redirector page with a broken link.
         $page = RedirectorPage::create();
         $page->RedirectionType = 'Internal';
         $page->LinkToID = 987654321;
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
         $this->isReportBroken($brokenLinksReport, true, false, 'RPBROKENLINK');
         // Make sure the page is now "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, true, true, 'RPBROKENLINK');
         // Correct the "draft" broken link.
         $contentPage = Page::create();
         $contentPage->Content = 'This is some content.';
         $contentPage->writeToStage('Stage');
         $contentPage->writeToStage('Live');
         $page->LinkToID = $contentPage->ID;
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
         $this->isReportBroken($brokenLinksReport, false, true, 'RPBROKENLINK');
         // Make sure the change has now been "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link.
         $this->isReportBroken($brokenLinksReport, false, false, 'RPBROKENLINK');
     }
 }
 /**
  * Normally to be called after 'updatePagesBasedOnHierarchy', basically updates the ParentID/Sort of pages
  * based on how they're structured for the given menu. 
  *
  * (Silverstripe doesn't seperate its menu and page-structure like Wordpress)
  */
 public function updatePagesBasedOnNavMenu($menu_slug = '')
 {
     if (!$menu_slug) {
         // If first parameter left blank, throw exception showing the developer what menu slugs they can provide.
         $menuItems = '';
         foreach ($this->_db->getNavMenuTypes() as $navMenuType) {
             $menuItems .= $navMenuType['name'] . ' (slug: ' . $navMenuType['slug'] . ')' . ", \n";
         }
         throw new WordpressImportException("Must provide menu slug for " . __FUNCTION__ . "({$menu_slug}).\nAvailable menus:\n" . $menuItems);
     }
     $this->logFunctionStart(__FUNCTION__);
     $wpNavMenuItems = $this->_db->getNavMenuItems($menu_slug);
     if (!$wpNavMenuItems) {
         throw new WordpressImportException("Bad menu slug. Either invalid or does not contain any menu items.");
     }
     // Make all non-Wordpress pages no longer show in menu.
     $list = SiteTree::get()->filter(array('WordpressID' => 0, 'ShowInMenus' => 1));
     foreach ($list as $record) {
         $record->ShowInMenus = 0;
         $record->WordpressData = true;
         try {
             $this->writeAndPublishRecord($record);
         } catch (Exception $e) {
             $this->log($record, 'error', $e);
         }
     }
     // Make SiteTree items match the nav_menu_item post_type's structure and sort order.
     $wordpressIDsToSilverstripeIDs = singleton('SiteTree')->WordpressIDToSilverstripeIDMap();
     $trackRecordsChangedByIDs = array();
     $list = $this->applyWordpressFilter(SiteTree::get());
     foreach ($wpNavMenuItems as $wpData) {
         $wpMeta = $this->_db->attachAndGetPostMeta($wpData);
         if (!isset($wpMeta['_menu_item_type'])) {
             throw new Exception('Menu item is missing _menu_item_type postmeta. Your Wordpress database might be too old. Update it if possible.');
         }
         $record = null;
         if (isset($wpMeta['_menu_item_object_id']) && $wpMeta['_menu_item_object_id'] > 0) {
             // Detect if menu has an associated page ID, if so, and if that page has been imported, use it.
             $record = $list->find('WordpressID', $wpMeta['_menu_item_object_id']);
         }
         $type = $wpMeta['_menu_item_type'];
         if ($type === 'post_type' || $type === 'custom') {
             if (!$record) {
                 // If direct link to external URL or home.
                 if (isset($wpMeta['_menu_item_url']) && $wpMeta['_menu_item_url']) {
                     // A direct URL link
                     // Eg: "http://www.mylivesite.com.au/newsletters/"
                     $url = $wpMeta['_menu_item_url'];
                     if ($url === '/') {
                         // Detect "home" page
                         // - _menu_item_object_id references itself in this case, so we
                         //   can't use it to detect the record.
                         $record = $list->filter(array('URLSegment' => 'home'))->first();
                     } else {
                         $record = RedirectorPage::get()->filter(array('RedirectionType' => 'External', 'ExternalURL' => $url))->first();
                         if (!$record) {
                             $record = RedirectorPage::create();
                             $record->RedirectionType = 'External';
                             $record->ExternalURL = $url;
                         }
                         $record->WordpressData = $wpData;
                     }
                 } else {
                     $this->log('Found "custom" menu item type (Post ID #' . $wpData['ID'] . ') with Sort "' . $sort . '". Unable to handle. Skipping.', 'notice');
                     continue;
                 }
             }
         } else {
             throw new Exception('Unable to handle menu type "' . $type . '"');
         }
         if (!$record) {
             DB::alteration_message('Unable to find menu items post record.', 'error');
             continue;
         }
         if (isset($trackRecordsChangedByIDs[$record->ID])) {
             DB::alteration_message('Already used "' . $record->Title . '" #' . $record->ID . ' in this menu.', 'error');
             continue;
         }
         // Determine where to place Page in SS based on Wordpress IDs
         $wordpressParentID = 0;
         $wpParentNavItem = null;
         if (isset($wpMeta['_menu_item_menu_item_parent']) && $wpMeta['_menu_item_menu_item_parent'] > 0) {
             $wpParentNavID = $wpMeta['_menu_item_menu_item_parent'];
             if ($wpParentNavID > 0 && isset($wpNavMenuItems[$wpParentNavID])) {
                 $wpParentNavItem = $wpNavMenuItems[$wpParentNavID];
                 $wpParentMeta = $this->_db->attachAndGetPostMeta($wpParentNavItem);
                 if (!$wpParentMeta) {
                     throw new Exception('Missing meta on parent nav_menu_item #' . $wpParentNavID);
                 }
                 $wordpressParentID = $wpParentMeta['_menu_item_object_id'];
             } else {
                 throw new Exception('Unable to find parent nav_menu_item #' . $wpParentNavID);
             }
         }
         if ($wordpressParentID > 0) {
             $silverstripeParentID = $wordpressIDsToSilverstripeIDs[$wordpressParentID];
             $record->ParentID = $silverstripeParentID;
         } else {
             if ($wordpressParentID == 0) {
                 $record->ParentID = $this->root_parent_id;
             }
         }
         // Update with menu data
         $record->MenuTitle = $wpData['post_title'];
         if ($record instanceof RedirectorPage && $record->Title == '') {
             $record->Title = $record->MenuTitle;
         }
         $record->ShowInMenus = 1;
         // NOTE(Jake): Wordpress keeps its menu_order value going even under parents, like so:
         //			   - Menu Item 1			(menu_order = 1)
         //			 		- Menu Sub Item 1	(menu_order = 2)
         // 		       - Menu Item 2			(menu_order = 3)
         //					- Menu Sub Item 1	(menu_order = 4)
         //					- Menu Sub Item 2	(menu_order = 5)
         $record->Sort = $wpData['menu_order'];
         if ($changedFields = $record->getChangedFields(true, DataObject::CHANGE_VALUE)) {
             try {
                 $this->writeAndPublishRecord($record);
                 $trackRecordsChangedByIDs[$record->ID] = $record->ID;
             } catch (Exception $e) {
                 $this->log($record, 'error', $e);
             }
         } else {
             $this->log($record, 'nochange');
         }
     }
     $this->logFunctionEnd(__FUNCTION__);
 }
Пример #6
0
 /**
  *	Test the broken redirector pages side report.
  */
 public function testBrokenRedirectorPages()
 {
     // Create a "draft" redirector page with a broken link.
     $page = RedirectorPage::create();
     $page->RedirectionType = 'Internal';
     $page->LinkToID = 987654321;
     $page->writeToStage('Stage');
     // Retrieve the broken redirector pages side report.
     $reports = SS_Report::get_reports();
     $brokenRedirectorPagesReport = null;
     foreach ($reports as $report) {
         if ($report instanceof SideReport_BrokenRedirectorPages) {
             $brokenRedirectorPagesReport = $report;
             break;
         }
     }
     // Determine that the report exists, otherwise it has been excluded.
     if ($brokenRedirectorPagesReport) {
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link, as the page has not been "published" yet.
         $this->isReportBroken($brokenRedirectorPagesReport, true, false);
         // Make sure the page is now "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link.
         $this->isReportBroken($brokenRedirectorPagesReport, true, true);
         // Correct the "draft" broken link.
         $contentPage = Page::create();
         $contentPage->Content = 'This is some content.';
         $contentPage->writeToStage('Stage');
         $contentPage->writeToStage('Live');
         $page->LinkToID = $contentPage->ID;
         $page->writeToStage('Stage');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has detected the page having a broken link, as the previous content remains "published".
         $this->isReportBroken($brokenRedirectorPagesReport, false, true);
         // Make sure the change has now been "published".
         $page->writeToStage('Live');
         // ASSERT that the "draft" report has NOT detected the page having a broken link.
         // ASSERT that the "published" report has NOT detected the page having a broken link.
         $this->isReportBroken($brokenRedirectorPagesReport, false, false);
     }
 }
 /**
  * Creates the default SiteTree CMS section if not exists
  * 
  * @param SilvercartFrontPage $rootPage SiteTree root page
  * 
  * @return SilvercartFrontPage
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 21.03.2016
  */
 public function createDefaultSiteTreeCMSSection($rootPage)
 {
     $legalNavigationHolder = new SilvercartMetaNavigationHolder();
     $legalNavigationHolder->Title = _t('SilvercartMetaNavigationHolder.DEFAULT_TITLE_LEGAL');
     $legalNavigationHolder->URLSegment = _t('SilvercartMetaNavigationHolder.DEFAULT_URLSEGMENT_LEGAL', 'legal');
     $legalNavigationHolder->Status = "Published";
     $legalNavigationHolder->ShowInMenus = 0;
     $legalNavigationHolder->IdentifierCode = "SilvercartMetaNavigationHolderLegal";
     $legalNavigationHolder->ParentID = $rootPage->ID;
     $legalNavigationHolder->InheritFromParent = false;
     $legalNavigationHolder->write();
     $legalNavigationHolder->publish("Stage", "Live");
     $serviceNavigationHolder = new SilvercartMetaNavigationHolder();
     $serviceNavigationHolder->Title = _t('SilvercartMetaNavigationHolder.DEFAULT_TITLE_SERVICE');
     $serviceNavigationHolder->URLSegment = _t('SilvercartMetaNavigationHolder.DEFAULT_URLSEGMENT_SERVICE', 'service');
     $serviceNavigationHolder->Status = "Published";
     $serviceNavigationHolder->ShowInMenus = 0;
     $serviceNavigationHolder->IdentifierCode = "SilvercartMetaNavigationHolderService";
     $serviceNavigationHolder->ParentID = $rootPage->ID;
     $serviceNavigationHolder->InheritFromParent = false;
     $serviceNavigationHolder->write();
     $serviceNavigationHolder->publish("Stage", "Live");
     $aboutNavigationHolder = new SilvercartMetaNavigationHolder();
     $aboutNavigationHolder->Title = _t('SilvercartMetaNavigationHolder.DEFAULT_TITLE_ABOUT');
     $aboutNavigationHolder->URLSegment = _t('SilvercartMetaNavigationHolder.DEFAULT_URLSEGMENT_ABOUT', 'about-us');
     $aboutNavigationHolder->Status = "Published";
     $aboutNavigationHolder->ShowInMenus = 0;
     $aboutNavigationHolder->IdentifierCode = "SilvercartMetaNavigationHolderAbout";
     $aboutNavigationHolder->ParentID = $rootPage->ID;
     $aboutNavigationHolder->InheritFromParent = false;
     $aboutNavigationHolder->write();
     $aboutNavigationHolder->publish("Stage", "Live");
     $shopNavigationHolder = new SilvercartMetaNavigationHolder();
     $shopNavigationHolder->Title = _t('SilvercartMetaNavigationHolder.DEFAULT_TITLE_SHOP');
     $shopNavigationHolder->URLSegment = _t('SilvercartMetaNavigationHolder.DEFAULT_URLSEGMENT_SHOP', 'shop-system');
     $shopNavigationHolder->Status = "Published";
     $shopNavigationHolder->ShowInMenus = 0;
     $shopNavigationHolder->IdentifierCode = "SilvercartMetaNavigationHolderShop";
     $shopNavigationHolder->ParentID = $rootPage->ID;
     $shopNavigationHolder->InheritFromParent = false;
     $shopNavigationHolder->write();
     $shopNavigationHolder->publish("Stage", "Live");
     // Sub pages of legal node
     $termsOfServicePage = new SilvercartMetaNavigationPage();
     $termsOfServicePage->Title = _t('TermsOfServicePage.DEFAULT_TITLE', 'terms of service');
     $termsOfServicePage->URLSegment = _t('TermsOfServicePage.DEFAULT_URLSEGMENT', 'terms-of-service');
     $termsOfServicePage->Status = "Published";
     $termsOfServicePage->ShowInMenus = 1;
     $termsOfServicePage->ParentID = $legalNavigationHolder->ID;
     $termsOfServicePage->IdentifierCode = "TermsOfServicePage";
     $termsOfServicePage->write();
     $termsOfServicePage->publish("Stage", "Live");
     $revocationInstructionPage = new RedirectorPage();
     $revocationInstructionPage->RedirectionType = 'Internal';
     $revocationInstructionPage->LinkToID = $termsOfServicePage->ID;
     $revocationInstructionPage->Title = _t('RevocationInstructionPage.DEFAULT_TITLE', 'revocation instruction');
     $revocationInstructionPage->URLSegment = _t('RevocationInstructionPage.DEFAULT_URLSEGMENT', 'revocation-instruction');
     $revocationInstructionPage->Status = "Published";
     $revocationInstructionPage->ShowInMenus = 1;
     $revocationInstructionPage->ParentID = $legalNavigationHolder->ID;
     $revocationInstructionPage->IdentifierCode = "SilvercartRevocationInstructionPage";
     $revocationInstructionPage->write();
     $revocationInstructionPage->publish("Stage", "Live");
     $revocationPage = new SilvercartRevocationFormPage();
     $revocationPage->Title = _t('SilvercartRevocationFormPage.DEFAULT_TITLE', 'Revocation');
     $revocationPage->URLSegment = _t('SilvercartRevocationFormPage.DEFAULT_URLSEGMENT', 'Revocation');
     $revocationPage->Status = "Published";
     $revocationPage->ShowInMenus = 1;
     $revocationPage->IdentifierCode = "SilvercartRevocationFormPage";
     $revocationPage->ParentID = $legalNavigationHolder->ID;
     $revocationPage->write();
     $revocationPage->publish("Stage", "Live");
     $dataPrivacyStatementPage = new SilvercartMetaNavigationPage();
     $dataPrivacyStatementPage->Title = _t('SilvercartDataPrivacyStatementPage.DEFAULT_TITLE', 'data privacy statement');
     $dataPrivacyStatementPage->URLSegment = _t('SilvercartDataPrivacyStatementPage.DEFAULT_URLSEGMENT', 'data-privacy-statement');
     $dataPrivacyStatementPage->Status = "Published";
     $dataPrivacyStatementPage->ShowInMenus = 1;
     $dataPrivacyStatementPage->IdentifierCode = "DataPrivacyStatementPage";
     $dataPrivacyStatementPage->ParentID = $legalNavigationHolder->ID;
     $dataPrivacyStatementPage->write();
     $dataPrivacyStatementPage->publish("Stage", "Live");
     // Sub pages of service node
     $this->createDefaultSiteTreeMyAccountSection($serviceNavigationHolder);
     $paymentMethodsPage = new SilvercartPaymentMethodsPage();
     $paymentMethodsPage->Title = _t('SilvercartPaymentMethodsPage.DEFAULT_TITLE', 'Payment methods');
     $paymentMethodsPage->URLSegment = _t('SilvercartPaymentMethodsPage.DEFAULT_URLSEGMENT', 'payment-methods');
     $paymentMethodsPage->Status = "Published";
     $paymentMethodsPage->ShowInMenus = 1;
     $paymentMethodsPage->ParentID = $serviceNavigationHolder->ID;
     $paymentMethodsPage->IdentifierCode = "SilvercartPaymentMethodsPage";
     $paymentMethodsPage->write();
     $paymentMethodsPage->publish("Stage", "Live");
     $shippingFeesPage = new SilvercartShippingFeesPage();
     $shippingFeesPage->Title = _t('SilvercartShippingFeesPage.DEFAULT_TITLE', 'shipping fees');
     $shippingFeesPage->URLSegment = _t('SilvercartShippingFeesPage.DEFAULT_URLSEGMENT', 'shipping-fees');
     $shippingFeesPage->Status = "Published";
     $shippingFeesPage->ShowInMenus = 1;
     $shippingFeesPage->ParentID = $serviceNavigationHolder->ID;
     $shippingFeesPage->IdentifierCode = "SilvercartShippingFeesPage";
     $shippingFeesPage->write();
     $shippingFeesPage->publish("Stage", "Live");
     $newsletterPage = new SilvercartNewsletterPage();
     $newsletterPage->Title = _t('SilvercartNewsletterPage.DEFAULT_TITLE', 'Newsletter');
     $newsletterPage->URLSegment = _t('SilvercartNewsletterPage.DEFAULT_URLSEGMENT', 'newsletter');
     $newsletterPage->Status = "Published";
     $newsletterPage->ShowInMenus = true;
     $newsletterPage->ShowInSearch = true;
     $newsletterPage->ParentID = $serviceNavigationHolder->ID;
     $newsletterPage->IdentifierCode = "SilvercartNewsletterPage";
     $newsletterPage->write();
     $newsletterPage->publish("Stage", "Live");
     $newsletterResponsePage = new SilvercartNewsletterResponsePage();
     $newsletterResponsePage->Title = _t('SilvercartNewsletterResponsePage.DEFAULT_TITLE', 'Newsletter Status');
     $newsletterResponsePage->URLSegment = _t('SilvercartNewsletterResponsePage.DEFAULT_URLSEGMENT', 'newsletter_status');
     $newsletterResponsePage->Status = "Published";
     $newsletterResponsePage->ShowInMenus = false;
     $newsletterResponsePage->ShowInSearch = false;
     $newsletterResponsePage->ParentID = $newsletterPage->ID;
     $newsletterResponsePage->IdentifierCode = "SilvercartNewsletterResponsePage";
     $newsletterResponsePage->write();
     $newsletterResponsePage->publish("Stage", "Live");
     $newsletterOptInConfirmationPage = new SilvercartNewsletterOptInConfirmationPage();
     $newsletterOptInConfirmationPage->Title = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_TITLE', 'register confirmation page');
     $newsletterOptInConfirmationPage->URLSegment = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_URLSEGMENT', 'register-confirmation');
     $newsletterOptInConfirmationPage->Content = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_CONTENT');
     $newsletterOptInConfirmationPage->ConfirmationFailureMessage = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_CONFIRMATIONFAILUREMESSAGE');
     $newsletterOptInConfirmationPage->ConfirmationSuccessMessage = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_CONFIRMATIONSUCCESSMESSAGE');
     $newsletterOptInConfirmationPage->AlreadyConfirmedMessage = _t('SilvercartNewsletterOptInConfirmationPage.DEFAULT_ALREADYCONFIRMEDMESSAGE');
     $newsletterOptInConfirmationPage->Status = "Published";
     $newsletterOptInConfirmationPage->ParentID = $newsletterPage->ID;
     $newsletterOptInConfirmationPage->ShowInMenus = false;
     $newsletterOptInConfirmationPage->ShowInSearch = false;
     $newsletterOptInConfirmationPage->IdentifierCode = "SilvercartNewsletterOptInConfirmationPage";
     $newsletterOptInConfirmationPage->write();
     $newsletterOptInConfirmationPage->publish("Stage", "Live");
     // Sub pages of about node
     $imprintPage = new SilvercartMetaNavigationPage();
     $imprintPage->Title = _t('ImprintPage.DEFAULT_TITLE', 'imprint');
     $imprintPage->URLSegment = _t('ImprintPage.DEFAULT_URLSEGMENT', 'imprint');
     $imprintPage->Status = "Published";
     $imprintPage->ShowInMenus = 1;
     $imprintPage->ParentID = $aboutNavigationHolder->ID;
     $imprintPage->IdentifierCode = "ImprintPage";
     $imprintPage->write();
     $imprintPage->publish("Stage", "Live");
     $contactPage = new SilvercartContactFormPage();
     $contactPage->Title = _t('SilvercartContactFormPage.DEFAULT_TITLE', 'contact');
     $contactPage->URLSegment = _t('SilvercartContactFormPage.DEFAULT_URLSEGMENT', 'contact');
     $contactPage->Status = "Published";
     $contactPage->ShowInMenus = 1;
     $contactPage->IdentifierCode = "SilvercartContactFormPage";
     $contactPage->ParentID = $aboutNavigationHolder->ID;
     $contactPage->write();
     $contactPage->publish("Stage", "Live");
     $contactFormResponsePage = new SilvercartContactFormResponsePage();
     $contactFormResponsePage->Title = _t('SilvercartContactFormResponsePage.DEFAULT_TITLE', 'contact confirmation');
     $contactFormResponsePage->URLSegment = _t('SilvercartContactFormResponsePage.DEFAULT_URLSEGMENT', 'contactconfirmation');
     $contactFormResponsePage->Status = "Published";
     $contactFormResponsePage->ShowInMenus = false;
     $contactFormResponsePage->ShowInSearch = false;
     $contactFormResponsePage->IdentifierCode = "SilvercartContactFormResponsePage";
     $contactFormResponsePage->ParentID = $contactPage->ID;
     $contactFormResponsePage->Content = _t('SilvercartContactFormResponsePage.DEFAULT_CONTENT', 'Many thanks for Your message. Your request will be answered as soon as possible.');
     $contactFormResponsePage->write();
     $contactFormResponsePage->publish("Stage", "Live");
     // Sub pages of shop node
     $silvercartDePage = new RedirectorPage();
     $silvercartDePage->RedirectionType = 'External';
     $silvercartDePage->ExternalURL = 'http://www.silvercart.de';
     $silvercartDePage->Title = 'silvercart.de';
     $silvercartDePage->URLSegment = 'silvercart-de';
     $silvercartDePage->Status = "Published";
     $silvercartDePage->ShowInMenus = 1;
     $silvercartDePage->ParentID = $shopNavigationHolder->ID;
     $silvercartDePage->write();
     $silvercartDePage->publish("Stage", "Live");
     $silvercartOrgPage = new RedirectorPage();
     $silvercartOrgPage->RedirectionType = 'External';
     $silvercartOrgPage->ExternalURL = 'http://www.silvercart.org';
     $silvercartOrgPage->Title = 'silvercart.org';
     $silvercartOrgPage->URLSegment = 'silvercart-org';
     $silvercartOrgPage->Status = "Published";
     $silvercartOrgPage->ShowInMenus = 1;
     $silvercartOrgPage->ParentID = $shopNavigationHolder->ID;
     $silvercartOrgPage->write();
     $silvercartOrgPage->publish("Stage", "Live");
 }
Пример #8
0
 /**
  * Returns the pages that depend on this page. This includes virtual pages, pages that link to it, etc.
  * 
  * @param bool $includeVirtuals Set to false to exlcude virtual pages.
  * @return ArrayList
  */
 public function DependentPages($includeVirtuals = true)
 {
     if (class_exists('Subsite')) {
         $origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
         Subsite::disable_subsite_filter(true);
     }
     // Content links
     $items = new ArrayList();
     // We merge all into a regular SS_List, because DataList doesn't support merge
     if ($contentLinks = $this->BackLinkTracking()) {
         $linkList = new ArrayList();
         foreach ($contentLinks as $item) {
             $item->DependentLinkType = 'Content link';
             $linkList->push($item);
         }
         $items->merge($linkList);
     }
     // Virtual pages
     if ($includeVirtuals) {
         $virtuals = $this->VirtualPages();
         if ($virtuals) {
             $virtualList = new ArrayList();
             foreach ($virtuals as $item) {
                 $item->DependentLinkType = 'Virtual page';
                 $virtualList->push($item);
             }
             $items->merge($virtualList);
         }
     }
     // Redirector pages
     $redirectors = RedirectorPage::get()->where(array('"RedirectorPage"."RedirectionType"' => 'Internal', '"RedirectorPage"."LinkToID"' => $this->ID));
     if ($redirectors) {
         $redirectorList = new ArrayList();
         foreach ($redirectors as $item) {
             $item->DependentLinkType = 'Redirector page';
             $redirectorList->push($item);
         }
         $items->merge($redirectorList);
     }
     if (class_exists('Subsite')) {
         Subsite::disable_subsite_filter($origDisableSubsiteFilter);
     }
     return $items;
 }
 public function testVirtualPagePointingToRedirectorPage()
 {
     if (!class_exists('RedirectorPage')) {
         $this->markTestSkipped('RedirectorPage required');
     }
     $rp = new RedirectorPage(array('ExternalURL' => 'http://google.com', 'RedirectionType' => 'External'));
     $rp->write();
     $rp->doPublish();
     $vp = new VirtualPage(array('URLSegment' => 'vptest', 'CopyContentFromID' => $rp->ID));
     $vp->write();
     $vp->doPublish();
     $response = $this->get($vp->Link());
     $this->assertEquals(301, $response->getStatusCode());
     $this->assertEquals('http://google.com', $response->getHeader('Location'));
 }
    public function run($request)
    {
        Restrictable::set_enabled(false);
        Versioned::reading_stage('Stage');
        $admin = Security::findAnAdministrator();
        Session::set("loggedInAs", $admin->ID);
        $toPublish = array();
        $home = SiteTree::get()->filter('URLSegment', 'home')->first();
        if ($home) {
            $this->o("Home page already exists, _not_ bootstrapping");
            return;
        }
        $site = Multisites::inst()->getCurrentSite();
        $toPublish[] = $site;
        $dashboard = SiteDashboardPage::create(array('Title' => 'Dashboard', 'URLSegment' => 'dashboard', 'ParentID' => $site->ID));
        $dashboard->write();
        $this->o("Created Dashboard");
        $toPublish[] = $dashboard;
        $home = RedirectorPage::create(array('Title' => 'Home', 'URLSegment' => 'home', 'ParentID' => $site->ID));
        $home->LinkToID = $dashboard->ID;
        $home->write();
        $toPublish[] = $home;
        $this->o("Created homepage");
        $group = Group::create(array('Title' => 'All members'));
        $events = Calendar::create(array('Title' => 'Events', 'URLSegment' => 'events', 'ParentID' => $site->ID));
        $events->write();
        $toPublish[] = $events;
        $dummyEvent = CalendarEvent::create(array('Title' => 'Sample event', 'ParentID' => $events->ID));
        $dummyEvent->write();
        $toPublish[] = $dummyEvent;
        $dateTime = CalendarDateTime::create(array('StartDate' => strtotime('+1 week'), 'AllDay' => 1, 'EventID' => $dummyEvent->ID));
        $dateTime->write();
        $files = FileListingPage::create(array('Title' => 'File Listing', 'ParentID' => $site->ID));
        $files->write();
        $toPublish[] = $files;
        $news = MediaHolder::create(array('Title' => 'News', 'MediaTypeID' => 3, 'ParentID' => $site->ID));
        $news->write();
        $toPublish[] = $news;
        $text = <<<WORDS
\t\t\t<p>Oh no! Pull a sickie, this epic cuzzie is as rip-off as a snarky morepork. Mean while, in behind the 
\t\t\t\tbicycle shed, Lomu and The Hungery Caterpilar were up to no good with a bunch of cool jelly tip icecreams. 
\t\t\t\t\tThe flat stick force of his chundering was on par with Rangi's solid rimu chilly bin. Put the jug on 
\t\t\twill you bro, all these hard yakka utes can wait till later. The first prize for frying up goes to... 
\t\t\t\t\t\t\tsome uni student and his wicked wet blanket, what a egg. Bro, giant wekas are really tip-top good
\t\twith dodgy fellas, aye. You have no idea how nuclear-free our bung kiwis were aye. Every time</p><p>
\t\t\t\t\t\tI see those carked it wifebeater singlets it's like Castle Hill all over again aye, pissed 
\t\t\t\t\t\t\t\t\t\tas a rat. Anyway, Uncle Bully is just Mr Whippy in disguise, to find the true meaning of 
\t\t\t\t\t\t\t\t\t\t\tlife, one must start whale watching with the box of fluffies, mate. After the trotie
\t\t\t\t\t\t\t\t\t\t\t\tis jumped the ditch, you add all the heaps good whitebait fritters to 
\t\t\t\t\t\t\t\t\t\t\t\t\tthe paua you've got yourself a meal.</p><p>Technology has allowed
\t\t\t\t\t\t\t\t\t\t\t\t\t\tmint pukekos to participate in the global conversation of
\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tchoice keas. The next Generation of pearler dole bludgers have already packed a sad over at the beach. What's the hurry The Topp Twins? There's plenty of twink sticks in that one episode of Tux Wonder Dogs, you know the one bro. The sausage sizzle holds the most sweet as community in the country.. A Taniwha was playing rugby when the random reffing the game event occured. Those bloody Jaffa's, this outrageously awesome seabed is as tapu as a naff bloke. Pavalova is definitely not Australian, you don't know his story, bro. Mean while, in the sleepout, Jim Hickey and Sir Edmond Hillary were up to no good with a bunch of beautiful whanaus. The stuffed force of his cruising for a brusing was on par with James Cook's pretty suss pikelet. Put the jug on will you bro, all these buzzy stubbiess can wait till later.</p><p>The first prize for preparing the hungi goes to... Bazza and his rough as guts pohutukawa, what a sad guy. Bro, Monopoly money, from the New Zealand version with Queen Street and stuff are really hard case good with stink girl guide biscuits, aye. You have no idea how thermo-nuclear our sweet as mates were aye. Every time I see those fully sick packets of Wheetbix it's like Mt Cook all over again aye, see you right. Anyway, Mrs Falani is just Jonah Lomu in disguise, to find the true meaning of life, one must start rooting with the milk, mate. After the native vegetable is munted, you add all the beached as pieces of pounamu to the cheese on toast you've got yourself a meal. Technology has allowed primo kumaras to participate in the global conversation of sweet  gumboots. The next Generation of beaut manuses have already cooked over at Pack n' Save. What's the hurry Manus Morissette? There's plenty of onion dips in West Auckland. The tinny house holds the most same same but different community in the country.. Helen Clarke was packing a sad when the pretty suss whinging event occured. Eh, this stoked hongi is as cracker as a kiwi as chick.</p><p>Mean while, in the pub, Hercules Morse, as big as a horse and James and the Giant Peach were up to no good with a bunch of paru pinapple lumps. The bloody force of his wobbling was on par with Dr Ropata's crook lamington. Put the jug on will you bro, all these mean as foreshore and seabed issues can wait till later. The first prize for rooting goes to... Maui and his good as L&amp;P, what a hottie. Bro, marmite shortages are really shithouse good with hammered toasted sandwiches, aye. You have no idea how chocka full our chronic Bell Birds were aye. Every time I see those rip-off rugby balls it's like smoko time all over again aye, cook your own eggs Jake. Anyway, Cardigan Bay is just Spot, the Telecom dog in disguise, to find the true meaning of life, one must start pashing with the mince pie, mate.</p>
\t\t\t
WORDS;
        $story = MediaPage::create(array('Title' => 'Sample news item', 'Content' => $text, 'ParentID' => $news->ID));
        $story->write();
        $toPublish[] = $story;
        $group->write();
        $this->o("Created All Members group");
        $member = Member::create(array('FirstName' => 'Anon', 'Surname' => 'Ymous', 'Email' => '*****@*****.**'));
        $member->write();
        $member->Groups()->add($group);
        $site->Theme = 'ssau-minimalist';
        $site->LoggedInGroups()->add($group);
        $site->write();
        $this->o("Configured Site object");
        foreach ($toPublish as $item) {
            if (!is_object($item)) {
                print_r($item);
                continue;
            }
            $item->doPublish();
        }
        $this->o("Published everything");
        $message = <<<MSG
Your community system has been succesfully installed! Some things you might be interested in doing from this point are...

* Replying to this post! 
* Customising your dashboard
* Uploading some files and images to browse in the [file listing](file-listing)
* Create some events
* Add some RSS feeds to your Announcements dashlet (use the wrench to configure it!)
MSG;
        singleton('MicroBlogService')->createPost(null, $message, 'Installed!', 0, null, array('logged_in' => 1));
        Restrictable::set_enabled(true);
    }