/**
  *	Instantiate a search page, should one not exist.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $mode = Versioned::get_reading_mode();
     Versioned::reading_stage('Stage');
     // Determine whether pages should be created.
     if (self::config()->create_default_pages) {
         // Determine whether an extensible search page already exists.
         if (!ExtensibleSearchPage::get()->first()) {
             // Instantiate an extensible search page.
             $page = ExtensibleSearchPage::create();
             $page->Title = 'Search Page';
             $page->write();
             DB::alteration_message('"Default" Extensible Search Page', 'created');
         }
     } else {
         if (ClassInfo::exists('Multisites')) {
             foreach (Site::get() as $site) {
                 // Determine whether an extensible search page already exists.
                 if (!ExtensibleSearchPage::get()->filter('SiteID', $site->ID)->first()) {
                     // Instantiate an extensible search page.
                     $page = ExtensibleSearchPage::create();
                     $page->ParentID = $site->ID;
                     $page->Title = 'Search Page';
                     $page->write();
                     DB::alteration_message("\"{$site->Title}\" Extensible Search Page", 'created');
                 }
             }
         }
     }
     Versioned::set_reading_mode($mode);
 }
 /**
  * Ensures that there is always a 404 page by checking if there's an
  * instance of ErrorPage with a 404 and 500 error code. If there is not,
  * one is created when the DB is built.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->class === 'ErrorPage' && SiteTree::config()->create_default_pages) {
         $defaultPages = $this->getDefaultRecords();
         foreach ($defaultPages as $defaultData) {
             $code = $defaultData['ErrorCode'];
             $page = ErrorPage::get()->filter('ErrorCode', $code)->first();
             $pageExists = !empty($page);
             if (!$pageExists) {
                 $page = new ErrorPage($defaultData);
                 $page->write();
                 $page->publish('Stage', 'Live');
             }
             // Check if static files are enabled
             if (!self::config()->enable_static_file) {
                 continue;
             }
             // Ensure this page has cached error content
             $success = true;
             if (!$page->hasStaticPage()) {
                 // Update static content
                 $success = $page->writeStaticPage();
             } elseif ($pageExists) {
                 // If page exists and already has content, no alteration_message is displayed
                 continue;
             }
             if ($success) {
                 DB::alteration_message(sprintf('%s error page created', $code), 'created');
             } else {
                 DB::alteration_message(sprintf('%s error page could not be created. Please check permissions', $code), 'error');
             }
         }
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->config()->get("auto_include")) {
         $check = TemplateOverviewPage::get()->First();
         if (!$check) {
             $page = new TemplateOverviewPage();
             $page->ShowInMenus = 0;
             $page->ShowInSearch = 0;
             $page->Title = "Templates overview";
             $page->PageTitle = "Templates overview";
             $page->Sort = 99998;
             $page->URLSegment = "templates";
             $parent = Page::get()->filter(array("URLSegment" => $this->config()->get("parent_url_segment")))->First();
             if ($parent) {
                 $page->ParentID = $parent->ID;
             }
             $page->writeToStage('Stage');
             $page->publish('Stage', 'Live');
             $page->URLSegment = "templates";
             $page->writeToStage('Stage');
             $page->publish('Stage', 'Live');
             DB::alteration_message("TemplateOverviewPage", "created");
         }
     }
 }
 /**
  * Ensures that there is always a 404 page
  * by checking if there's an instance of
  * ErrorPage with a 404 and 500 error code. If there
  * is not, one is created when the DB is built.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $pageNotFoundErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '404'");
     if (!($pageNotFoundErrorPage && $pageNotFoundErrorPage->exists())) {
         $pageNotFoundErrorPage = new ErrorPage();
         $pageNotFoundErrorPage->ErrorCode = 404;
         $pageNotFoundErrorPage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
         $pageNotFoundErrorPage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
         $pageNotFoundErrorPage->Status = 'New page';
         $pageNotFoundErrorPage->write();
         $pageNotFoundErrorPage->publish('Stage', 'Live');
         DB::alteration_message('404 page created', 'created');
     }
     $serverErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '500'");
     if (!($serverErrorPage && $serverErrorPage->exists())) {
         $serverErrorPage = new ErrorPage();
         $serverErrorPage->ErrorCode = 500;
         $serverErrorPage->Title = _t('ErrorPage.DEFAULTSERVERERRORPAGETITLE', 'Server error');
         $serverErrorPage->Content = _t('ErrorPage.DEFAULTSERVERERRORPAGECONTENT', '<p>Sorry, there was a problem with handling your request.</p>');
         $serverErrorPage->Status = 'New page';
         $serverErrorPage->write();
         $serverErrorPage->publish('Stage', 'Live');
         DB::alteration_message('500 page created', 'created');
     }
 }
 /**
  * Create default blog setup
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('UserAgreementPage')) {
         if (class_exists('Site') && ($sites = Site::get())) {
             if ($sites->first()) {
                 foreach ($sites as $site) {
                     $page = new UserAgreementPage();
                     $page->Title = "User Agreement";
                     $page->URLSegment = "user-agreement";
                     $page->Status = "Published";
                     $page->ShowInMenus = 0;
                     $page->ParentID = $site->ID;
                     $page->write();
                     $page->publish("Stage", "Live");
                     DB::alteration_message("User Agreement Page Created", "created");
                 }
             }
         } else {
             $page = new UserAgreementPage();
             $page->Title = "User Agreement";
             $page->URLSegment = "user-agreement";
             $page->Status = "Published";
             $page->ShowInMenus = 0;
             $page->write();
             $page->publish("Stage", "Live");
             DB::alteration_message("User Agreement Page Created", "created");
         }
     }
 }
Пример #6
0
 /**
  * Ensures that there is always a 404 page
  * by checking if there's an instance of
  * ErrorPage with a 404 and 500 error code. If there
  * is not, one is created when the DB is built.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->class == 'ErrorPage' && SiteTree::get_create_default_pages()) {
         // Ensure that an assets path exists before we do any error page creation
         if (!file_exists(ASSETS_PATH)) {
             mkdir(ASSETS_PATH);
         }
         $pageNotFoundErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '404'");
         $pageNotFoundErrorPageExists = $pageNotFoundErrorPage && $pageNotFoundErrorPage->exists() ? true : false;
         $pageNotFoundErrorPagePath = self::get_filepath_for_errorcode(404);
         if (!($pageNotFoundErrorPageExists && file_exists($pageNotFoundErrorPagePath))) {
             if (!$pageNotFoundErrorPageExists) {
                 $pageNotFoundErrorPage = new ErrorPage();
                 $pageNotFoundErrorPage->ErrorCode = 404;
                 $pageNotFoundErrorPage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
                 $pageNotFoundErrorPage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
                 $pageNotFoundErrorPage->write();
                 $pageNotFoundErrorPage->publish('Stage', 'Live');
             }
             // Ensure a static error page is created from latest error page content
             $response = Director::test(Director::makeRelative($pageNotFoundErrorPage->Link()));
             $written = null;
             if ($fh = fopen($pageNotFoundErrorPagePath, 'w')) {
                 $written = fwrite($fh, $response->getBody());
                 fclose($fh);
             }
             if ($written) {
                 DB::alteration_message('404 error page created', 'created');
             } else {
                 DB::alteration_message(sprintf('404 error page could not be created at %s. Please check permissions', $pageNotFoundErrorPagePath), 'error');
             }
         }
         $serverErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '500'");
         $serverErrorPageExists = $serverErrorPage && $serverErrorPage->exists() ? true : false;
         $serverErrorPagePath = self::get_filepath_for_errorcode(500);
         if (!($serverErrorPageExists && file_exists($serverErrorPagePath))) {
             if (!$serverErrorPageExists) {
                 $serverErrorPage = new ErrorPage();
                 $serverErrorPage->ErrorCode = 500;
                 $serverErrorPage->Title = _t('ErrorPage.DEFAULTSERVERERRORPAGETITLE', 'Server error');
                 $serverErrorPage->Content = _t('ErrorPage.DEFAULTSERVERERRORPAGECONTENT', '<p>Sorry, there was a problem with handling your request.</p>');
                 $serverErrorPage->write();
                 $serverErrorPage->publish('Stage', 'Live');
             }
             // Ensure a static error page is created from latest error page content
             $response = Director::test(Director::makeRelative($serverErrorPage->Link()));
             $written = null;
             if ($fh = fopen($serverErrorPagePath, 'w')) {
                 $written = fwrite($fh, $response->getBody());
                 fclose($fh);
             }
             if ($written) {
                 DB::alteration_message('500 error page created', 'created');
             } else {
                 DB::alteration_message(sprintf('500 error page could not be created at %s. Please check permissions', $serverErrorPagePath), 'error');
             }
         }
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $accountPages = DataObject::get('MembersAccountPage');
     foreach ($accountPages as $page) {
         $this->addMemberAccountFields($page);
     }
 }
 /**
  * This module always requires a page model.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!self::get()->exists() && $this->config()->create_default_pages) {
         $page = self::create(array('Title' => 'Account', 'URLSegment' => AccountPage_Controller::config()->url_segment, 'ShowInMenus' => 0));
         $page->write();
         $page->publish('Stage', 'Live');
         $page->flushCache();
         DB::alteration_message('Account page created', 'created');
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $page = DataObject::get_one('GridFieldTestPage');
     if (!$page) {
         $page = new GridFieldTestPage();
     }
     $page->URLSegment = 'gridfieldtest';
     $page->Title = 'GridField Test';
     $page->ParentID = 0;
     $page->write();
     $page->doPublish();
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!SubscriptionPage::get()->Count()) {
         $page = new SubscriptionPage();
         $page->Title = 'Newsletter Subscription';
         $page->URLSegment = 'newsletter-subscription';
         $page->SendNotification = 1;
         $page->ShowInMenus = false;
         $page->write();
         $page->publish('Stage', 'Live');
     }
 }
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('DPSHostedPaymentPage')) {
         $page = new DPSHostedPaymentPage();
         $page->Title = "Payment Status";
         $page->URLSegment = "paymentstatus";
         $page->ShowInMenus = 0;
         $page->ShowInSearch = 0;
         $page->write();
         SS_Database::alterationMessage("DPSHostedPaymentPage page created", "created");
     }
 }
 /**
  * Automatically create an AccountPage if one is not found
  * on the site at the time the database is built (dev/build).
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('AccountPage')) {
         $page = new AccountPage();
         $page->Title = 'Account';
         $page->Content = '<p>This is the account page. It is used for shop users to login and change their member details if they have an account.</p>';
         $page->URLSegment = 'account';
         $page->ShowInMenus = 0;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         DB::alteration_message('Account page \'Account\' created', 'created');
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!Catalog::get()->first()) {
         $catalog = new Catalog();
         $catalog->Title = "Product Catalog";
         $catalog->URLSegment = "catalog";
         $catalog->Sort = 4;
         $catalog->write();
         $catalog->publish('Stage', 'Live');
         $catalog->flushCache();
         DB::alteration_message('Product Catalog created', 'created');
     }
 }
Пример #14
0
 /**
  * Ensures that there is always a 404 page
  * by checking if there's an instance of
  * ErrorPage with a 404 error code. If there
  * is not, one is created when the DB is built.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '404'");
     if (!($errorPage && $errorPage->exists())) {
         $errorpage = new ErrorPage();
         $errorpage->ErrorCode = 404;
         $errorpage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
         $errorpage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
         $errorpage->Status = 'New page';
         $errorpage->write();
         DB::alteration_message('404 page created', 'created');
     }
 }
Пример #15
0
 /**
  * Ensure that any categories that exist with no forum holder are updated to be owned by the first forum holder
  * if there is one. This is required now that multiple forum holds are allowed, and categories belong to holders.
  *
  * @see sapphire/core/model/DataObject#requireDefaultRecords()
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!($cats = DataObject::get("ForumCategory", '"ForumCategory"."ForumHolderID" = 0'))) {
         return;
     }
     if (!($holder = DataObject::get_one("ForumHolder"))) {
         return;
     }
     foreach ($cats as $c) {
         $c->ForumHolderID = $holder->ID;
         $c->write();
     }
 }
Пример #16
0
 /**
  * Automatically create an AccountPage if one is not found
  * on the site at the time the database is built (dev/build).
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('AccountPage')) {
         $page = new AccountPage();
         $page->Title = 'Account';
         $page->Content = '';
         $page->URLSegment = 'account';
         $page->ShowInMenus = 0;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         DB::alteration_message('Account page \'Account\' created', 'created');
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     // Setup Discussion Page
     $page = DiscussionHolder::get()->first();
     if (!$page) {
         $page = new DiscussionHolder();
         $page->Title = "Discussions";
         $page->URLSegment = "discussions";
         $page->Sort = 3;
         $page->write();
         $page->publish('Stage', 'Live');
         DB::alteration_message('Discussions Holder Created', 'created');
     }
 }
Пример #18
0
 /**
  * Creates a default {@link SitemapPage} object if one does not currently exist.
  */
 public function requireDefaultRecords()
 {
     if (!($sitemap = DataObject::get_one('SitemapPage'))) {
         $sitemap = new SitemapPage();
         $sitemap->Title = _t('SitemapPage.SITEMAP', 'Sitemap');
         $sitemap->Content = sprintf('<p>%s</p>', _t('SitemapPage.DEFAULTCONTENT', 'This page displays a sitemap of the pages in your site.'));
         $sitemap->write();
         $sitemap->doPublish();
         if (method_exists('DB', 'alteration_message')) {
             DB::alteration_message('Created default Sitemap page.', 'created');
         } else {
             Database::alteration_message('Created default Sitemap page.', 'created');
         }
     }
     parent::requireDefaultRecords();
 }
Пример #19
0
 /**
  * Ensures that there is always a 404 page.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one("ErrorPage", "ErrorCode = '404'")) {
         $errorpage = new ErrorPage();
         $errorpage->ErrorCode = 404;
         $errorpage->Title = _t('ErrorPage.DEFAULTERRORPAGETITLE', 'Page not found');
         $errorpage->URLSegment = "page-not-found";
         $errorpage->ShowInMenus = false;
         $errorpage->Content = _t('ErrorPage.DEFAULTERRORPAGECONTENT', '<p>Sorry, it seems you were trying to access a page that doesn\'t exist.</p><p>Please check the spelling of the URL you were trying to access and try again.</p>');
         $errorpage->Status = "New page";
         $errorpage->write();
         // Don't publish, as the manifest may not be built yet
         // $errorpage->publish("Stage", "Live");
         Database::alteration_message("404 page created", "created");
     }
 }
 /**
  *  Creates a SiteMapPage at the top level when the database is built.
  *  Config MUST have 'autobuildpage' set to true, and site MUST NOT be in live mode.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $smp = DataObject::get_one('SiteMapPage');
     $autobuild = Config::inst()->get('SiteMapPage', 'autobuildpage');
     //TODO: This does not check for whether this SiteMapPage is an orphan or not
     if (!$smp && !Director::isLive() && $autobuild === true) {
         $smp = new SiteMapPage();
         $smp->Title = _t('SiteMapPage.DEFAULTTITLE', 'Site Map');
         $smp->Content = "<div>[SiteMap]</div><p>&nbsp;</p>";
         $smp->URLSegment = singleton('SiteTree')->generateURLSegment(_t('SiteMapPage.DEFAULTTITLE', 'Site Map'));
         $smp->Status = "Published";
         $smp->write();
         $smp->publish("Stage", "Live");
         DB::alteration_message("Default site map page created ;)", "created");
     }
 }
 /**
  * Create a default NewsHolderPage. This prevents error500 because of a missing page.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (NewsHolderPage::get()->count() == 0) {
         $page = NewsHolderPage::create();
         $page->Title = _t('NewsHolderPage.DEFAULTPAGETITLE', 'Newspage');
         $page->Content = '';
         $page->URLSegment = 'news';
         $page->Sort = 1;
         $page->Status = 'Published';
         $page->IsPrimary = true;
         $page->write();
         $page->publish('Stage', 'Live');
         $page->flushCache();
         DB::alteration_message('Newsholder Page created', 'created');
     } else {
         /** Migration is only possible, if the module is installed. We're assuming, this means there's at least one Holderpage. */
         $this->migrateUp();
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     $intranetGroup = Group::get()->filter(array("Code" => $this->Config()->get("group_code")))->first();
     if ($intranetGroup && $intranetGroup->exists()) {
         //do nothing
     } else {
         $intranetGroup = new Group();
         DB::alteration_message($this->Config()->get("group_name") . ' group created', "created");
     }
     if ($intranetGroup) {
         $intranetGroup->Code = $this->Config()->get("group_code");
         $intranetGroup->Title = $this->Config()->get("group_name");
         $intranetGroup->write();
         Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
         if (DB::query("\r\n\t\t\t\tSELECT *\r\n\t\t\t\tFROM Permission\r\n\t\t\t\tWHERE \"GroupID\" = '" . $intranetGroup->ID . "'\r\n\t\t\t\t\tAND \"Code\" LIKE '" . $this->Config()->get("permission_code") . "'")->numRecords() == 0) {
             Permission::grant($intranetGroup->ID, $this->Config()->get("permission_code"));
             DB::alteration_message($this->Config()->get("group_name") . ' permissions granted', "created");
         }
     }
 }
 /**
  * This automatically creates a CheckoutPage whenever dev/build
  * is invoked and there is no page on the site with CheckoutPage
  * applied to it.
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!($page = DataObject::get_one('CheckoutPage'))) {
         $page = new CheckoutPage();
         $page->Title = 'Checkout';
         $page->Content = '<p>This is the checkout page. The order summary and order form appear below this content.</p>';
         $page->PurchaseComplete = '<p>Your purchase is complete.</p>';
         $page->ChequeMessage = '<p>Please note: Your goods will not be dispatched until we receive your payment.</p>';
         $page->URLSegment = 'checkout';
         $page->ShowInMenus = 0;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         Database::alteration_message('Checkout page \'Checkout\' created', 'created');
     }
     if ($page->TermsPageID == 0 && ($termsPage = DataObject::get_one('Page', "`URLSegment` = 'terms-and-conditions'"))) {
         $page->TermsPageID = $termsPage->ID;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         Database::alteration_message("Page '{$termsPage->Title}' linked to the Checkout page '{$page->Title}'", 'changed');
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     //clear all old records
     $bigFmailyPages = DB::query("SELECT \"SiteTree_Live\".\"ID\" FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ClassName\" = 'BigFamilyPage'")->column();
     if (count($bigFmailyPages)) {
         $ids = "(" . implode(",", $bigFmailyPages) . ")";
         //Delete all children from all stages
         DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ParentID\" IN {$ids}");
         DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"ParentID\" IN {$ids}");
         DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ParentID\" IN {$ids}");
         //Delete themselves from all stages
         DB::query("DELETE FROM \"SiteTree\" WHERE \"SiteTree\".\"ID\" IN {$ids}");
         DB::query("DELETE FROM \"SiteTree_versions\" WHERE \"SiteTree_versions\".\"RecordID\" IN {$ids}");
         DB::query("DELETE FROM \"SiteTree_Live\" WHERE \"SiteTree_Live\".\"ID\" IN {$ids}");
     }
     //create new records
     $bigFamilyPages = DataObject::get('BigFamilyPage');
     foreach ($bigFamilyPages as $page) {
         foreach ($page->AllChildren() as $child) {
             $child->delete();
         }
         $page->delete();
     }
     $familyPage = new BigFamilyPage();
     $familyPage->Title = "Big Family";
     $familyPage->write();
     $familyPage->publish('Stage', 'Live');
     foreach (singleton('Employee')->data() as $name) {
         $page = new Page();
         $page->Title = $name;
         $page->MenuTitle = $name;
         $page->ParentID = $familyPage->ID;
         $page->write();
         $page->publish('Stage', 'Live');
     }
     DB::alteration_message("Added default 'BigFamilyPage' and its children pages", "created");
 }
 /**
  * Change the contact-us page to ContactUsPage type
  */
 function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link("contact-us")) {
         $contactpage = new HomePage();
         $contactpage->Title = "Contact Us";
         $contactpage->URLSegment = "contact-us";
         $contactpage->Sort = 3;
         $contactpage->write();
         $contactpage->publish('Stage', 'Live');
         $contactpage->flushCache();
         DB::alteration_message('Contact Us created', 'created');
     } else {
         $contactpage = SiteTree::get_by_link("contact-us");
         if ($contactpage->ClassName != "ContactUsPage") {
             $contactpage = $contactpage->newClassInstance("ContactUsPage");
             $contactpage->write();
             $contactpage->publish('Stage', 'Live');
             $contactpage->flushCache();
             DB::alteration_message('Contact Us changed to ContactUsPage', 'changed');
         }
     }
     parent::requireDefaultRecords();
 }
Пример #26
0
 /**
  * Change the home page to HomePage type
  */
 public function requireDefaultRecords()
 {
     if (!SiteTree::get_by_link("home")) {
         $homepage = new HomePage();
         ${$homepage}->Title = "Home";
         $homepage->URLSegment = "home";
         $homepage->Sort = 1;
         $homepage->write();
         $homepage->publish('Stage', 'Live');
         $homepage->flushCache();
         DB::alteration_message('Home Page created', 'created');
     } else {
         $homepage = SiteTree::get_by_link("home");
         if ($homepage->ClassName != "HomePage") {
             $homepage = $homepage->newClassInstance("HomePage");
             $homepage->write();
             $homepage->publish('Stage', 'Live');
             $homepage->flushCache();
             DB::alteration_message('Home changed to HomePage', 'changed');
         }
     }
     parent::requireDefaultRecords();
 }
 /**
  * Create default news setup
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('NewsHolder')) {
         $newsHolder = new NewsHolder();
         $newsHolder->Title = 'News';
         $newsHolder->Namespace = 'global';
         $newsHolder->URLSegment = 'news';
         $newsHolder->Status = 'Published';
         $newsHolder->write();
         $newsHolder->publish('Stage', 'Live');
         $newsItem = new NewsItem();
         $newsItem->Title = _t('NewsHolder.SUCTITLE', 'SilverStripe news module successfully installed');
         $newsItem->Date = date('Y-m-d');
         $newsItem->URLSegment = 'sample-news-item';
         $newsItem->Content = _t('NewsHolder.SUCCONTENT', 'Congratulations, the SilverStripe news module has been successfully installed. This news item can be safely deleted.');
         $newsItem->Status = 'Published';
         $newsItem->ParentID = $newsHolder->ID;
         $newsItem->write();
         $newsItem->publish('Stage', 'Live');
         DB::alteration_message('News item created', 'created');
     }
 }
 /**
  * Automatically create an AccountPage if one is not found
  * on the site at the time the database is built (dev/build).
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('AccountPage')) {
         $page = new AccountPage();
         $page->Title = 'Account';
         $page->Content = '';
         $page->URLSegment = 'account';
         $page->ShowInMenus = 0;
         $page->writeToStage('Stage');
         $page->publish('Stage', 'Live');
         DB::alteration_message('Account page \'Account\' created', 'created');
     }
     //Create a new group for customers
     $allGroups = DataObject::get('Group');
     $existingCustomerGroup = $allGroups->find('Title', 'Customers');
     if (!$existingCustomerGroup) {
         $customerGroup = new Group();
         $customerGroup->Title = 'Customers';
         $customerGroup->setCode($customerGroup->Title);
         $customerGroup->write();
     }
 }
Пример #29
0
 /**
  * Ensures that there is always a 404 page by checking if there's an
  * instance of ErrorPage with a 404 and 500 error code. If there is not,
  * one is created when the DB is built.
  */
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->class == 'ErrorPage' && SiteTree::config()->create_default_pages) {
         // Ensure that an assets path exists before we do any error page creation
         if (!file_exists(ASSETS_PATH)) {
             mkdir(ASSETS_PATH);
         }
         $defaultPages = $this->getDefaultRecords();
         foreach ($defaultPages as $defaultData) {
             $code = $defaultData['ErrorCode'];
             $page = DataObject::get_one('ErrorPage', sprintf("\"ErrorPage\".\"ErrorCode\" = '%s'", $code));
             $pageExists = $page && $page->exists();
             $pagePath = self::get_filepath_for_errorcode($code);
             if (!($pageExists && file_exists($pagePath))) {
                 if (!$pageExists) {
                     $page = new ErrorPage($defaultData);
                     $page->write();
                     $page->publish('Stage', 'Live');
                 }
                 // Ensure a static error page is created from latest error page content
                 $response = Director::test(Director::makeRelative($page->Link()));
                 $written = null;
                 if ($fh = fopen($pagePath, 'w')) {
                     $written = fwrite($fh, $response->getBody());
                     fclose($fh);
                 }
                 if ($written) {
                     DB::alteration_message(sprintf('%s error page created', $code), 'created');
                 } else {
                     DB::alteration_message(sprintf('%s error page could not be created at %s. Please check permissions', $code, $pagePath), 'error');
                 }
             }
         }
     }
 }
 public function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if ($this->config()->create_default_pages) {
         $groupHolder = DataObject::get_one('ScoutGroupHolder');
         if (!$groupHolder) {
             $groupHolder = new ScoutGroupHolder();
             $groupHolder->Title = "Groups";
             $groupHolder->URLSegment = 'groups';
             $groupHolder->Status = 'Published';
             $groupHolder->write();
             $groupHolder->publish('Stage', 'Live');
             DB::alteration_message('Scout Group Holder page created', 'created');
         }
     }
     $districtAdmin = DataObject::get_one('Group', "Code = 'scout-district-admin'");
     if (!$districtAdmin) {
         $districtAdmin = new Group();
         $districtAdmin->Code = 'scout-district-admin';
         $districtAdmin->Title = _t('ScoutDistrict.Groups.SCOUTDISTRICTADMIN', 'Scout District Admin');
         $districtAdmin->write();
         Permission::grant($districtAdmin->ID, ScoutDistrictPermissions::$district_admin);
         DB::alteration_message('Scout District Admin group created', 'created');
     }
     $groupManager = DataObject::get_one('Group', "Code = 'scout-group-manager'");
     if (!$groupManager) {
         $groupManager = new Group();
         $groupManager->Code = 'scout-group-manager';
         $groupManager->Title = _t('ScoutDistrict.Groups.SCOUTGROUPMANAGER', 'Scout Group Manager');
         $groupManager->write();
         Permission::grant($groupManager->ID, ScoutDistrictPermissions::$group_manager);
         Permission::grant($groupManager->ID, "CMS_ACCESS_CMSMain");
         DB::alteration_message('Scout Group Manager group created', 'created');
     }
 }