예제 #1
0
 public function setUp()
 {
     parent::setUp();
     // Set backend root to /ImageTest
     AssetStoreTest_SpyStore::activate('FileTest');
     // Create a test folders for each of the fixture references
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         $filePath = ASSETS_PATH . '/FileTest/' . $folder->getFilename();
         SS_Filesystem::makeFolder($filePath);
     }
     // Create a test files for each of the fixture references
     $fileIDs = $this->allFixtureIDs('File');
     foreach ($fileIDs as $fileID) {
         $file = DataObject::get_by_id('File', $fileID);
         $root = ASSETS_PATH . '/FileTest/';
         if ($folder = $file->Parent()) {
             $root .= $folder->getFilename();
         }
         $path = $root . substr($file->getHash(), 0, 10) . '/' . basename($file->getFilename());
         SS_Filesystem::makeFolder(dirname($path));
         $fh = fopen($path, "w+");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     }
     // Conditional fixture creation in case the 'cms' module is installed
     if (class_exists('ErrorPage')) {
         $page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404));
         $page->write();
         $page->publish('Stage', 'Live');
     }
 }
 /**
  * Create an {@link ErrorPage} for status code 503
  * 
  * @see UnderConstruction_Extension::onBeforeInit()
  * @see DataObjectDecorator::requireDefaultRecords()
  * @return Void
  */
 function requireDefaultRecords()
 {
     // Ensure that an assets path exists before we do any error page creation
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH);
     }
     $pageUnderConstructionErrorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '503'");
     $pageUnderConstructionErrorPageExists = $pageUnderConstructionErrorPage && $pageUnderConstructionErrorPage->exists() ? true : false;
     $pageUnderConstructionErrorPagePath = ErrorPage::get_filepath_for_errorcode(503);
     if (!($pageUnderConstructionErrorPageExists && file_exists($pageUnderConstructionErrorPagePath))) {
         if (!$pageUnderConstructionErrorPageExists) {
             $pageUnderConstructionErrorPage = new ErrorPage();
             $pageUnderConstructionErrorPage->ErrorCode = 503;
             $pageUnderConstructionErrorPage->Title = _t('UnderConstruction.TITLE', 'Under Construction');
             $pageUnderConstructionErrorPage->Content = _t('UnderConstruction.CONTENT', '<p>Sorry, this site is currently under construction.</p>');
             $pageUnderConstructionErrorPage->Status = 'New page';
             $pageUnderConstructionErrorPage->write();
             $pageUnderConstructionErrorPage->publish('Stage', 'Live');
         }
         // Ensure a static error page is created from latest error page content
         $response = Director::test(Director::makeRelative($pageUnderConstructionErrorPage->Link()));
         if ($fh = fopen($pageUnderConstructionErrorPagePath, 'w')) {
             $written = fwrite($fh, $response->getBody());
             fclose($fh);
         }
         if ($written) {
             DB::alteration_message('503 error page created', 'created');
         } else {
             DB::alteration_message(sprintf('503 error page could not be created at %s. Please check permissions', $pageUnderConstructionErrorPagePath), 'error');
         }
     }
 }
 /**
  * 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');
     }
 }
예제 #4
0
파일: ErrorPage.php 프로젝트: jlsa/justitia
 static function die_fancy($except)
 {
     // Log the error?
     if ($except instanceof InternalException) {
         Log::error($except->getMessage());
     }
     // Utility: error pages
     $view = new ErrorPage($except);
     $view->write();
     exit;
 }
 /**
  * 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'");
     $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->Status = 'New page';
             $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()));
         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->Status = 'New page';
             $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()));
         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');
         }
     }
 }
예제 #6
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');
     }
 }
예제 #7
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");
     }
 }
예제 #8
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 setUp()
 {
     parent::setUp();
     Config::inst()->update('CloudAssets', 'disabled', false);
     Config::inst()->update('CloudAssets', 'uploads_disabled', false);
     Config::inst()->update('Director', 'alternate_protocol', 'http');
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH);
     }
     /* Create a test folders for each of the fixture references */
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         if (!file_exists(BASE_PATH . "/{$folder->Filename}")) {
             mkdir(BASE_PATH . "/{$folder->Filename}");
         }
     }
     /* Create a test files for each of the fixture references */
     $fileIDs = $this->allFixtureIDs('File');
     foreach ($fileIDs as $fileID) {
         if ($fileID == 'png') {
             continue;
         }
         $file = DataObject::get_by_id('File', $fileID);
         $fh = fopen(BASE_PATH . "/{$file->Filename}", "w");
         fwrite($fh, str_repeat('x', 1000));
         fclose($fh);
     }
     // Conditional fixture creation in case the 'cms' module is installed
     if (class_exists('ErrorPage')) {
         $page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404));
         $page->write();
         $page->publish('Stage', 'Live');
     }
     $src = dirname(__FILE__) . '/test-png32.png';
     $dest = ASSETS_PATH . '/FileTest-folder1/test-png32.png';
     $f = copy($src, $dest);
     if (!$f) {
         die('unable to copy $src to $dest');
     }
     CloudAssets::inst()->clearBucketCache();
 }
예제 #10
0
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     // create a 400 ErrorPage
     if ($this->class == 'ErrorPage') {
         // Ensure that an assets path exists before we do any error page creation
         if (!file_exists(ASSETS_PATH)) {
             mkdir(ASSETS_PATH);
         }
         $ErrorPage400 = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '400'");
         $ErrorPage400Exists = $ErrorPage400 && $ErrorPage400->exists() ? true : false;
         $ErrorPage400Path = ErrorPage::get_filepath_for_errorcode(400);
         if (!($ErrorPage400Exists && file_exists($ErrorPage400Path))) {
             if (!$ErrorPage400Exists) {
                 $ErrorPage400 = new ErrorPage();
                 $ErrorPage400->ErrorCode = 400;
                 $ErrorPage400->Title = _t('ErrorPage.ERRORPAGE400TITLE', '400 Error');
                 $ErrorPage400->Content = _t('ErrorPage.ERRORPAGE400CONTENT', '<p>An error occurred while processing your request.</p>');
                 $ErrorPage400->Status = 'New page';
                 $ErrorPage400->write();
                 $ErrorPage400->publish('Stage', 'Live');
             }
             // Ensure a static error page is created from latest error page content
             $response = Director::test(Director::makeRelative($ErrorPage400->Link()));
             if ($fh = fopen($ErrorPage400Path, 'w')) {
                 $written = fwrite($fh, $response->getBody());
                 fclose($fh);
             }
             if ($written) {
                 DB::alteration_message('400 error page created', 'created');
             } else {
                 DB::alteration_message(sprintf('400 error page could not be created at %s. Please check permissions', $ErrorPage400Path), 'error');
             }
         }
         $ErrorPage412 = DataObject::get_one('ErrorPage', "\"ErrorCode\" = '412'");
         $ErrorPage412Exists = $ErrorPage412 && $ErrorPage412->exists() ? true : false;
         $ErrorPage412Path = ErrorPage::get_filepath_for_errorcode(412);
         if (!($ErrorPage412Exists && file_exists($ErrorPage412Path))) {
             if (!$ErrorPage412Exists) {
                 $ErrorPage412 = new ErrorPage();
                 $ErrorPage412->ErrorCode = 412;
                 $ErrorPage412->Title = _t('ErrorPage.ERRORPAGE412TITLE', '412 Error');
                 $ErrorPage412->Content = _t('ErrorPage.ERRORPAGE412CONTENT', '<p>Your Session has expired!.</p>');
                 $ErrorPage412->Status = 'New page';
                 $ErrorPage412->write();
                 $ErrorPage412->publish('Stage', 'Live');
             }
             // Ensure a static error page is created from latest error page content
             $response = Director::test(Director::makeRelative($ErrorPage412->Link()));
             if ($fh = fopen($ErrorPage412Path, 'w')) {
                 $written = fwrite($fh, $response->getBody());
                 fclose($fh);
             }
             if ($written) {
                 DB::alteration_message('412 error page created', 'created');
             } else {
                 DB::alteration_message(sprintf('412 error page could not be created at %s. Please check permissions', $ErrorPage412Path), 'error');
             }
         }
     }
 }
예제 #11
0
 public function setUp()
 {
     parent::setUp();
     if (!file_exists(ASSETS_PATH)) {
         mkdir(ASSETS_PATH);
     }
     /* Create a test folders for each of the fixture references */
     $folderIDs = $this->allFixtureIDs('Folder');
     foreach ($folderIDs as $folderID) {
         $folder = DataObject::get_by_id('Folder', $folderID);
         if (!file_exists(BASE_PATH . "/{$folder->Filename}")) {
             mkdir(BASE_PATH . "/{$folder->Filename}");
         }
     }
     /* Create a test files for each of the fixture references */
     $fileIDs = $this->allFixtureIDs('File');
     foreach ($fileIDs as $fileID) {
         $file = DataObject::get_by_id('File', $fileID);
         $fh = fopen(BASE_PATH . "/{$file->Filename}", "w");
         fwrite($fh, str_repeat('x', 1000000));
         fclose($fh);
     }
     // Conditional fixture creation in case the 'cms' module is installed
     if (class_exists('ErrorPage')) {
         $page = new ErrorPage(array('Title' => 'Page not Found', 'ErrorCode' => 404));
         $page->write();
         $page->publish('Stage', 'Live');
     }
 }
 /**
  * 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');
             }
         }
     }
 }
 /**
  * Test fallback to file generation API with enable_static_file disabled
  */
 public function testGeneratedFile()
 {
     Config::inst()->update('ErrorPage', 'enable_static_file', false);
     $this->logInWithPermission('ADMIN');
     $page = new ErrorPage();
     $page->ErrorCode = 405;
     $page->Title = 'Method Not Allowed';
     $page->write();
     $page->doPublish();
     // Dynamic content is available
     $response = ErrorPage::response_for('405');
     $this->assertNotEmpty($response);
     $this->assertNotEmpty($response->getBody());
     $this->assertEquals(405, (int) $response->getStatusCode());
     // Static content is not available
     $this->assertEmpty(ErrorPage::get_content_for_errorcode('405'));
     $expectedErrorPagePath = AssetStoreTest_SpyStore::base_path() . '/error-405.html';
     $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location');
 }
예제 #14
0
 /**
  * Test fallback to file generation API with enable_static_file disabled
  */
 public function testGeneratedFile()
 {
     Config::inst()->update('ErrorPage', 'enable_static_file', false);
     $this->logInWithPermission('ADMIN');
     $page = new ErrorPage();
     $page->ErrorCode = 405;
     $page->Title = 'Method Not Allowed';
     $page->write();
     $page->doPublish();
     // Error content is available, even though the static file does not exist (only in assetstore)
     $this->assertNotEmpty(ErrorPage::get_content_for_errorcode('405'));
     $expectedErrorPagePath = AssetStoreTest_SpyStore::base_path() . '/error-405.html';
     $this->assertFileNotExists($expectedErrorPagePath, 'Error page is not cached in static location');
 }